@@ -32,6 +32,7 @@ function! lsp#ui#vim#code_action#do(option) abort
32
32
let l: range = lsp#utils#range#_get_current_line_range ()
33
33
endif
34
34
35
+ let l: bufnr = bufnr (' %' )
35
36
let l: command_id = lsp#_new_command ()
36
37
for l: server_name in l: server_names
37
38
let l: diagnostic = lsp#ui#vim#diagnostics#get_diagnostics_under_cursor (l: server_name )
@@ -46,13 +47,13 @@ function! lsp#ui#vim#code_action#do(option) abort
46
47
\ },
47
48
\ },
48
49
\ ' sync' : l: sync ,
49
- \ ' on_notification' : function (' s:handle_code_action' , [l: server_name , l: command_id , l: sync , l: query ]),
50
+ \ ' on_notification' : function (' s:handle_code_action' , [l: server_name , l: command_id , l: sync , l: query, l: bufnr ]),
50
51
\ })
51
52
endfor
52
53
echo ' Retrieving code actions ...'
53
54
endfunction
54
55
55
- function ! s: handle_code_action (server_name, command_id, sync , query, data) abort
56
+ function ! s: handle_code_action (server_name, command_id, sync , query, bufnr , data) abort
56
57
" Ignore old request.
57
58
if a: command_id != lsp#_last_command ()
58
59
return
@@ -87,40 +88,35 @@ function! s:handle_code_action(server_name, command_id, sync, query, data) abort
87
88
88
89
" Execute code action.
89
90
if 0 < l: index && l: index <= len (l: code_actions )
90
- call s: handle_one_code_action (a: server_name , a: sync , l: code_actions [l: index - 1 ])
91
+ call s: handle_one_code_action (a: server_name , a: sync , a: bufnr , l: code_actions [l: index - 1 ])
91
92
endif
92
93
endfunction
93
94
94
- function ! s: handle_executeCommand (server_name, command_or_code_action, data) abort
95
- if lsp#client#is_error (a: data [' response' ])
96
- call lsp#utils#error (' Failed to ' . a: command_or_code_action [' command' ] . ' for ' . a: server_name . ' : ' . lsp#client#error_message (a: data [' response' ]))
97
- return
98
- endif
99
- endfunction
100
-
101
- function ! s: handle_one_code_action (server_name, sync , command_or_code_action) abort
95
+ function ! s: handle_one_code_action (server_name, sync , bufnr , command_or_code_action) abort
102
96
" has WorkspaceEdit.
103
97
if has_key (a: command_or_code_action , ' edit' )
104
98
call lsp#utils#workspace_edit#apply_workspace_edit (a: command_or_code_action [' edit' ])
105
99
endif
106
100
107
101
" Command.
108
102
if has_key (a: command_or_code_action , ' command' ) && type (a: command_or_code_action [' command' ]) == type (' ' )
109
- call lsp#send_request (a: server_name , {
110
- \ ' method' : ' workspace/executeCommand' ,
111
- \ ' params' : a: command_or_code_action ,
112
- \ ' sync' : a: sync ,
113
- \ ' on_notification' : function (' s:handle_executeCommand' , [a: server_name , a: command_or_code_action ]),
114
- \ })
103
+ call lsp#ui#vim#execute_command#_execute ({
104
+ \ ' server_name' : a: server_name ,
105
+ \ ' command_name' : get (a: command_or_code_action , ' command' , ' ' ),
106
+ \ ' command_args' : get (a: command_or_code_action , ' arguments' , v: null ),
107
+ \ ' sync' : a: sync ,
108
+ \ ' bufnr' : a: bufnr ,
109
+ \ })
115
110
116
111
" has Command.
117
112
elseif has_key (a: command_or_code_action , ' command' ) && type (a: command_or_code_action [' command' ]) == type ({})
118
- call lsp#send_request (a: server_name , {
119
- \ ' method' : ' workspace/executeCommand' ,
120
- \ ' params' : a: command_or_code_action [' command' ],
121
- \ ' sync' : a: sync ,
122
- \ ' on_notification' : function (' s:handle_executeCommand' , [a: server_name , a: command_or_code_action ]),
123
- \ })
113
+ call lsp#ui#vim#execute_command#_execute ({
114
+ \ ' server_name' : a: server_name ,
115
+ \ ' command_name' : get (a: command_or_code_action [' command' ], ' command' , ' ' ),
116
+ \ ' command_args' : get (a: command_or_code_action [' command' ], ' arguments' , v: null ),
117
+ \ ' sync' : a: sync ,
118
+ \ ' bufnr' : a: bufnr ,
119
+ \ })
124
120
endif
125
121
endfunction
126
122
0 commit comments