-
Notifications
You must be signed in to change notification settings - Fork 798
Renaming interface method does not propagate change to implementing types #2275
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
Comments
I encounter this often. The workaround is tedious (manual renaming of implementations). Should be able to rename the interface method and have it rename the implementations. |
I hope this issue gets fixed soon because renaming interfaces is a basic refactoring action. |
This is bad because if you try to rename the impl method instead, it tells you to rename the interface method (which breaks everything). This doesn't seem like an exact match, but I think it's relevant? golang/go#34438 |
Yes and yes. It is possible in Goland (jetbrains) and that feature is used a lot there. Let's implement it in vscode too! |
Without any good UX I don't think this is possible. How can gopls be sure you want to change something that looks like you implement the interface you are changing? For example you could be changing |
What about using changeAnnotations with needConfirmation field set to true. It will display a confirmation prompt for every struct which currently implements the interface. User can decide which implementation has to be renamed. |
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
go version
to get version of Go from the VS Code integrated terminal.go version go1.18.1 darwin/arm64
gopls -v version
to get version of Gopls from the VS Code integrated terminal.golang.org/x/tools/gopls v0.8.4
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders.Version: 1.66.2
v0.33.1
Go: Locate Configured Go Tools
command.Share the Go related settings you have added/edited
Run
Preferences: Open Settings (JSON)
command to open your settings.json file.Share all the settings with the
go.
or["go"]
orgopls
prefixes.No go settings touched, this is a fairly clean install of vscode.
Describe the bug
Renaming a method in an interface does not rename implementations of that method. The editor is aware of the implementing methods, and even prevents you from triggering the rename from the implementing method. The editor instructs you to rename the symbol in the interface if you want to change the interface and the implementation. But following those instructions does not rename the implementation.
I expect to be able to rename an interface method and have that change propagate to all implementations. I also expect to be able to rename a method in an implementation and have that propagate to the interface and all other implementations.
I'm not sure if this is a vscode bug or a gopls bug. This flow works correctly in Goland.
Steps to reproduce the behavior:
renaming this method "do" to "dog" would make github.com/vlymar/vscode-rename-bug-report.coolDoer no longer assignable to interface doer (rename github.com/vlymar/vscode-rename-bug-report.doer.do if you intend to change both types)
Note that this exact behavior only happens if you have an explicit assignment of the implementing type to a variable with the interface type (e.g. line 12). If you don't explicitly assign to the interface type:
Screenshots or recordings
Let me know if my steps above aren't enough and I'll provide a recording.
Thanks for looking into this! Let me know how I can help.
The text was updated successfully, but these errors were encountered: