-
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: add support for 'refactor.extract.constant' code actions #37170
Comments
Change https://golang.org/cl/221917 mentions this issue: |
Change https://golang.org/cl/241957 mentions this issue: |
https://golang.org/cl/241957 and https://golang.org/cl/240182 support extracting a function and variable, respectively, as a code action. The following are open issues with function extraction:
|
Extract function is a code action, similar to extract variable. After highlighting a selection, if valid, the lightbulb appears to trigger extraction. The current implementation does not allow users to extract selections with a return statement. Updates golang/go#37170 Change-Id: I5fc3b19cf7dbca4407ecf0cc37017661223614d1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/241957 Run-TryBot: Rebecca Stambler <[email protected]> Run-TryBot: Josh Baum <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
Change https://golang.org/cl/243650 mentions this issue: |
Previously, users could not extract code that contained a return statement. Now, users can extract code with return statements, as long as the statements are nested within an if, case, or other control flow statement. Updates golang/go#37170 Change-Id: I2df52d0241517472decabce3666a32392ff257bd Reviewed-on: https://go-review.googlesource.com/c/tools/+/243650 Run-TryBot: Josh Baum <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
Change https://golang.org/cl/312469 mentions this issue: |
Change https://golang.org/cl/313211 mentions this issue: |
If there is a return statement that is guaranteed to execute in the selection to extract to function, then the result of calling the extracted function can be directly returned. Updates golang/go#37170 Change-Id: I6454e4107d670e4a1bc9048b2e1073fc80fc78ab Reviewed-on: https://go-review.googlesource.com/c/tools/+/312469 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
Due to the limitations of comments in ast, it is difficult to move comments. The extract function feature currently does not handle comments at all. This change instead prints the comments that would have been lost above the call to the function, so that the user can easily recover them. Otherwise, it was possible for users to lose comments and not notice. Updates golang/go#37170 Change-Id: I1e2d865f5deddefbb0417732490decbdfcde5f3d Reviewed-on: https://go-review.googlesource.com/c/tools/+/313211 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
Change https://golang.org/cl/351989 mentions this issue: |
@suerta-git: What refactoring would you like to see there? |
@stamblerre I am expecting to see |
Ok, if you are seeing a refactoring there but it doesn't work with the hotkey, then this is probably a VS Code bug, not a bug in the extension. Please file an issue with https://github.com/microsoft/vscode. |
@stamblerre so you mean this extension already provides the funtionality for 'refactor.extract.constant/variable', but the hotkey doesn't work due to some reason like a vscode bug, right? |
Oh actually- now I see the issue. We don't actually offer |
Hi @stamblerre thanks for your reply. I tried to reinstall my vscode and restore to the initial state. Then set one customized shortcut like this in
The issue still exists: Using quick fix ( Using shortcut ( As a reference, for other languages, Seems even though vscode provides the ability for customizing shortcuts, this feature is not well supported by language extensions. Not sure if it is due to some bugs in vscode. |
gopls sets the codeActionKind for
We should definitely consider being more specific for the code action kinds to enable keybindings like this. |
CanExtract strips of the whitespace on either end of the range in order to get an exact range to extract to function. We can do the same thing for comments by moving adjusting the range if the start or end positions contain the position. Updates golang/go#37170 Fixes golang/go#54816 Change-Id: I3508c822434400f084a273730380c89611803e97 Reviewed-on: https://go-review.googlesource.com/c/tools/+/351989 Reviewed-by: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Change https://go.dev/cl/564338 mentions this issue: |
I've started attacking this issue at https://go.dev/cl/564338 and added tests/enabled the usage of One possible issue is that I have not implemented a new type of code action for constants- the |
Thanks, @NateWilliams2. I commented on your CL. In order to check if an expression is constant, we need type information. We can discuss further on the CL, if you want. |
Change https://go.dev/cl/565235 mentions this issue: |
Change https://go.dev/cl/567135 mentions this issue: |
Change https://go.dev/cl/633257 mentions this issue: |
Change https://go.dev/cl/633717 mentions this issue: |
See microsoft/vscode-go#3040.
https://microsoft.github.io/language-server-protocol/specifications/specification-3-15/#textDocument_codeAction has more details on the possibilities here.
The function refactoring can be implemented by making use of guru's freevars code.
The text was updated successfully, but these errors were encountered: