From 6278e7f8d00252c0fb287a6d1f641d87386e44cb Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Wed, 20 Dec 2023 02:10:52 +0000 Subject: [PATCH 1/2] Fix "go to label" in bazel LSP When executing "go to definition" on a label, it would previously go to the correct file but not to the definition of that target. The reason was because we were searching for a function call where the name is the whole label. Now it parses the label to extract the name and searches using that. This doesn't work in a few cases, for example "//foo" and "@foo", where the name is implicit. However, I think to solve this we would need to implement a label parser. If one already exists, I could not find it. I imagine a lot of the code in `resolve_folder` could be simplified with the use of a label parser too. --- starlark_bin/bin/bazel.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/starlark_bin/bin/bazel.rs b/starlark_bin/bin/bazel.rs index c05778910..d63a5fcb6 100644 --- a/starlark_bin/bin/bazel.rs +++ b/starlark_bin/bin/bazel.rs @@ -768,10 +768,15 @@ impl LspContext for BazelContext { location_finder: if same_filename { None } else { - let literal = literal.to_owned(); - Some(Box::new(move |ast| { - Ok(ast.find_function_call_with_name(&literal)) - })) + match literal.split(":").last() { + None => None, + Some(name) => { + let name = name.to_owned(); + Some(Box::new(move |ast| { + Ok(ast.find_function_call_with_name(&name)) + })) + } + } }, }) }) From 329c9b1fab794d71190daac4064a667c82f1515e Mon Sep 17 00:00:00 2001 From: Cameron Martin Date: Fri, 19 Jan 2024 20:41:32 +0000 Subject: [PATCH 2/2] Use bazel label parser --- starlark_bin/bin/bazel.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/starlark_bin/bin/bazel.rs b/starlark_bin/bin/bazel.rs index 09b57b5be..566e7e60d 100644 --- a/starlark_bin/bin/bazel.rs +++ b/starlark_bin/bin/bazel.rs @@ -745,14 +745,11 @@ impl LspContext for BazelContext { location_finder: if same_filename { None } else { - match literal.split(":").last() { - None => None, - Some(name) => { - let name = name.to_owned(); - Some(Box::new(move |ast| { - Ok(ast.find_function_call_with_name(&name)) - })) - } + match Label::parse(literal) { + Err(_) => None, + Ok(label) => Some(Box::new(move |ast| { + Ok(ast.find_function_call_with_name(&label.name)) + })), } }, })