@@ -119,7 +119,7 @@ function! lsp#ui#vim#rename() abort
119
119
\ ' textDocument' : lsp#get_text_document_identifier (),
120
120
\ ' position' : lsp#get_position (),
121
121
\ },
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 () ]),
123
123
\ })
124
124
return
125
125
endif
@@ -270,7 +270,7 @@ function! s:handle_location(ctx, server, type, data) abort "ctx = {counter, list
270
270
endif
271
271
endfunction
272
272
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
274
274
if a: last_command_id != lsp#_last_command ()
275
275
return
276
276
endif
@@ -279,8 +279,28 @@ function! s:handle_rename_prepare(server, last_command_id, type, data) abort
279
279
call lsp#utils#error (' Failed to retrieve ' . a: type . ' for ' . a: server . ' : ' . lsp#client#error_message (a: data [' response' ]))
280
280
return
281
281
endif
282
+ let l: result = a: data [' response' ][' result' ]
282
283
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 )
284
304
let l: lines = getline (1 , ' $' )
285
305
let [l: start_line , l: start_col ] = lsp#utils#position#lsp_to_vim (' %' , l: range [' start' ])
286
306
let [l: end_line , l: end_col ] = lsp#utils#position#lsp_to_vim (' %' , l: range [' end' ])
0 commit comments