fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16k stars 1.45k forks source link

Don't allow gorename with unsaved changes #352

Closed hraban closed 9 years ago

hraban commented 9 years ago

It's not immediately obvious that gorename works on the filesystem, completely outside vim. When I have unsaved edits, this creates a conflict and I am screwed. I think at least a "warning: save your buffers before using gorename" if any unsaved buffers are detected would be nice. Or save all buffers automatically before :GoRename?

fatih commented 9 years ago

We can only detect the file you are calling gorename on it, but not the others. So if gorename is operating on other files, the scope is determined by gorename itself. Vim-go doesn't have any idea about the scope itself. I would not save all buffers, but you can do it easily with :wa which will save all changed buffers. You can combine this, with the gorename command to a mapping such as:

au FileType go nmap  <leader>e  :wa<cr><Plug>(go-rename)

So now whenever you call <leader>e it will save all buffer before executing gorename.

I'm closing this as there is not much I can do. Thanks for reporting it though, reopen if you believe this is a serious problem :)

hraban commented 9 years ago

I understand the situation, it's not a functionality problem, just a UI issue. Basically, the work-flow for using :GoRename is always this:

:wa
:GoRename whatever
:bufdo e

And if you forget any of that, you can cause yourself quite some trouble.

What would you say about a patch which:

1) Detects if any unsaved go buffers are open, and prevents GoRename from running if there are 2) executes :bufdo e after gorename

?

EDIT: Pfew, I am doing heavy refactoring, and this has bitten me three times in five minutes now. I have to abandon changes every time. Allowing a :GoRename with any unsaved .go buffer is almost never a good idea. Do you know how I can edit my vim file to never allow :GoRename to execute if any (.go or just any) buffers are open? I forget :wa.