Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Cmd-click to jump to a source file from a build rule #380

Merged
merged 2 commits into from
Apr 16, 2024

Conversation

kchodorow
Copy link
Contributor

Part of issue #353.

@vogelsgesang
Copy link
Collaborator

Thanks for your contribution, @kchodorow! Much appreciated 🙂

I am admittedly not sure which future direction we want to take regarding "Starlark / Bazel language features"... Should those be provided by the language server (which has a deeper logical understanding of the StarLark code) or by the TypeScript part of this extension (as proposed in this PR)?

On a related note, I am wondering if / how we would want to support glob expressions. I guess a hover information "glob expression matched 16 files" and a list of all the matched files would be useful? Not sure...

@cameron-martin @withered-magic What is your opinion on the long-term direction in which we should go here? Should this functionality be covered by the language servers or not?

Does one of your language servers already provide comparable functionality? If none of the language servers currently provides this functionality already, I would say we should move ahead with the PR as currently proposed (to unlock immediate user benefit) and then migrate this functionality into the language servers later on...

@withered-magic
Copy link

withered-magic commented Apr 15, 2024

There was actually a similar request for starpls here, but going in the opposite direction (from source file to corresponding BUILD.bazel files): withered-magic/starpls#100. Haven't gotten a chance to look into too much but it actually should be pretty straightforward to implement!

To me it seems reasonable for these sorts of functionalities to be covered by the language server and to have the language server be the only handler for fielding goto-def/find reference requests, which this feature sounds like

@cameron-martin
Copy link
Collaborator

cameron-martin commented Apr 15, 2024

bazel-lsp does have go-to-definition from BUILD files to source files. I'm generally for trying to push as much functionality into the language servers, but I'm also not against giving a several-line fix to overlapping functionality in this extension, particularly considering no language server is enabled by default.

@vogelsgesang
Copy link
Collaborator

Works smoothly 🙂

Screen.Recording.2024-04-16.at.01.24.43.mov

One small issue which I noticed: The individual path components are linked individually (i.e. the py extension is linked, and not the complete file name). I think we can fix this by using a LocationLink instead of a Location and by setting the originSelectionRange. I think the necessary range should already be available from the variable range defined in line 43

Not introduced by you, but a patch to fix this would still be welcome :)

@vogelsgesang
Copy link
Collaborator

There was actually a similar request for starpls here, but going in the opposite direction (from source file to corresponding BUILD.bazel files): withered-magic/starpls#100. Haven't gotten a chance to look into too much but it actually should be pretty straightforward to implement!

To me it seems reasonable for these sorts of functionalities to be covered by the language server and to have the language server be the only handler for fielding goto-def/find reference requests, which this feature sounds like

Interesting idea... I didn't realize that we could also implement "go from source file to BUILD file" in the language server. So far, I was only considering the "go from BUILD file to source file" (i.e. this pull request here) in mind for the language server. I like the idea to implement both directions in the LS.

bazel-lsp does have go-to-definition from BUILD files to source files.

I just tried this out. Worked without any issues for me.

I'm generally for trying to push as much functionality into the language servers, but I'm also not against giving a several-line fix to overlapping functionality in this extension, particularly considering no language server is enabled by default.

Then let's move ahead with this PR. I am still waiting if we can fix the originSelectionRange, and will then merge this PR.

@withered-magic
Copy link

withered-magic commented Apr 16, 2024

Just landed this functionality on main for starpls! Will include it in the next release

Interesting idea... I didn't realize that we could also implement "go from source file to BUILD file" in the language server. So far, I was only considering the "go from BUILD file to source file" (i.e. this pull request here) in mind for the language server. I like the idea to implement both directions in the LS.

One thing that I realized for the opposite direction (i.e. "go to BUILD file from source file") was that the best approach for this in terms of UX wasn't super clear. To me this sounds like it'd be best fulfilled by a "Find references" request, but it's unclear how the user should issue that request (e.g. where to actually right click and select "Find references" from). As a starter I was going to just make it so that issuing a "Find references" from text that would be otherwise meaningless (e.g. blank space) would default to this behavior. But maybe it would be better to align on this here or in another thread before starting on any implementations?

@kchodorow
Copy link
Contributor Author

I was thinking it would just be a command palette option, since as you say there's no particular code we're "finding references" from.

@cameron-martin had the neat idea of having the Bazel Build Targets pane in the sidebar keep pace with whatever you currently are editing. I'm going to take a look at the API and see if that's feasible.

@vogelsgesang
Copy link
Collaborator

I was thinking it would just be a command palette option, since as you say there's no particular code we're "finding references" from.

Yes, that would also be my user interface of choice... Afaik, language servers can also contribute commands, but I never tried this before.

@kchodorow regarding this pull request at hand here: Are you still planning to improve originSelectionRange (see previous messages) or do you want me to merge this PR as is?

@withered-magic
Copy link

withered-magic commented Apr 16, 2024

Ah ok, I think my only reservation with making It a command palette option would be that other editors besides VSCode that are also using the LSP would also have to implement some custom way to use this functionality (if they have the equivalent of command palette). Language servers can definitely support custom commands though! There's a couple custom ones defined in starpls for debugging purposes.

@kchodorow
Copy link
Contributor Author

Oh, sorry, I missed the originSelectionRange comment! I'm a little confused about how to do what you're asking for... it doesn't seem like mouseover highlight is handled by this code. provideDefinition is triggered after the cmd/ctrl key is hit, AFAICT.

@vogelsgesang
Copy link
Collaborator

vogelsgesang commented Apr 16, 2024

ok, I will merge this PR and then see if can link the correct range in a follow-up commit

@vogelsgesang vogelsgesang merged commit fa38d08 into bazelbuild:master Apr 16, 2024
4 checks passed
@vogelsgesang
Copy link
Collaborator

see #382 for what I had in mind regarding originSelectionRange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants