mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
fixup: include more information for impls
This commit is contained in:
parent
d50f18fb65
commit
6870bfd099
1 changed files with 40 additions and 2 deletions
|
@ -110,8 +110,23 @@ pub(crate) fn def_to_moniker(
|
||||||
// Handle associated items within a trait
|
// Handle associated items within a trait
|
||||||
if let Some(assoc) = def.as_assoc_item(db) {
|
if let Some(assoc) = def.as_assoc_item(db) {
|
||||||
let container = assoc.container(db);
|
let container = assoc.container(db);
|
||||||
if let AssocItemContainer::Trait(parent_trait) = container {
|
match container {
|
||||||
path.push(parent_trait.name(db));
|
AssocItemContainer::Trait(trait_) => {
|
||||||
|
// Because different traits can have functions with the same name,
|
||||||
|
// we have to include the trait name as part of the moniker for uniqueness.
|
||||||
|
path.push(trait_.name(db));
|
||||||
|
}
|
||||||
|
AssocItemContainer::Impl(impl_) => {
|
||||||
|
// Because a struct can implement multiple traits, for implementations
|
||||||
|
// we add both the struct name and the trait name to the path
|
||||||
|
if let Some(adt) = impl_.self_ty(db).as_adt() {
|
||||||
|
path.push(adt.name(db));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(trait_) = impl_.trait_(db) {
|
||||||
|
path.push(trait_.name(db));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +268,29 @@ pub mod module {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn moniker_for_trait_impl_function() {
|
||||||
|
check_moniker(
|
||||||
|
r#"
|
||||||
|
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
||||||
|
pub mod module {
|
||||||
|
pub trait MyTrait {
|
||||||
|
pub fn func() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MyStruct {}
|
||||||
|
|
||||||
|
impl MyTrait for MyStruct {
|
||||||
|
pub fn func$0() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"foo::module::MyStruct::MyTrait::func",
|
||||||
|
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
||||||
|
MonikerKind::Export,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn moniker_for_field() {
|
fn moniker_for_field() {
|
||||||
check_moniker(
|
check_moniker(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue