eliminate find_use_path and show 'as' and 'use'

This commit is contained in:
mahdi-frms 2021-07-04 20:57:45 +04:30
parent 486bffc23e
commit 02d33c9856
4 changed files with 16 additions and 21 deletions

View File

@ -295,6 +295,7 @@ impl CompletionItem {
label,
insert_text: None,
is_snippet: false,
trait_name: None,
detail: None,
documentation: None,
lookup: None,
@ -398,6 +399,7 @@ pub(crate) struct Builder {
source_range: TextRange,
completion_kind: CompletionKind,
import_to_add: Option<ImportEdit>,
trait_name: Option<String>,
label: String,
insert_text: Option<String>,
is_snippet: bool,
@ -434,6 +436,8 @@ impl Builder {
} else {
format_to!(label, " ({})", original_path)
}
} else if let Some(trait_name) = self.trait_name {
format_to!(label, " ({})", trait_name)
}
let text_edit = match self.text_edit {
@ -468,6 +472,10 @@ impl Builder {
self.label = label.into();
self
}
pub(crate) fn trait_name(&mut self, trait_name: impl Into<String>) -> &mut Builder {
self.trait_name = Some(trait_name.into());
self
}
pub(crate) fn insert_text(&mut self, insert_text: impl Into<String>) -> &mut Builder {
self.insert_text = Some(insert_text.into());
self

View File

@ -1,6 +1,6 @@
//! Renderer for `const` fields.
use hir::{AsAssocItem, HasSource, ModuleDef};
use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind;
use syntax::{
ast::{Const, NameOwner},
@ -49,11 +49,8 @@ impl<'a> ConstRender<'a> {
let db = self.ctx.db();
if let Some(actm) = self.const_.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!("{} ({})", name.clone(), path));
item.insert_text(name.clone());
}
item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone());
}
}

View File

@ -1,6 +1,6 @@
//! Renderer for function calls.
use hir::{AsAssocItem, HasSource, HirDisplay, ModuleDef};
use hir::{AsAssocItem, HasSource, HirDisplay};
use ide_db::SymbolKind;
use itertools::Itertools;
use syntax::ast::Fn;
@ -79,14 +79,7 @@ impl<'a> FunctionRender<'a> {
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.trait_name(trt.name(db).to_string());
}
}
}

View File

@ -1,6 +1,6 @@
//! Renderer for type aliases.
use hir::{AsAssocItem, HasSource, ModuleDef};
use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind;
use syntax::{
ast::{NameOwner, TypeAlias},
@ -62,11 +62,8 @@ impl<'a> TypeAliasRender<'a> {
let db = self.ctx.db();
if let Some(actm) = self.type_alias.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!("{} ({})", name.clone(), path));
item.insert_text(name.clone());
}
item.trait_name(trt.name(db).to_string());
item.insert_text(name.clone());
}
}