From 041cfbe0f46c7f565ce1828857d35adb9cf2d7e7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 5 Oct 2021 18:00:27 +0200 Subject: [PATCH] Render the expansion of snippets as their docs --- crates/ide_completion/src/completions/postfix.rs | 12 ++++++------ crates/ide_completion/src/completions/snippet.rs | 5 ++++- docs/user/generated_config.adoc | 5 ----- editors/code/package.json | 5 ----- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 4df6c36ebe..b74030c173 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -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, diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index ed6c4c7493..a0e5f56129 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -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); } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 7ec66c18be..f80b978545 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -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`):: + -- diff --git a/editors/code/package.json b/editors/code/package.json index fd6d03cb8a..d9afdfad1b 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -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,