-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/tools/gopls: support selection range request #36679
Comments
I'm interested in having a look at this one. Would you suggest that I follow the same advice as over here (#47558 (comment)) to get started? |
Hi @rneatherway, sorry for the slow response. Sure this is a good starter project, and a good way to get started would be to solve the problem outside of gopls using go/ast: given a position and an ast.File, can you find interesting selection ranges? Then we can help you wire this into gopls' request handling. |
No problem at all, thanks for the guidance 👍 |
👋 I've had a go at this and put together a function of this signature: type Selection struct {
StartLine int
StartCol int
EndLine int
EndCol int
}
func expandSelection(
fileSet *token.FileSet,
file *ast.File,
s Selection,
) Selection It's up at https://github.com/rneatherway/expand along with some tests/examples. Note that it also requires a |
Thanks! We'll take a look. |
Sorry to prod, but if you have any advice on wiring this up I'd be interested to try that too. |
@rneatherway so sorry that this fell through the cracks. Entirely my fault, and thank you for following up. What you've done looks good! I think there is a utility that may be helpful, which operates similarly to your algorithm: Using this traversal, you can start from the innermost enclosing interval, and work outwards until you find an interesting node, then compute its range. One note: for simplicity I suggest working with a |
Oh nice, thanks! I've simplified the code in my repository using that helper method. The input and output are now in terms of offsets so hopefully this is ready to try integrating. It's hard to go much further without knowing what the language server has available when this will be invoked. |
Yep, let's start integrating it. The entry point for this handler is A similar type of request is |
(aside: converting to int does not convert token.Pos to offsets, as token.Pos is relative to some file base position. You must use token.File.Offset to convert to an offset) |
@findleyr I've got a branch visible at https://github.com/golang/tools/compare/master...rneatherway:tools:selectionrange?expand=1 including extending the tests to support this new case. A few things came up while working on it that I'd appreciate your opinion on:
|
Change https://go.dev/cl/452315 mentions this issue: |
I got far enough that I decided to open the pull request: golang/tools#416 I guess my last question would be whether you had any advice on how to test this change with VSCode "live". So far I have tried |
@hyangah do we need to register a new selection range provider? It may be that this needs a vscode-go change as well. |
I've got a feeling that we need to do something like https://github.com/elm-tooling/elm-language-server/blob/c7e21144c0833690a58bbf5f5e6b44b123c1fc9f/src/providers/selectionRangeProvider.ts, but looking in the vscode-go repository a lot of the providers are in a |
Change https://go.dev/cl/458199 mentions this issue: |
Thanks for implementing the feature. That's neat. |
The server needs to tell the client it's supporting this feature. Updates golang/go#36679 Change-Id: Ia6fdb35ea90fac81367d4b45721928c606344afc Reviewed-on: https://go-review.googlesource.com/c/tools/+/458199 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]>
Ah thanks! I wasn't sure how the final wiring up should look. Is there anything more we need to do in vscode-go? |
Forked from microsoft/vscode-go#2984.
See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_selectionRange.
The text was updated successfully, but these errors were encountered: