about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWilfred Hughes <wilfred@meta.com>2023-08-04 15:28:22 -0700
committerWilfred Hughes <wilfred@meta.com>2023-08-04 16:38:31 -0700
commitedabffbd5ae0fa16afd4c555442bce4e96386a8f (patch)
tree015ab1816d20fb74466969871c32caab7f185df2
parentc59bd2dc3f05692f92b5b1c76f3d08d116e63422 (diff)
downloadrust-edabffbd5ae0fa16afd4c555442bce4e96386a8f.tar.gz
rust-edabffbd5ae0fa16afd4c555442bce4e96386a8f.zip
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.
-rw-r--r--crates/ide/src/moniker.rs11
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs38
2 files changed, 49 insertions, 0 deletions
diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs
index de8c5b8e830..17f3771b1a5 100644
--- a/crates/ide/src/moniker.rs
+++ b/crates/ide/src/moniker.rs
@@ -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(_)
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index 4579aca3021..44337f955e5 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -417,6 +417,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(
             r#"