Skip to content

Commit

Permalink
Auto merge of #15393 - Wilfred:full_moniker_param, r=Veykril
Browse files Browse the repository at this point in the history
SCIP: Qualify parameters by the containing function

SCIP requires symbols to be unique, but multiple functions may have a parameter with the same name. Qualify parameters according to the containing function.
  • Loading branch information
bors committed Aug 5, 2023
2 parents 86b6b6f + edabffb commit 27e2eea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/ide/src/moniker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ pub(crate) fn def_to_moniker(
});
}

// Qualify locals/parameters by their parent definition name.
if let Definition::Local(it) = def {
let parent_name = it.parent(db).name(db);
if let Some(name) = parent_name {
description.push(MonikerDescriptor {
name: name.display(db).to_string(),
desc: MonikerDescriptorKind::Method,
});
}
}

let name_desc = match def {
// These are handled by top-level guard (for performance).
Definition::GenericParam(_)
Expand Down
38 changes: 38 additions & 0 deletions crates/rust-analyzer/src/cli/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,44 @@ pub mod module {
);
}

#[test]
fn symbol_for_param() {
check_symbol(
r#"
//- /lib.rs crate:main deps:foo
use foo::example_mod::func;
fn main() {
func(42);
}
//- /foo/lib.rs crate:foo@0.1.0,https://a.b/foo.git library
pub mod example_mod {
pub fn func(x$0: usize) {}
}
"#,
"rust-analyzer cargo foo 0.1.0 example_mod/func().(x)",
);
}

#[test]
fn symbol_for_closure_param() {
check_symbol(
r#"
//- /lib.rs crate:main deps:foo
use foo::example_mod::func;
fn main() {
func();
}
//- /foo/lib.rs crate:foo@0.1.0,https://a.b/foo.git library
pub mod example_mod {
pub fn func() {
let f = |x$0: usize| {};
}
}
"#,
"rust-analyzer cargo foo 0.1.0 example_mod/func().(x)",
);
}

#[test]
fn local_symbol_for_local() {
check_symbol(
Expand Down

0 comments on commit 27e2eea

Please sign in to comment.