Skip to content

Add options to lsp#ui#vim#rename() to specify server #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions autoload/lsp/ui/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ function! s:rename(server, new_name, pos) abort
echo ' ... Renaming ...'
endfunction

function! lsp#ui#vim#rename() abort
" options - {
" server - 'server_name' " optional
" }
function! lsp#ui#vim#rename(options) abort
let l:servers = filter(lsp#get_allowed_servers(), 'lsp#capabilities#has_rename_prepare_provider(v:val)')
let l:prepare_support = 1
if len(l:servers) == 0
Expand All @@ -115,7 +118,16 @@ function! lsp#ui#vim#rename() abort
endif

" TODO: ask the user which server it should use to rename if there are multiple
let l:server = l:servers[0]
if has_key(a:options, 'server')
if index(l:servers, a:options['server']) >= 0
let l:server = a:options['server']
else
call s:not_supported('Renaming by ' .. a:options['server'])
return
endif
else
let l:server = l:servers[0]
endif

if l:prepare_support
call lsp#send_request(l:server, {
Expand Down
5 changes: 3 additions & 2 deletions plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ command! -nargs=* LspNextDiagnostic call lsp#internal#diagnostics#movement#_next
command! -nargs=* LspPreviousDiagnostic call lsp#internal#diagnostics#movement#_previous_diagnostics(<f-args>)
command! LspReferences call lsp#ui#vim#references({})
command! LspAddTreeReferences call lsp#ui#vim#add_tree_references()
command! LspRename call lsp#ui#vim#rename()
command! LspRename call lsp#ui#vim#rename(
\ extend({}, lsp#utils#args#_parse(<q-args>, {}, v:null)))
command! LspTypeDefinition call lsp#ui#vim#type_definition(0, <q-mods>)
command! LspTypeHierarchy call lsp#internal#type_hierarchy#show()
command! LspPeekTypeDefinition call lsp#ui#vim#type_definition(1)
Expand Down Expand Up @@ -191,7 +192,7 @@ nnoremap <silent> <plug>(lsp-next-diagnostic-nowrap) :<c-u>call lsp#internal#dia
nnoremap <silent> <plug>(lsp-previous-diagnostic) :<c-u>call lsp#internal#diagnostics#movement#_previous_diagnostics()<cr>
nnoremap <silent> <plug>(lsp-previous-diagnostic-nowrap) :<c-u>call lsp#internal#diagnostics#movement#_previous_diagnostics("-wrap=0")<cr>
nnoremap <silent> <plug>(lsp-references) :<c-u>call lsp#ui#vim#references({})<cr>
nnoremap <silent> <plug>(lsp-rename) :<c-u>call lsp#ui#vim#rename()<cr>
nnoremap <silent> <plug>(lsp-rename) :<c-u>call lsp#ui#vim#rename({})<cr>
nnoremap <silent> <plug>(lsp-type-definition) :<c-u>call lsp#ui#vim#type_definition(0)<cr>
nnoremap <silent> <plug>(lsp-type-hierarchy) :<c-u>call lsp#internal#type_hierarchy#show()<cr>
nnoremap <silent> <plug>(lsp-peek-type-definition) :<c-u>call lsp#ui#vim#type_definition(1)<cr>
Expand Down