I just want to ask what is the proper way of renaming go code?
example I have this.
on the directory github.com\samp\pack\pack.go
package pack
// New is a new package
func New(){
}
then I tried to rename it using gorename -from '"github.com/samp/pack".pack.New' -to New1 but I got always gorename: -from '"github.com/samp/pack.pack.New"': invalid expression I already tried to remove the pack but still the same invalid expression.
BTW I want also to ask if there a good blog or documentation about gorename? I cant find any.
This is strange. I tested gorename on my end (even with the same path, file name and file contents that you posted here), and it works without problems.
Did you double-check if the GOPATH is set in the Command Prompt window where you run gorename? (go env GOPATH)
Otherwise it could indeed be an OS-specific issue - I tested on a Mac.
In this case, try the -v option to make gorename chattier.
That is what I am thinking, I also try it on a fresh Win 10 install on hyper-v got same result. I will download Ubuntu, try it there.
Also the -offset sometimes will work sometimes will now but most of the time it will say no identifier at this position on Emacs and the stranger is sometimes it will rename the other variable on the same line.
I can successfully rename it using atom with go-rename package, but I don’t like opening atom just to do a rename.
BTW I took print screen, the -v option doesn’t give any more details.
I suspect a quoting issue. On unixes, the -from '"github.com/samp/pack".New' thing will have the outer set of quotes removed (i.e., interpreted) by the shell and sent to the program as "github.com/samp/pack".New while your command on Windows will probably send the actual single quotes as well to the program.
Good point. This would explain why the error message still contains the single quotes (wrapped into a new pair of double quotes).
(As a side note, this also reveals that my second reply was quite pointless - I was not aware that the gorename error message removes the double quotes around the path, and adds new double quotes around everything instead.)
In order gorename to work on command prompt just remove the single quotes and escape the double quotes, while on powershell just escape the double quotes.