Skip to content

Commit 27e2eea

Browse files
committed
Auto merge of rust-lang#15393 - Wilfred:full_moniker_param, r=Veykril
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.
2 parents 86b6b6f + edabffb commit 27e2eea

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

crates/ide/src/moniker.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ pub(crate) fn def_to_moniker(
177177
});
178178
}
179179

180+
// Qualify locals/parameters by their parent definition name.
181+
if let Definition::Local(it) = def {
182+
let parent_name = it.parent(db).name(db);
183+
if let Some(name) = parent_name {
184+
description.push(MonikerDescriptor {
185+
name: name.display(db).to_string(),
186+
desc: MonikerDescriptorKind::Method,
187+
});
188+
}
189+
}
190+
180191
let name_desc = match def {
181192
// These are handled by top-level guard (for performance).
182193
Definition::GenericParam(_)

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,44 @@ pub mod module {
416416
);
417417
}
418418

419+
#[test]
420+
fn symbol_for_param() {
421+
check_symbol(
422+
r#"
423+
//- /lib.rs crate:main deps:foo
424+
use foo::example_mod::func;
425+
fn main() {
426+
func(42);
427+
}
428+
//- /foo/lib.rs crate:[email protected],https://a.b/foo.git library
429+
pub mod example_mod {
430+
pub fn func(x$0: usize) {}
431+
}
432+
"#,
433+
"rust-analyzer cargo foo 0.1.0 example_mod/func().(x)",
434+
);
435+
}
436+
437+
#[test]
438+
fn symbol_for_closure_param() {
439+
check_symbol(
440+
r#"
441+
//- /lib.rs crate:main deps:foo
442+
use foo::example_mod::func;
443+
fn main() {
444+
func();
445+
}
446+
//- /foo/lib.rs crate:[email protected],https://a.b/foo.git library
447+
pub mod example_mod {
448+
pub fn func() {
449+
let f = |x$0: usize| {};
450+
}
451+
}
452+
"#,
453+
"rust-analyzer cargo foo 0.1.0 example_mod/func().(x)",
454+
);
455+
}
456+
419457
#[test]
420458
fn local_symbol_for_local() {
421459
check_symbol(

0 commit comments

Comments
 (0)