vscode-bazel icon indicating copy to clipboard operation
vscode-bazel copied to clipboard

Code Navigation settings for Starlark files

Open arquer opened this issue 1 year ago • 7 comments

Probably not an actual issue but more like a question/feature request.

While browsing BUILD files, is there any way that I can configure where the extension will search for rules so that I can easily navigate them (Ctrl + Click)?

I ask because I have projects where my checked out directory structure might not match the one assumed by the rules in BUILD, and even when doing that I often find code navigation taking be to BUILD files located in my bazel cache or in a temporary "bazel-bin" or similar.

In other words, is there a way I can configure this extension so that Ctrl+Click on a dependency that points to another repo (@repo/path/to:rule) actually takes me to a cloned version of that repo I have?

Thanks!

arquer avatar Sep 26 '24 18:09 arquer

This functionality should be available if you configure a language server (see the README). Currently, that functionality is still experimental, also see #1 for a lot more context on the current state of language server support

vogelsgesang avatar Sep 27 '24 11:09 vogelsgesang

Oh I see, thanks, I didn't know a language server had anything to do with this so I hadn't looked into that, definitely will now.

arquer avatar Sep 28 '24 00:09 arquer

Hi @vogelsgesang , I went ahead and installed the language server (bazel-lsp) but have seen no difference in the behaviors I was explaining above. Code navigation often still takes me to bazel's cache instead of the starlark BUILD sources, even when I add bazel's cache to the list of directories to ignore.

Is there some way of debugging this you would recommend? I am pretty new to starlark/bazel and really all I want is code navigation so I can navigate a huge source code base easily.

arquer avatar Sep 28 '24 20:09 arquer

I am a bit confused.

Which language are you trying to use code navigation on? Starlark? C++? Python? some other language?

vogelsgesang avatar Sep 30 '24 11:09 vogelsgesang

Starlark! basically I wanna be able to ctrl + click on some dependencie of a bazel rule and be taken to that rule's definition

arquer avatar Sep 30 '24 16:09 arquer

👍 ok, then I understood your initial post correctly.

I am not sure how the code navigation for Starlark should work. My best bet would have been that this should work with the Starlark-LSPs. @cameron-martin and @withered-magic might be able to provide more context on what works / doesn't work regarding Starlark code navigation, yet

vogelsgesang avatar Sep 30 '24 19:09 vogelsgesang

It sounds like the ask here is for code navigation to resolve symlinks, like clangd does from memory. This may have unintended consequences on further code navigation when naively implemented, since it'll lose the context on what the bazel workspace is.

Do you mind opening an issue on bazel-lsp and starpls?

cameron-martin avatar Oct 11 '24 23:10 cameron-martin

I believe that the general request is in fact supported today already by using one of the mentioned language servers from the readme. It will allow you to control+click your way through starlark code and even to jump into external dependencies of yours.

What's important to note though is that, yes, sometimes this will take you into bazels cache directory. This is because of the way bazelmod treats external dependencies which are downloaded to the repository cache and then extracted into bazel output base. As such, from bazels perspective, this is where the external starlark code lives.

Now I understand that in your case, thats actually source code inside your repository which you probably model as an external dependency via local_override or similar. In that case the files in your output base will be symlinks to your source directory. I believe this is a boundary case that is not worth handling separately, as for your usecase you could also work on the symlinked files.

cbandera avatar Dec 12 '25 20:12 cbandera

I believe this is a boundary case that is not worth handling separately, as for your usecase you could also work on the symlinked files.

I do think resolving symlinks when going to definitions is worth considering, since I have found this feature in other language servers (I believe clangd) useful in the past. However, I believe this lives in the language servers, not this extension.

cameron-martin avatar Dec 12 '25 22:12 cameron-martin