Skip to content

Commit e42203b

Browse files
authored
Support all of rename response formats (#1387)
1 parent c0325a8 commit e42203b

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

autoload/lsp/ui/vim.vim

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function! lsp#ui#vim#rename() abort
119119
\ 'textDocument': lsp#get_text_document_identifier(),
120120
\ 'position': lsp#get_position(),
121121
\ },
122-
\ 'on_notification': function('s:handle_rename_prepare', [l:server, l:command_id, 'rename_prepare']),
122+
\ 'on_notification': function('s:handle_rename_prepare', [l:server, l:command_id, 'rename_prepare', expand('<cword>'), lsp#get_position()]),
123123
\ })
124124
return
125125
endif
@@ -270,7 +270,7 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
270270
endif
271271
endfunction
272272

273-
function! s:handle_rename_prepare(server, last_command_id, type, data) abort
273+
function! s:handle_rename_prepare(server, last_command_id, type, cword, position, data) abort
274274
if a:last_command_id != lsp#_last_command()
275275
return
276276
endif
@@ -279,8 +279,28 @@ function! s:handle_rename_prepare(server, last_command_id, type, data) abort
279279
call lsp#utils#error('Failed to retrieve '. a:type . ' for ' . a:server . ': ' . lsp#client#error_message(a:data['response']))
280280
return
281281
endif
282+
let l:result = a:data['response']['result']
282283

283-
let l:range = a:data['response']['result']
284+
" Check response: null.
285+
if empty(l:result)
286+
echo 'The ' . a:server . ' returns for ' . a:type . ' (The rename request may be invalid at the given position).'
287+
return
288+
endif
289+
290+
" Check response: { defaultBehavior: boolean }.
291+
if has_key(l:result, 'defaultBehavior')
292+
call timer_start(1, {x->s:rename(a:server, input('new name: ', a:cword), a:position)})
293+
return
294+
endif
295+
296+
" Check response: { placeholder: string }
297+
if has_key(l:result, 'placeholder') && !empty(l:result['placeholder'])
298+
call timer_start(1, {x->s:rename(a:server, input('new name: ', a:cword), a:position)})
299+
return
300+
endif
301+
302+
" Check response: { range: Range } | Range
303+
let l:range = get(l:result, 'range', l:result)
284304
let l:lines = getline(1, '$')
285305
let [l:start_line, l:start_col] = lsp#utils#position#lsp_to_vim('%', l:range['start'])
286306
let [l:end_line, l:end_col] = lsp#utils#position#lsp_to_vim('%', l:range['end'])

0 commit comments

Comments
 (0)