Skip to content

Commit

Permalink
Merge pull request #3698 from bhcleek/rename/gopls-rename
Browse files Browse the repository at this point in the history
rename: add support for gopls rename
  • Loading branch information
bhcleek authored Dec 27, 2024
2 parents 2072091 + 3b3e5fd commit 95136df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@ function! go#rename#Rename(bang, ...) abort
let l:bin = go#config#RenameCommand()

" return with a warning if the bin doesn't exist
let bin_path = go#path#CheckBinPath(l:bin)
let bin_path = go#path#CheckBinPath(substitute(l:bin, 'gopls rename$', 'gopls', ''))
if empty(bin_path)
return
endif

let fname = expand('%:p')
let pos = go#util#OffsetCursor()
let offset = printf('%s:#%d', fname, pos)

if l:bin == 'gopls'
call go#lsp#Rename(to_identifier)
return
endif

let fname = expand('%:p')
let pos = go#util#OffsetCursor()

let args = []
if l:bin == 'gorename'
let offset = printf('%s:#%d', fname, pos)
let l:args = extend(l:args, ['-tags', go#config#BuildTags(), '-offset', offset, '-to', to_identifier])
elseif l:bin == 'gopls rename'
let offset = printf('%s:#%d', fname, pos)
let l:args = extend(l:args, ['rename', '-write', offset, to_identifier])
else
call go#util#EchoWarning('unexpected rename command')
endif
Expand Down
2 changes: 1 addition & 1 deletion doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ default it is set to edit.
*'g:go_rename_command'*

Use this option to define which tool is used to rename. By default `gopls`
is used. Valid options are `gorename` and `gopls`.
is used. Valid options are `gopls`, `gopls rename`, and `gorename`.
>
let g:go_rename_command = 'gopls'
<
Expand Down

0 comments on commit 95136df

Please sign in to comment.