From 5e93e2ced2224fae39b5f52fa4838803df71e1fc Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 23 Apr 2021 18:19:59 +1000 Subject: [PATCH] add code action for buf action --- README.md | 4 ++++ lua/navigator/codeAction.lua | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 52763dd..50f0f69 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ Use or `:q!` to kill the floating window, to move and 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) diff --git a/lua/navigator/codeAction.lua b/lua/navigator/codeAction.lua index 1a938a0..00498ce 100644 --- a/lua/navigator/codeAction.lua +++ b/lua/navigator/codeAction.lua @@ -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 Apply Exit"} + local data = {"  Auto Fix Apply 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