Skip to content
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/cmd/gorename: fails due DO NOT EDIT comment #28175

Closed
anjmao opened this issue Oct 12, 2018 · 5 comments
Closed

x/tools/cmd/gorename: fails due DO NOT EDIT comment #28175

anjmao opened this issue Oct 12, 2018 · 5 comments

Comments

@anjmao
Copy link

anjmao commented Oct 12, 2018

It's not possible to rename using gorename if I have generated mock files. I can make it work only by manually removing DO NOT EDIT comment from generated file.
I see there is this logic

There is -force flag which is a bit scary and I don't want to break my program.

-force     causes the renaming to proceed even if conflicts were reported.
           The resulting program may be ill-formed, or experience a change
           in behaviour.

           WARNING: this flag may even cause the renaming tool to crash.
           (In due course this bug will be fixed by moving certain
           analyses into the type-checker.)

Would be great to have some flag like -report-conflicts which returns conflicts so editors can visually show conflicts. Eg. Gogland is doing the same, if there are conflicts it allows you to mark files and force rename.

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

All versions

Does this issue reproduce with the latest release?

Yes

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

All

What did you do?

  1. Generate gomock files from this interface

storage.go

type Foo struct {}

type Storage interface {
    Create(foo Foo)
}
  1. Now try to rename Foo to Bar

What did you expect to see?

Rename to work normally

What did you see instead?

Because generated gomock file contains DO NOT EDIT I get
refusing to modify generated file%s containing DO NOT EDIT marker

@gopherbot gopherbot added this to the Unreleased milestone Oct 12, 2018
@cznic
Copy link
Contributor

cznic commented Oct 12, 2018

It's not possible to rename using gorename if I have generated mock files.

To rename something in a generated file one changes the generator. I don't see why gorename should ever touch generated files, quite the opposite.

This is IMO working as intended.

@ysmolski
Copy link
Member

Even if it is the way it supposed to work - I like that gorename stays on the safe side - it can break a flow when somebody wants to change declaration that happens outside of "DO NOT EDIT" files. But do people usually get stumbled onto this often?

@anjmao can you describe exactly how did you use gorename and did you find the fix for this situation at all?

@ysmolski
Copy link
Member

Offtopic note. It seems to me that gorename does not receive much love recently. Is it because it's not widely used tool or just authors has shifted their attention?.. I wonder if gorename is used only within emacs and vim.

@anjmao
Copy link
Author

anjmao commented Nov 22, 2018

@ysmolsky Solution is simple, remove DO NOT EDIT comment in generated file.

@anjmao anjmao closed this as completed Nov 22, 2018
@myitcv
Copy link
Member

myitcv commented Nov 22, 2018

@anjmao I think you are after:

-d         display diffs instead of rewriting files

As you say, -force is intended for the use case where you need to "force" the rename to happen in generated files (because to ignore generated files would, in some situations) cause the rename to fail because the result does not type-check).

@golang golang locked and limited conversation to collaborators Nov 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants