mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
fixup: properly handle all associated items
This commit is contained in:
parent
09c7e22ec2
commit
d50f18fb65
1 changed files with 34 additions and 23 deletions
|
@ -107,18 +107,16 @@ pub(crate) fn def_to_moniker(
|
||||||
let mut path = vec![];
|
let mut path = vec![];
|
||||||
path.extend(module.path_to_root(db).into_iter().filter_map(|x| x.name(db)));
|
path.extend(module.path_to_root(db).into_iter().filter_map(|x| x.name(db)));
|
||||||
|
|
||||||
match def {
|
// Handle associated items within a trait
|
||||||
Definition::Field(it) => path.push(it.parent_def(db).name(db)),
|
if let Some(assoc) = def.as_assoc_item(db) {
|
||||||
Definition::Function(it) => {
|
let container = assoc.container(db);
|
||||||
// Ensure that trait functions are properly namespaced with the trait name
|
if let AssocItemContainer::Trait(parent_trait) = container {
|
||||||
if let Some(assoc) = it.as_assoc_item(db) {
|
path.push(parent_trait.name(db));
|
||||||
let container = assoc.container(db);
|
|
||||||
if let AssocItemContainer::Trait(parent_trait) = container {
|
|
||||||
path.push(parent_trait.name(db));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
|
|
||||||
|
if let Definition::Field(it) = def {
|
||||||
|
path.push(it.parent_def(db).name(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
path.push(def.name(db)?);
|
path.push(def.name(db)?);
|
||||||
|
@ -208,11 +206,6 @@ pub mod module {
|
||||||
fn moniker_for_trait() {
|
fn moniker_for_trait() {
|
||||||
check_moniker(
|
check_moniker(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs crate:main deps:foo
|
|
||||||
use foo::module::func;
|
|
||||||
fn main() {
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
||||||
pub mod module {
|
pub mod module {
|
||||||
pub trait MyTrait {
|
pub trait MyTrait {
|
||||||
|
@ -224,19 +217,37 @@ pub mod module {
|
||||||
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
||||||
MonikerKind::Export,
|
MonikerKind::Export,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn moniker_for_trait_constant() {
|
||||||
check_moniker(
|
check_moniker(
|
||||||
r#"
|
r#"
|
||||||
//- /lib.rs crate:main deps:foo
|
|
||||||
use foo::module::func;
|
|
||||||
fn main() {
|
|
||||||
func();
|
|
||||||
}
|
|
||||||
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
||||||
pub mod module {
|
pub mod module {
|
||||||
pub fn func$0() {}
|
pub trait MyTrait {
|
||||||
|
const MY_CONST$0: u8;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
"foo::module::func",
|
"foo::module::MyTrait::MY_CONST",
|
||||||
|
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
||||||
|
MonikerKind::Export,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn moniker_for_trait_type() {
|
||||||
|
check_moniker(
|
||||||
|
r#"
|
||||||
|
//- /foo/lib.rs crate:foo@CratesIo:0.1.0,https://a.b/foo.git
|
||||||
|
pub mod module {
|
||||||
|
pub trait MyTrait {
|
||||||
|
type MyType$0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"foo::module::MyTrait::MyType",
|
||||||
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
r#"PackageInformation { name: "foo", repo: "https://a.b/foo.git", version: "0.1.0" }"#,
|
||||||
MonikerKind::Export,
|
MonikerKind::Export,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue