diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index d975405347..49aee62aba 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs @@ -250,7 +250,7 @@ impl Trait for A {} fn foo(a: A) { a.$0 } "#, expect![[r#" - me the_method() fn(&self) + me the_method() (Trait) fn(&self) "#]], ); } @@ -265,7 +265,7 @@ impl Trait for T {} fn foo(a: &A) { a.$0 } ", expect![[r#" - me the_method() fn(&self) + me the_method() (Trait) fn(&self) "#]], ); } @@ -283,7 +283,7 @@ impl Trait for A {} fn foo(a: A) { a.$0 } ", expect![[r#" - me the_method() fn(&self) + me the_method() (Trait) fn(&self) "#]], ); } diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index 1b8997ecf3..a525343f77 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -333,7 +333,7 @@ trait Trait { fn m(); } fn foo() { let _ = Trait::$0 } "#, expect![[r#" - fn m() fn() + fn m() (Trait) fn() "#]], ); } @@ -350,7 +350,7 @@ impl Trait for S {} fn foo() { let _ = S::$0 } "#, expect![[r#" - fn m() fn() + fn m() (Trait) fn() "#]], ); } @@ -367,7 +367,7 @@ impl Trait for S {} fn foo() { let _ = ::$0 } "#, expect![[r#" - fn m() fn() + fn m() (Trait) fn() "#]], ); } @@ -393,14 +393,14 @@ trait Sub: Super { fn foo() { T::$0 } "#, expect![[r#" - ta SubTy type SubTy; - ta Ty type Ty; - ct C2 const C2: (); - fn subfunc() fn() - me submethod(…) fn(&self) - ct CONST const CONST: u8; - fn func() fn() - me method(…) fn(&self) + ta SubTy (Sub) type SubTy; + ta Ty (Super) type Ty; + ct C2 (Sub) const C2: (); + fn subfunc() (Sub) fn() + me submethod(…) (Sub) fn(&self) + ct CONST (Super) const CONST: u8; + fn func() (Super) fn() + me method(…) (Super) fn(&self) "#]], ); } @@ -433,14 +433,14 @@ impl Sub for Wrap { } "#, expect![[r#" - ta SubTy type SubTy; - ta Ty type Ty; - ct CONST const CONST: u8 = 0; - fn func() fn() - me method(…) fn(&self) - ct C2 const C2: () = (); - fn subfunc() fn() - me submethod(…) fn(&self) + ta SubTy (Sub) type SubTy; + ta Ty (Super) type Ty; + ct CONST (Super) const CONST: u8 = 0; + fn func() (Super) fn() + me method(…) (Super) fn(&self) + ct C2 (Sub) const C2: () = (); + fn subfunc() (Sub) fn() + me submethod(…) (Sub) fn(&self) "#]], ); } diff --git a/crates/ide_completion/src/render/const_.rs b/crates/ide_completion/src/render/const_.rs index 8add369e47..20db851e8f 100644 --- a/crates/ide_completion/src/render/const_.rs +++ b/crates/ide_completion/src/render/const_.rs @@ -1,6 +1,6 @@ //! Renderer for `const` fields. -use hir::HasSource; +use hir::{AsAssocItem, HasSource, ModuleDef}; use ide_db::SymbolKind; use syntax::{ ast::{Const, NameOwner}, @@ -37,7 +37,7 @@ impl<'a> ConstRender<'a> { let detail = self.detail(); let mut item = - CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); + CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name.clone()); item.kind(SymbolKind::Const) .set_documentation(self.ctx.docs(self.const_)) .set_deprecated( @@ -46,6 +46,17 @@ impl<'a> ConstRender<'a> { ) .detail(detail); + 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()); + } + } + } + Some(item.build()) } diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index 19f2c86e9c..002d545576 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs @@ -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 { diff --git a/crates/ide_completion/src/render/type_alias.rs b/crates/ide_completion/src/render/type_alias.rs index e0234171ac..073663e50f 100644 --- a/crates/ide_completion/src/render/type_alias.rs +++ b/crates/ide_completion/src/render/type_alias.rs @@ -1,6 +1,6 @@ //! Renderer for type aliases. -use hir::HasSource; +use hir::{AsAssocItem, HasSource, ModuleDef}; use ide_db::SymbolKind; use syntax::{ ast::{NameOwner, TypeAlias}, @@ -50,7 +50,7 @@ impl<'a> TypeAliasRender<'a> { let detail = self.detail(); let mut item = - CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); + CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name.clone()); item.kind(SymbolKind::TypeAlias) .set_documentation(self.ctx.docs(self.type_alias)) .set_deprecated( @@ -59,6 +59,17 @@ impl<'a> TypeAliasRender<'a> { ) .detail(detail); + 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()); + } + } + } + Some(item.build()) } diff --git a/crates/ide_completion/src/tests.rs b/crates/ide_completion/src/tests.rs index 6bc25add4f..454ef914c1 100644 --- a/crates/ide_completion/src/tests.rs +++ b/crates/ide_completion/src/tests.rs @@ -126,7 +126,7 @@ fn render_completion_list(completions: Vec) -> String { s.chars().count() } let label_width = - completions.iter().map(|it| monospace_width(it.label())).max().unwrap_or_default().min(16); + completions.iter().map(|it| monospace_width(it.label())).max().unwrap_or_default().min(22); completions .into_iter() .map(|it| { diff --git a/crates/ide_completion/src/tests/item_list.rs b/crates/ide_completion/src/tests/item_list.rs index 77f00e8e5c..8cd5208cc4 100644 --- a/crates/ide_completion/src/tests/item_list.rs +++ b/crates/ide_completion/src/tests/item_list.rs @@ -30,7 +30,7 @@ fn in_mod_item_list() { sn tmod (Test module) sn tfn (Test function) sn macro_rules - ma makro!(…) #[macro_export] macro_rules! makro + ma makro!(…) #[macro_export] macro_rules! makro "##]], ) } @@ -58,9 +58,9 @@ fn in_source_file_item_list() { sn tmod (Test module) sn tfn (Test function) sn macro_rules - ma makro!(…) #[macro_export] macro_rules! makro + ma makro!(…) #[macro_export] macro_rules! makro md module - ma makro!(…) #[macro_export] macro_rules! makro + ma makro!(…) #[macro_export] macro_rules! makro "##]], ) } diff --git a/crates/ide_completion/src/tests/type_pos.rs b/crates/ide_completion/src/tests/type_pos.rs index 1ab47b27e8..c34b4b4f85 100644 --- a/crates/ide_completion/src/tests/type_pos.rs +++ b/crates/ide_completion/src/tests/type_pos.rs @@ -140,7 +140,7 @@ trait Trait2 { fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {} "#, expect![[r#" - ta Foo = type Foo; + ta Foo = (Trait2) type Foo; tp T cp CONST_PARAM tt Trait @@ -151,7 +151,7 @@ fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {} md module st Unit ct CONST - ma makro!(…) macro_rules! makro + ma makro!(…) macro_rules! makro bt u32 "#]], );