add code action for buf action

neovim_0_5
ray-x 3 years ago
parent 70356e73f3
commit 5e93e2ced2

@ -66,6 +66,10 @@ Use <c-e> or `:q!` to kill the floating window, <up/down> to move and <c-o> to o
![document symbol](https://github.com/ray-x/files/blob/master/img/navigator/doc_symbol.gif?raw=true)
### Workspace Symbol
![workspace symbol](https://github.com/ray-x/files/blob/master/img/navigator/workspace_symbol.gif?raw=true)
### Diagnostic
![diagnostic](https://github.com/ray-x/files/blob/master/img/navigator/diag.jpg?raw=true)

@ -4,13 +4,13 @@ local code_action = {}
local gui = require "navigator.gui"
local config = require("navigator").config_values
local api = vim.api
function code_action.code_action_handler(err, _, actions, num, _, _, customSelectionHandler)
-- log(actions)
function code_action.code_action_handler(err, _, actions, cid, bufnr, _, customSelectionHandler)
log(cid, bufnr)
if actions == nil or vim.tbl_isempty(actions) then
print("No code actions available")
return
end
local data = {"[] Auto Fix <C-o> Apply <C-e> Exit"}
local data = {" Auto Fix <C-o> Apply <C-e> Exit"}
for i, action in ipairs(actions) do
local title = action.title:gsub("\r\n", "\\r\\n")
title = title:gsub("\n", "\\n")
@ -23,20 +23,25 @@ function code_action.code_action_handler(err, _, actions, num, _, _, customSelec
width = #str
end
end
-- log(data)
local function apply_action(idx)
local action_chosen = actions[idx - 1]
local switch = string.format('silent b %d', bufnr)
if action_chosen.edit or type(action_chosen.command) == "table" then
if action_chosen.edit then
vim.lsp.util.apply_workspace_edit(action_chosen.edit)
end
if type(action_chosen.command) == "table" then
-- switch buff
vim.cmd(switch)
vim.lsp.buf.execute_command(action_chosen.command)
end
else
vim.cmd(switch)
vim.lsp.buf.execute_command(action_chosen)
end
log(action_chosen)
end
gui.new_list_view {
@ -58,7 +63,6 @@ function code_action.code_action_handler(err, _, actions, num, _, _, customSelec
end
local l = data[pos]
return l
-- log("on move", l)
end
}
end

Loading…
Cancel
Save