1
0
Fork 0
mirror of synced 2024-11-17 22:45:34 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/rename.vim

78 lines
2.2 KiB
VimL
Raw Normal View History

2014-10-31 17:30:24 -04:00
if !exists("g:go_gorename_bin")
2016-06-26 07:12:36 -04:00
let g:go_gorename_bin = "gorename"
2014-10-31 17:30:24 -04:00
endif
2016-02-20 08:13:10 -05:00
if !exists("g:go_gorename_prefill")
2016-06-26 07:12:36 -04:00
let g:go_gorename_prefill = 1
2016-02-20 08:13:10 -05:00
endif
2015-12-08 08:20:04 -05:00
function! go#rename#Rename(bang, ...)
2016-06-26 07:12:36 -04:00
let to = ""
if a:0 == 0
let from = expand("<cword>")
let ask = printf("vim-go: rename '%s' to: ", from)
if g:go_gorename_prefill
let to = input(ask, from)
2014-10-31 17:30:24 -04:00
else
2016-06-26 07:12:36 -04:00
let to = input(ask)
2014-10-31 17:30:24 -04:00
endif
2016-06-26 07:12:36 -04:00
redraw!
if empty(to)
return
2014-10-31 17:30:24 -04:00
endif
2016-06-26 07:12:36 -04:00
else
let to = a:1
endif
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
"return with a warning if the bin doesn't exist
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
if empty(bin_path)
return
endif
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
let fname = expand('%:p')
let pos = go#util#OffsetCursor()
let cmd = printf('%s -offset %s -to %s', shellescape(bin_path), shellescape(printf('%s:#%d', fname, pos)), shellescape(to))
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
let out = go#tool#ExecuteInDir(cmd)
2016-06-11 09:56:50 -04:00
2016-06-26 07:12:36 -04:00
" reload all files to reflect the new changes. We explicitly call
" checktime to trigger a reload of all files. See
" http://www.mail-archive.com/vim@vim.org/msg05900.html for more info
" about the autoread bug
let current_autoread = &autoread
set autoread
silent! checktime
let &autoread = current_autoread
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" strip out newline on the end that gorename puts. If we don't remove, it
" will trigger the 'Hit ENTER to continue' prompt
let clean = split(out, '\n')
let l:listtype = "quickfix"
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
elseif empty(errors)
" failed to parse errors, output the original content
call go#util#EchoError(out)
2014-10-31 17:30:24 -04:00
endif
2016-06-26 07:12:36 -04:00
return
else
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
endif
2014-10-31 17:30:24 -04:00
2016-06-26 07:12:36 -04:00
" refresh the buffer so we can see the new content
" TODO(arslan): also find all other buffers and refresh them too. For this
" we need a way to get the list of changes from gorename upon an success
" change.
silent execute ":e"
2014-10-31 17:30:24 -04:00
endfunction
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et