Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

fix(code_actions): use the builtin code_action #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/symbols-outline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function M._current_node()
return M.state.flattened_outline_items[current_line]
end

local function goto_location(change_focus)
function M._goto_location(change_focus)
local node = M._current_node()
vim.api.nvim_win_set_cursor(
M.state.code_win,
Expand Down Expand Up @@ -218,11 +218,11 @@ local function setup_keymaps(bufnr)
end
-- goto_location of symbol and focus that window
map(config.options.keymaps.goto_location, function()
goto_location(true)
M._goto_location(true)
end)
-- goto_location of symbol but stay in outline
map(config.options.keymaps.focus_location, function()
goto_location(false)
M._goto_location(false)
end)
-- hover symbol
map(
Expand Down
32 changes: 6 additions & 26 deletions lua/symbols-outline/code_action.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
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']
)
-- keep the cursor info in outline and jump back (or not jump back?)
local winnr, pos = vim.api.nvim_get_current_win(), vim.api.nvim_win_get_cursor(0)
main._goto_location(true)
vim.lsp.buf.code_action()
vim.fn.win_gotoid(winnr)
vim.api.nvim_win_set_cursor(winnr, pos)
end

return M