mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/vim-go/autoload/go/rename.vim

70 lines
2.0 KiB
VimL
Raw Normal View History

2014-10-31 17:30:24 -04:00
if !exists("g:go_gorename_bin")
let g:go_gorename_bin = "gorename"
endif
2016-02-20 08:13:10 -05:00
if !exists("g:go_gorename_prefill")
let g:go_gorename_prefill = 1
endif
2015-12-08 08:20:04 -05:00
function! go#rename#Rename(bang, ...)
2014-10-31 17:30:24 -04:00
let to = ""
if a:0 == 0
2015-07-13 06:22:46 -04:00
let from = expand("<cword>")
let ask = printf("vim-go: rename '%s' to: ", from)
2016-02-20 08:13:10 -05:00
if g:go_gorename_prefill
let to = input(ask, from)
else
let to = input(ask)
endif
redraw!
if empty(to)
return
endif
2014-10-31 17:30:24 -04:00
else
let to = a:1
endif
"return with a warning if the bin doesn't exist
2016-02-20 08:13:10 -05:00
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
if empty(bin_path)
return
2014-10-31 17:30:24 -04:00
endif
2015-07-13 06:22:46 -04:00
let fname = expand('%:p')
2016-03-20 14:01:44 -04:00
let pos = go#util#OffsetCursor()
2015-01-18 07:58:28 -05:00
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
let out = go#tool#ExecuteInDir(cmd)
" 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')
2016-02-20 08:13:10 -05:00
let l:listtype = "quickfix"
2016-05-14 07:57:54 -04:00
if go#util#ShellError() != 0
2015-12-08 08:20:04 -05:00
let errors = go#tool#ParseErrors(split(out, '\n'))
2016-02-20 08:13:10 -05:00
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
2015-12-08 08:20:04 -05:00
if !empty(errors) && !a:bang
2016-02-20 08:13:10 -05:00
call go#list#JumpToFirst(l:listtype)
2016-01-05 13:18:45 -05:00
elseif empty(errors)
" failed to parse errors, output the original content
call go#util#EchoError(out)
2015-12-08 08:20:04 -05:00
endif
return
2014-10-31 17:30:24 -04:00
else
2016-02-20 08:13:10 -05:00
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
2014-10-31 17:30:24 -04:00
redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
endif
" refresh the buffer so we can see the new content
2015-12-08 08:20:04 -05:00
" 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.
2014-10-31 17:30:24 -04:00
silent execute ":e"
endfunction
" vim:ts=4:sw=4:et
"