mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
show local variable types in completion
This commit is contained in:
parent
5f3ff157e3
commit
8e49bb664a
6 changed files with 30 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
//! This modules takes care of rendering various defenitions as completion items.
|
||||
use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution};
|
||||
use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution, Ty};
|
||||
use join_to_string::join;
|
||||
use ra_syntax::ast::NameOwner;
|
||||
use test_utils::tested_by;
|
||||
|
@ -80,10 +80,18 @@ impl Completions {
|
|||
None,
|
||||
),
|
||||
};
|
||||
CompletionItem::new(completion_kind, ctx.source_range(), local_name)
|
||||
.kind(kind)
|
||||
.set_documentation(docs)
|
||||
.add_to(self)
|
||||
|
||||
let mut completion_item =
|
||||
CompletionItem::new(completion_kind, ctx.source_range(), local_name);
|
||||
if let Resolution::LocalBinding(pat_id) = def {
|
||||
let ty = ctx
|
||||
.analyzer
|
||||
.type_of_pat_by_id(ctx.db, pat_id.clone())
|
||||
.filter(|t| t != &Ty::Unknown)
|
||||
.map(|t| t.display(ctx.db).to_string());
|
||||
completion_item = completion_item.set_detail(ty);
|
||||
};
|
||||
completion_item.kind(kind).set_documentation(docs).add_to(self)
|
||||
}
|
||||
|
||||
pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue