Skip to content

Commit 02d33c9

Browse files
committed
eliminate find_use_path and show 'as' and 'use'
1 parent 486bffc commit 02d33c9

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

crates/ide_completion/src/item.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ impl CompletionItem {
295295
label,
296296
insert_text: None,
297297
is_snippet: false,
298+
trait_name: None,
298299
detail: None,
299300
documentation: None,
300301
lookup: None,
@@ -398,6 +399,7 @@ pub(crate) struct Builder {
398399
source_range: TextRange,
399400
completion_kind: CompletionKind,
400401
import_to_add: Option<ImportEdit>,
402+
trait_name: Option<String>,
401403
label: String,
402404
insert_text: Option<String>,
403405
is_snippet: bool,
@@ -434,6 +436,8 @@ impl Builder {
434436
} else {
435437
format_to!(label, " ({})", original_path)
436438
}
439+
} else if let Some(trait_name) = self.trait_name {
440+
format_to!(label, " ({})", trait_name)
437441
}
438442

439443
let text_edit = match self.text_edit {
@@ -468,6 +472,10 @@ impl Builder {
468472
self.label = label.into();
469473
self
470474
}
475+
pub(crate) fn trait_name(&mut self, trait_name: impl Into<String>) -> &mut Builder {
476+
self.trait_name = Some(trait_name.into());
477+
self
478+
}
471479
pub(crate) fn insert_text(&mut self, insert_text: impl Into<String>) -> &mut Builder {
472480
self.insert_text = Some(insert_text.into());
473481
self

crates/ide_completion/src/render/const_.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Renderer for `const` fields.
22
3-
use hir::{AsAssocItem, HasSource, ModuleDef};
3+
use hir::{AsAssocItem, HasSource};
44
use ide_db::SymbolKind;
55
use syntax::{
66
ast::{Const, NameOwner},
@@ -49,11 +49,8 @@ impl<'a> ConstRender<'a> {
4949
let db = self.ctx.db();
5050
if let Some(actm) = self.const_.as_assoc_item(db) {
5151
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
52-
let module = self.ctx.completion.scope.module().unwrap();
53-
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
54-
item.label(format!("{} ({})", name.clone(), path));
55-
item.insert_text(name.clone());
56-
}
52+
item.trait_name(trt.name(db).to_string());
53+
item.insert_text(name.clone());
5754
}
5855
}
5956

crates/ide_completion/src/render/function.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Renderer for function calls.
22
3-
use hir::{AsAssocItem, HasSource, HirDisplay, ModuleDef};
3+
use hir::{AsAssocItem, HasSource, HirDisplay};
44
use ide_db::SymbolKind;
55
use itertools::Itertools;
66
use syntax::ast::Fn;
@@ -79,14 +79,7 @@ impl<'a> FunctionRender<'a> {
7979
let db = self.ctx.db();
8080
if let Some(actm) = self.func.as_assoc_item(db) {
8181
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
82-
let module = self.ctx.completion.scope.module().unwrap();
83-
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
84-
item.label(format!(
85-
"{} ({})",
86-
item.clone().build().label().to_owned(),
87-
path
88-
));
89-
}
82+
item.trait_name(trt.name(db).to_string());
9083
}
9184
}
9285
}

crates/ide_completion/src/render/type_alias.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Renderer for type aliases.
22
3-
use hir::{AsAssocItem, HasSource, ModuleDef};
3+
use hir::{AsAssocItem, HasSource};
44
use ide_db::SymbolKind;
55
use syntax::{
66
ast::{NameOwner, TypeAlias},
@@ -62,11 +62,8 @@ impl<'a> TypeAliasRender<'a> {
6262
let db = self.ctx.db();
6363
if let Some(actm) = self.type_alias.as_assoc_item(db) {
6464
if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
65-
let module = self.ctx.completion.scope.module().unwrap();
66-
if let Some(path) = module.find_use_path(db, ModuleDef::Trait(trt)) {
67-
item.label(format!("{} ({})", name.clone(), path));
68-
item.insert_text(name.clone());
69-
}
65+
item.trait_name(trt.name(db).to_string());
66+
item.insert_text(name.clone());
7067
}
7168
}
7269

0 commit comments

Comments
 (0)