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

@ -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);
}