show imported trait on autocompletion of associated items

This commit is contained in:
mahdi-frms 2021-07-04 00:59:47 +04:30
parent e5c1c8cf2f
commit 486bffc23e
8 changed files with 74 additions and 36 deletions

View file

@ -1,6 +1,6 @@
//! Renderer for function calls.
use hir::{HasSource, HirDisplay};
use hir::{AsAssocItem, HasSource, HirDisplay, ModuleDef};
use ide_db::SymbolKind;
use itertools::Itertools;
use syntax::ast::Fn;
@ -73,9 +73,25 @@ impl<'a> FunctionRender<'a> {
self.ctx.is_deprecated(self.func) || self.ctx.is_deprecated_assoc_item(self.func),
)
.detail(self.detail())
.add_call_parens(self.ctx.completion, call.clone(), params)
.add_import(import_to_add)
.lookup_by(self.name);
.add_call_parens(self.ctx.completion, call.clone(), params);
if import_to_add.is_none() {
let db = self.ctx.db();
if let Some(actm) = self.func.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
let module = self.ctx.completion.scope.module().unwrap();
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
item.label(format!(
"{} ({})",
item.clone().build().label().to_owned(),
path
));
}
}
}
}
item.add_import(import_to_add).lookup_by(self.name);
let ret_type = self.func.ret_type(self.ctx.db());
item.set_relevance(CompletionRelevance {