-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: rename on a method receiver should rename all receivers for the type #41892
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
Some questions:
|
From a user perspective, I think it's better to rename even if the receiver names are not consistent at the moment, and rename as many receivers as possible. |
Some preferences from someone who just created a dupe of this issue 🤦
Fail the entire rename, so you can evaluate the conflict and decide if you still think the new receiver name is appropriate.
Rename them all, only if the issue above did not occur. |
I think this would be a relatively easy fix. Because a type may have many methods, only some of whose receivers may be safely renamed, I think the tool should be best effort: that is, it should report an error only if it cannot rename the selected receiver, but it should attempt to rename as many of the other receivers as possible. |
One question that came up during the implementation: should renaming any reference to a receiver cause renaming of all methods' receivers? Or should we enable users to selectively rename just a single receiver, by requiring some extra indication of intent for the larger operation: by renaming all receivers only when the rename was initiated at a receiver declaration, not just a reference? |
Change https://go.dev/cl/665935 mentions this issue: |
Change https://go.dev/cl/666455 mentions this issue: |
This change modifies the behavior of the new "rename receiver" operation, which affects the receivers of all methods of the same type: now, the broader renaming occurs only when the renaming is requested at the declaration of the receiver. Renaming a use of a receiver affects only that variable. + test, doc, relnote Fixes golang/go#41892 Change-Id: I54c771f51da90b8b2a25801435e81875639ab459 Reviewed-on: https://go-review.googlesource.com/c/tools/+/666455 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Initial state:
emacs -nw main.go
main.go:7:6
).M-x eglot-rename
t
) for the method receiver.What did you expect to see?
Per http://golang.org/wiki/CodeReviewComments#receiver-names:
Since the file already satisfied that consistency rule before the rename, I expect it to satisfy that rule after the rename, too: all of the method receivers should have been renamed to the new name entered in step (4).
What did you see instead?
Only the receiver for the one method was renamed.
gopls
log:The text was updated successfully, but these errors were encountered: