Render the expansion of snippets as their docs

This commit is contained in:
Lukas Wirth 2021-10-05 18:00:27 +02:00
parent 77cbf4adbc
commit 041cfbe0f4
4 changed files with 10 additions and 17 deletions

View file

@ -2,6 +2,7 @@
mod format_like; mod format_like;
use hir::Documentation;
use ide_db::{ use ide_db::{
helpers::{insert_use::ImportScope, FamousDefs, SnippetCap}, helpers::{insert_use::ImportScope, FamousDefs, SnippetCap},
ty_filter::TryEnum, ty_filter::TryEnum,
@ -236,11 +237,10 @@ fn add_custom_postfix_completions(
Some(imports) => imports, Some(imports) => imports,
None => return, None => return,
}; };
let mut builder = postfix_snippet( let body = snippet.postfix_snippet(&receiver_text);
trigger, let mut builder =
snippet.description.as_deref().unwrap_or_default(), postfix_snippet(trigger, snippet.description.as_deref().unwrap_or_default(), &body);
&snippet.postfix_snippet(&receiver_text), builder.documentation(Documentation::new(format!("```rust\n{}\n```", body)));
);
for import in imports.into_iter() { for import in imports.into_iter() {
builder.add_import(import); builder.add_import(import);
} }
@ -481,7 +481,7 @@ fn main() {
snippets: vec![Snippet::new( snippets: vec![Snippet::new(
&[], &[],
&["break".into()], &["break".into()],
&["ControlFlow::Break($receiver)".into()], &["ControlFlow::Break(${receiver})".into()],
"", "",
&["core::ops::ControlFlow".into()], &["core::ops::ControlFlow".into()],
crate::SnippetScope::Expr, crate::SnippetScope::Expr,

View file

@ -1,5 +1,6 @@
//! This file provides snippet completions, like `pd` => `eprintln!(...)`. //! This file provides snippet completions, like `pd` => `eprintln!(...)`.
use hir::Documentation;
use ide_db::helpers::{insert_use::ImportScope, SnippetCap}; use ide_db::helpers::{insert_use::ImportScope, SnippetCap};
use syntax::T; use syntax::T;
@ -109,7 +110,9 @@ fn add_custom_completions(
Some(imports) => imports, Some(imports) => imports,
None => return, 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() { for import in imports.into_iter() {
builder.add_import(import); builder.add_import(import);
} }

View file

@ -146,11 +146,6 @@ Custom completion snippets.
-- --
Whether to show postfix snippets like `dbg`, `if`, `not`, etc. 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`):: [[rust-analyzer.completion.autoimport.enable]]rust-analyzer.completion.autoimport.enable (default: `true`)::
+ +
-- --

View file

@ -595,11 +595,6 @@
"default": true, "default": true,
"type": "boolean" "type": "boolean"
}, },
"rust-analyzer.completion.postfix.snippets": {
"markdownDescription": "Custom postfix completion snippets.",
"default": {},
"type": "object"
},
"rust-analyzer.completion.autoimport.enable": { "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.", "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, "default": true,