feat: Add code actions support
Uses the default handler, mapped to 'a'
This commit is contained in:
@@ -143,6 +143,10 @@ local function setup_keymaps(bufnr)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "r",
|
||||
":lua require('symbols-outline.rename').rename()<Cr>",
|
||||
{})
|
||||
-- code actions
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "a",
|
||||
":lua require('symbols-outline.code_action').show_code_actions()<Cr>",
|
||||
{})
|
||||
-- close outline when escape is pressed
|
||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Esc>", ":bw!<Cr>",{})
|
||||
end
|
||||
|
||||
31
lua/symbols-outline/code_action.lua
Normal file
31
lua/symbols-outline/code_action.lua
Normal file
@@ -0,0 +1,31 @@
|
||||
local vim = vim
|
||||
|
||||
local main = require('symbols-outline')
|
||||
|
||||
local M = {}
|
||||
|
||||
local function get_action_params(node, winnr)
|
||||
local bufnr = vim.api.nvim_win_get_buf(winnr)
|
||||
local fn = "file://" .. vim.api.nvim_buf_get_name(bufnr)
|
||||
|
||||
local pos = {line = node.line, character = node.character}
|
||||
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr, node.line)
|
||||
return {
|
||||
textDocument = {uri = fn},
|
||||
range = {start = pos, ["end"] = pos},
|
||||
context = {diagnostics = diagnostics},
|
||||
bufnr = bufnr
|
||||
}
|
||||
end
|
||||
|
||||
function M.show_code_actions()
|
||||
local current_line = vim.api.nvim_win_get_cursor(main.state.outline_win)[1]
|
||||
local node = main.state.flattened_outline_items[current_line]
|
||||
|
||||
local params = get_action_params(node, main.state.code_win)
|
||||
|
||||
vim.lsp.buf_request(params.bufnr, "textDocument/codeAction", params,
|
||||
vim.lsp.handlers["textDocument/codeAction"])
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user