-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: renaming method of an in-use interface fails #34438
Comments
Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here. |
In general I am not sure that is actually viable. |
I don't disagree. The only reason I tried it on the interface at all was in response to a message from gopls when I tried it on the implementation (in retrospect, I probably shouldn't have expected that to work either...). The message from gopls was
Maybe that message is the actual issue, directing users to try a thing that probably isn't reasonable. |
I guess we should think what the ideal experience is. |
Is there a workaround for doing this kind of rename? assuming a simple example like the one provided: just an interface and an implementation. |
Using the example from https://play.golang.org/p/YPivBBZLhZ8 from earlier it's not possible to rename $ gopls version
golang.org/x/tools/gopls 0.4.1
golang.org/x/tools/gopls@v0.4.1-pre2 h1:X5vb657+UV0LeFGyLzTdYti9nkyllZoLaKsebuW8p1M=
$ gopls rename -w main.go:11:13 B
gopls: renaming this method "A" to "B" would make github.com/golang/go/issues/34438.impl no longer assignable to interface X (rename github.com/golang/go/issues/34438.X.A if you intend to change both types)
$ gopls rename -w main.go:6:2 B
gopls: internal error: during renaming of abstract method func (github.com/golang/go/issues/34438.X).A() int changedMethods=false, coupled method=func (github.com/golang/go/issues/34438.impl).A() int Please file a bug report One path forward would be to allow multiple renames in the same invocation, i.e. to allow $ gopls rename -w main.go:6:2 B main.go:11:13 B |
I suppose this is the price we pay for having structs not need to declare what interfaces they implement. I personally prefer having the freedom to rename interface functions and their implementers as I please versus not needing to declare what interfaces my structs implement. UPDATE: GoLand seems to support renaming interface functions and its implementers. See here. |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Minimal example:
https://play.golang.org/p/sDBH3VQY5TF
Attempt to rename the
X.A()
method usinggopls
.What did you expect to see?
X.A
, andimpl.A
should be renamedWhat did you see instead?
gopls
reports an error:The text was updated successfully, but these errors were encountered: