mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Render the expansion of snippets as their docs
This commit is contained in:
parent
77cbf4adbc
commit
041cfbe0f4
4 changed files with 10 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
mod format_like;
|
||||
|
||||
use hir::Documentation;
|
||||
use ide_db::{
|
||||
helpers::{insert_use::ImportScope, FamousDefs, SnippetCap},
|
||||
ty_filter::TryEnum,
|
||||
|
@ -236,11 +237,10 @@ fn add_custom_postfix_completions(
|
|||
Some(imports) => imports,
|
||||
None => return,
|
||||
};
|
||||
let mut builder = postfix_snippet(
|
||||
trigger,
|
||||
snippet.description.as_deref().unwrap_or_default(),
|
||||
&snippet.postfix_snippet(&receiver_text),
|
||||
);
|
||||
let body = snippet.postfix_snippet(&receiver_text);
|
||||
let mut builder =
|
||||
postfix_snippet(trigger, snippet.description.as_deref().unwrap_or_default(), &body);
|
||||
builder.documentation(Documentation::new(format!("```rust\n{}\n```", body)));
|
||||
for import in imports.into_iter() {
|
||||
builder.add_import(import);
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ fn main() {
|
|||
snippets: vec![Snippet::new(
|
||||
&[],
|
||||
&["break".into()],
|
||||
&["ControlFlow::Break($receiver)".into()],
|
||||
&["ControlFlow::Break(${receiver})".into()],
|
||||
"",
|
||||
&["core::ops::ControlFlow".into()],
|
||||
crate::SnippetScope::Expr,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
|
||||
|
||||
use hir::Documentation;
|
||||
use ide_db::helpers::{insert_use::ImportScope, SnippetCap};
|
||||
use syntax::T;
|
||||
|
||||
|
@ -109,7 +110,9 @@ fn add_custom_completions(
|
|||
Some(imports) => imports,
|
||||
None => return,
|
||||
};
|
||||
let mut builder = snippet(ctx, cap, &trigger, &snip.snippet());
|
||||
let body = snip.snippet();
|
||||
let mut builder = snippet(ctx, cap, &trigger, &body);
|
||||
builder.documentation(Documentation::new(format!("```rust\n{}\n```", body)));
|
||||
for import in imports.into_iter() {
|
||||
builder.add_import(import);
|
||||
}
|
||||
|
|
|
@ -146,11 +146,6 @@ Custom completion snippets.
|
|||
--
|
||||
Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
|
||||
--
|
||||
[[rust-analyzer.completion.postfix.snippets]]rust-analyzer.completion.postfix.snippets (default: `{}`)::
|
||||
+
|
||||
--
|
||||
Custom postfix completion snippets.
|
||||
--
|
||||
[[rust-analyzer.completion.autoimport.enable]]rust-analyzer.completion.autoimport.enable (default: `true`)::
|
||||
+
|
||||
--
|
||||
|
|
|
@ -595,11 +595,6 @@
|
|||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"rust-analyzer.completion.postfix.snippets": {
|
||||
"markdownDescription": "Custom postfix completion snippets.",
|
||||
"default": {},
|
||||
"type": "object"
|
||||
},
|
||||
"rust-analyzer.completion.autoimport.enable": {
|
||||
"markdownDescription": "Toggles the additional completions that automatically add imports when completed.\nNote that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.",
|
||||
"default": true,
|
||||
|
|
Loading…
Reference in a new issue