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

View file

@ -1,6 +1,6 @@
//! Renderer for `const` fields. //! Renderer for `const` fields.
use hir::{AsAssocItem, HasSource, ModuleDef}; use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind; use ide_db::SymbolKind;
use syntax::{ use syntax::{
ast::{Const, NameOwner}, ast::{Const, NameOwner},
@ -49,13 +49,10 @@ impl<'a> ConstRender<'a> {
let db = self.ctx.db(); let db = self.ctx.db();
if let Some(actm) = self.const_.as_assoc_item(db) { if let Some(actm) = self.const_.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) { if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
let module = self.ctx.completion.scope.module().unwrap(); item.trait_name(trt.name(db).to_string());
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
item.label(format!("{} ({})", name.clone(), path));
item.insert_text(name.clone()); item.insert_text(name.clone());
} }
} }
}
Some(item.build()) Some(item.build())
} }

View file

@ -1,6 +1,6 @@
//! Renderer for function calls. //! Renderer for function calls.
use hir::{AsAssocItem, HasSource, HirDisplay, ModuleDef}; use hir::{AsAssocItem, HasSource, HirDisplay};
use ide_db::SymbolKind; use ide_db::SymbolKind;
use itertools::Itertools; use itertools::Itertools;
use syntax::ast::Fn; use syntax::ast::Fn;
@ -79,14 +79,7 @@ impl<'a> FunctionRender<'a> {
let db = self.ctx.db(); let db = self.ctx.db();
if let Some(actm) = self.func.as_assoc_item(db) { if let Some(actm) = self.func.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) { if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
let module = self.ctx.completion.scope.module().unwrap(); item.trait_name(trt.name(db).to_string());
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
item.label(format!(
"{} ({})",
item.clone().build().label().to_owned(),
path
));
}
} }
} }
} }

View file

@ -1,6 +1,6 @@
//! Renderer for type aliases. //! Renderer for type aliases.
use hir::{AsAssocItem, HasSource, ModuleDef}; use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind; use ide_db::SymbolKind;
use syntax::{ use syntax::{
ast::{NameOwner, TypeAlias}, ast::{NameOwner, TypeAlias},
@ -62,13 +62,10 @@ impl<'a> TypeAliasRender<'a> {
let db = self.ctx.db(); let db = self.ctx.db();
if let Some(actm) = self.type_alias.as_assoc_item(db) { if let Some(actm) = self.type_alias.as_assoc_item(db) {
if let Some(trt) = actm.containing_trait_or_trait_impl(db) { if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
let module = self.ctx.completion.scope.module().unwrap(); item.trait_name(trt.name(db).to_string());
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
item.label(format!("{} ({})", name.clone(), path));
item.insert_text(name.clone()); item.insert_text(name.clone());
} }
} }
}
Some(item.build()) Some(item.build())
} }