Merge branch 'code_action' of github.com:zjp-CN/symbols-outline.nvim

simrat39/symbols-outline.nvim#168
This commit is contained in:
hedy
2023-10-31 20:17:37 +08:00
2 changed files with 9 additions and 29 deletions

View File

@@ -104,7 +104,7 @@ function M._current_node()
return M.state.flattened_outline_items[current_line] return M.state.flattened_outline_items[current_line]
end end
local function goto_location(change_focus) function M._goto_location(change_focus)
local node = M._current_node() local node = M._current_node()
vim.api.nvim_win_set_cursor( vim.api.nvim_win_set_cursor(
M.state.code_win, M.state.code_win,
@@ -221,11 +221,11 @@ local function setup_keymaps(bufnr)
end end
-- goto_location of symbol and focus that window -- goto_location of symbol and focus that window
map(config.options.keymaps.goto_location, function() map(config.options.keymaps.goto_location, function()
goto_location(true) M._goto_location(true)
end) end)
-- goto_location of symbol but stay in outline -- goto_location of symbol but stay in outline
map(config.options.keymaps.focus_location, function() map(config.options.keymaps.focus_location, function()
goto_location(false) M._goto_location(false)
end) end)
-- hover symbol -- hover symbol
map( map(

View File

@@ -1,34 +1,14 @@
local vim = vim
local main = require 'symbols-outline' local main = require 'symbols-outline'
local M = {} 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() function M.show_code_actions()
local current_line = vim.api.nvim_win_get_cursor(main.state.outline_win)[1] -- keep the cursor info in outline and jump back (or not jump back?)
local node = main.state.flattened_outline_items[current_line] local winnr, pos = vim.api.nvim_get_current_win(), vim.api.nvim_win_get_cursor(0)
main._goto_location(true)
local params = get_action_params(node, main.state.code_win) vim.lsp.buf.code_action()
vim.lsp.buf_request( vim.fn.win_gotoid(winnr)
params.bufnr, vim.api.nvim_win_set_cursor(winnr, pos)
'textDocument/codeAction',
params,
vim.lsp.handlers['textDocument/codeAction']
)
end end
return M return M