@@ -382,74 +382,6 @@ function! lsp#ui#vim#document_symbol() abort
382
382
echo ' Retrieving document symbols ...'
383
383
endfunction
384
384
385
- " Returns currently selected range. If nothing is selected, returns empty
386
- " dictionary.
387
- "
388
- " @returns
389
- " Range - https://microsoft.github.io/language-server-protocol/specification#range
390
- function ! s: get_visual_selection_range () abort
391
- " TODO: unify this method with s:get_visual_selection_pos()
392
- let [l: line_start , l: column_start ] = getpos (" '<" )[1 :2 ]
393
- let [l: line_end , l: column_end ] = getpos (" '>" )[1 :2 ]
394
- call lsp#log ([l: line_start , l: column_start , l: line_end , l: column_end ])
395
- if l: line_start == 0
396
- return {}
397
- endif
398
- " For line selection, column_end is a very large number, so trim it to
399
- " number of characters in this line.
400
- if l: column_end - 1 > len (getline (l: line_end ))
401
- let l: column_end = len (getline (l: line_end )) + 1
402
- endif
403
- let l: char_start = lsp#utils#to_char (' %' , l: line_start , l: column_start )
404
- let l: char_end = lsp#utils#to_char (' %' , l: line_end , l: column_end )
405
- return {
406
- \ ' start' : { ' line' : l: line_start - 1 , ' character' : l: char_start },
407
- \ ' end' : { ' line' : l: line_end - 1 , ' character' : l: char_end },
408
- \}
409
- endfunction
410
-
411
- " https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction
412
- function ! lsp#ui#vim#code_action () abort
413
- let l: servers = filter (lsp#get_whitelisted_servers (), ' lsp#capabilities#has_code_action_provider(v:val)' )
414
- let l: command_id = lsp#_new_command ()
415
- let l: diagnostic = lsp#ui#vim#diagnostics#get_diagnostics_under_cursor ()
416
-
417
- if len (l: servers ) == 0
418
- call s: not_supported (' Code action' )
419
- return
420
- endif
421
-
422
- let l: range = s: get_visual_selection_range ()
423
- if empty (l: range )
424
- if empty (l: diagnostic )
425
- echo ' No diagnostics found under the cursors'
426
- return
427
- else
428
- let l: range = l: diagnostic [' range' ]
429
- let l: diagnostics = [l: diagnostic ]
430
- end
431
- else
432
- let l: diagnostics = []
433
- endif
434
-
435
- for l: server in l: servers
436
- call lsp#send_request (l: server , {
437
- \ ' method' : ' textDocument/codeAction' ,
438
- \ ' params' : {
439
- \ ' textDocument' : lsp#get_text_document_identifier (),
440
- \ ' range' : l: range ,
441
- \ ' context' : {
442
- \ ' diagnostics' : l: diagnostics ,
443
- \ ' only' : [' ' , ' quickfix' , ' refactor' , ' refactor.extract' , ' refactor.inline' , ' refactor.rewrite' , ' source' , ' source.organizeImports' ],
444
- \ },
445
- \ },
446
- \ ' on_notification' : function (' s:handle_code_action' , [l: server , l: command_id , ' codeAction' ]),
447
- \ })
448
- endfor
449
-
450
- echo ' Retrieving code actions ...'
451
- endfunction
452
-
453
385
function ! s: handle_symbol (server, last_command_id, type , data) abort
454
386
if a: last_command_id != lsp#_last_command ()
455
387
return
@@ -582,37 +514,6 @@ function! s:handle_text_edit(server, last_command_id, type, data) abort
582
514
redraw | echo ' Document formatted'
583
515
endfunction
584
516
585
- function ! s: handle_code_action (server, last_command_id, type , data) abort
586
- if lsp#client#is_error (a: data [' response' ])
587
- call lsp#utils#error (' Failed to ' . a: type . ' for ' . a: server . ' : ' . lsp#client#error_message (a: data [' response' ]))
588
- return
589
- endif
590
-
591
- let l: codeActions = a: data [' response' ][' result' ]
592
-
593
- let l: index = 0
594
- let l: choices = []
595
-
596
- call lsp#log (' s:handle_code_action' , l: codeActions )
597
-
598
- if len (l: codeActions ) == 0
599
- echo ' No code actions found'
600
- return
601
- endif
602
-
603
- while l: index < len (l: codeActions )
604
- call add (l: choices , string (l: index + 1 ) . ' - ' . l: codeActions [index ][' title' ])
605
-
606
- let l: index += 1
607
- endwhile
608
-
609
- let l: choice = inputlist (l: choices )
610
-
611
- if l: choice > 0 && l: choice <= l: index
612
- call s: execute_command_or_code_action (a: server , l: codeActions [l: choice - 1 ])
613
- endif
614
- endfunction
615
-
616
517
function ! s: handle_type_hierarchy (ctx, server, type , data) abort " ctx = {counter, list, last_command_id}
617
518
if a: ctx [' last_command_id' ] != lsp#_last_command ()
618
519
return
@@ -679,37 +580,3 @@ function! s:get_treeitem_for_tree_hierarchy(Callback, object) dict abort
679
580
call a: Callback (' success' , s: hierarchyitem_to_treeitem (a: object ))
680
581
endfunction
681
582
682
- " @params
683
- " server - string
684
- " comand_or_code_action - Command | CodeAction
685
- function ! s: execute_command_or_code_action (server, command_or_code_action) abort
686
- if has_key (a: command_or_code_action , ' command' ) && type (a: command_or_code_action [' command' ]) == type (' ' )
687
- let l: command = a: command_or_code_action
688
- call s: execute_command (a: server , l: command )
689
- else
690
- let l: code_action = a: command_or_code_action
691
- if has_key (l: code_action , ' edit' )
692
- call lsp#utils#workspace_edit#apply_workspace_edit (a: command_or_code_action [' edit' ])
693
- endif
694
- if has_key (l: code_action , ' command' )
695
- call s: execute_command (a: server , l: code_action [' command' ])
696
- endif
697
- endif
698
- endfunction
699
-
700
- " Sends workspace/executeCommand with given command.
701
- " @params
702
- " server - string
703
- " command - https://microsoft.github.io/language-server-protocol/specification#command
704
- function ! s: execute_command (server, command ) abort
705
- let l: params = {' command' : a: command [' command' ]}
706
- if has_key (a: command , ' arguments' )
707
- let l: params [' arguments' ] = a: command [' arguments' ]
708
- endif
709
- call lsp#send_request (a: server , {
710
- \ ' method' : ' workspace/executeCommand' ,
711
- \ ' params' : l: params ,
712
- \ })
713
- endfunction
714
-
715
-
0 commit comments