1
0
Fork 0
mirror of synced 2024-12-22 15:08:57 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/rename.vim

67 lines
2 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
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)
let to = input(ask, from)
2014-10-31 17:30:24 -04:00
redraw
else
let to = a:1
endif
"return with a warning if the bin doesn't exist
2015-07-13 06:22:46 -04:00
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
2014-10-31 17:30:24 -04:00
if empty(bin_path)
return
endif
2015-07-13 06:22:46 -04:00
let fname = expand('%:p')
2014-10-31 17:30:24 -04:00
let pos = s:getpos(line('.'), col('.'))
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')
if v:shell_error
2015-12-08 08:20:04 -05:00
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
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
2015-12-08 08:20:04 -05:00
call go#list#Clean()
call go#list#Window()
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
func! s:getpos(l, c)
if &encoding != 'utf-8'
let buf = a:l == 1 ? '' : (join(getline(1, a:l-1), "\n") . "\n")
let buf .= a:c == 1 ? '' : getline('.')[:a:c-2]
return len(iconv(buf, &encoding, 'utf-8'))
endif
return line2byte(a:l) + (a:c-2)
endfun
" vim:ts=4:sw=4:et
"