@@ -147,13 +147,18 @@ lsp.document_symbols = function(opts)
147147end
148148
149149lsp .code_actions = function (opts )
150- local params = opts .params or vim .lsp .util .make_range_params ()
150+ local params = vim . F . if_nil ( opts .params , vim .lsp .util .make_range_params () )
151151
152152 params .context = {
153153 diagnostics = vim .lsp .diagnostic .get_line_diagnostics (),
154154 }
155155
156- local results_lsp , err = vim .lsp .buf_request_sync (0 , " textDocument/codeAction" , params , opts .timeout or 10000 )
156+ local results_lsp , err = vim .lsp .buf_request_sync (
157+ 0 ,
158+ " textDocument/codeAction" ,
159+ params ,
160+ vim .F .if_nil (opts .timeout , 10000 )
161+ )
157162
158163 if err then
159164 print (" ERROR: " .. err )
@@ -181,6 +186,7 @@ lsp.code_actions = function(opts)
181186 local entry = {
182187 idx = idx ,
183188 command_title = result .title :gsub (" \r\n " , " \\ r\\ n" ):gsub (" \n " , " \\ n" ),
189+ client = client ,
184190 client_name = client and client .name or " " ,
185191 command = result ,
186192 }
@@ -211,9 +217,9 @@ lsp.code_actions = function(opts)
211217
212218 local function make_display (entry )
213219 return displayer {
214- { entry .idx .. " :" , " TelescopePromptPrefix" },
215- { entry .command_title },
216- { entry .client_name , " TelescopeResultsComment" },
220+ { entry .value . idx .. " :" , " TelescopePromptPrefix" },
221+ { entry .value . command_title },
222+ { entry .value . client_name , " TelescopeResultsComment" },
217223 }
218224 end
219225
@@ -283,14 +289,10 @@ lsp.code_actions = function(opts)
283289 prompt_title = " LSP Code Actions" ,
284290 finder = finders .new_table {
285291 results = results ,
286- entry_maker = function (line )
292+ entry_maker = function (action )
287293 return {
288- valid = line ~= nil ,
289- value = line .command ,
290- ordinal = line .idx .. line .command_title ,
291- command_title = line .command_title ,
292- idx = line .idx ,
293- client_name = line .client_name ,
294+ value = action ,
295+ ordinal = action .idx .. action .command_title ,
294296 display = make_display ,
295297 }
296298 end ,
@@ -299,9 +301,24 @@ lsp.code_actions = function(opts)
299301 actions .select_default :replace (function ()
300302 local selection = action_state .get_selected_entry ()
301303 actions .close (prompt_bufnr )
302- local action = selection .value
303-
304- execute_action (transform_action (action ))
304+ local action = selection .value .command
305+ local client = selection .value .client
306+ if
307+ not action .edit
308+ and client
309+ and type (client .resolved_capabilities .code_action ) == " table"
310+ and client .resolved_capabilities .code_action .resolveProvider
311+ then
312+ client .request (" codeAction/resolve" , action , function (resolved_err , resolved_action )
313+ if resolved_err then
314+ vim .notify (resolved_err .code .. " : " .. resolved_err .message , vim .log .levels .ERROR )
315+ return
316+ end
317+ execute_action (transform_action (resolved_action ))
318+ end )
319+ else
320+ execute_action (transform_action (action ))
321+ end
305322 end )
306323
307324 return true
0 commit comments