golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.51k stars 17.6k forks source link

x/tools/refactor/rename: does not rename example functions #21920

Open takeyourhatoff opened 7 years ago

takeyourhatoff commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go 1.9

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

What did you do?

https://play.golang.org/p/ibc3hWTjqN

Rename a function

What did you expect to see?

https://play.golang.org/p/U0pdaBJT8j

gorename to rename the function, and to rename the example function, ExampleF.

gorename correctly renames the comment above documenting the function but does not rename the example function. After the rename, the example function is no longer visible in godoc

What did you see instead?

https://play.golang.org/p/aSKw0KKxLH

agnivade commented 6 years ago

Why do you expect ExampleF to be renamed to ExampleG ? You asked F to be renamed, and it did that perfectly.

It correctly renames F in rename.go and also renames the function invocation in rename_test.go. This seems the right behavior to me.

takeyourhatoff commented 6 years ago

You are not wrong, I just think the more useful behaviour would be to rename the example function too so that godoc does not break when you use gorename. I can't think of a situation where you would not want gorename to rename the example function too.

agnivade commented 6 years ago

You can just run gorename again with passing ExampleF to ExampleG. I feel that is the simplest and the correct way.

/cc @bradfitz - does it make sense to rename ExampleF to ExampleG too ?

P.S. - I didnt know who owns gorename. Since you oversee godoc and goimports, so thought of looping you in.

bradfitz commented 6 years ago

@alandonovan owns gorename. I'll let him decide things.