mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 19:36:40 +00:00
LSP: Add textDocument/codeAction support (#11607)
* Add textDocument/codeAction * Add callback for workspace/executeCommand * Escape newlines in codeAction titles * Return empty list in get_line_diagnostics if no buffer diagnostics * Add stub documentation * Validate context parameter in code_action * Add support for edit in CodeAction responses * Group diagnostics by line in vim.lsp.util.get_line_diagnostics() * Advertise code action literal support
This commit is contained in:
@@ -720,19 +720,28 @@ do
|
||||
return severity_highlights[severity]
|
||||
end
|
||||
|
||||
function M.show_line_diagnostics()
|
||||
function M.get_line_diagnostics()
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local line = api.nvim_win_get_cursor(0)[1] - 1
|
||||
local linenr = api.nvim_win_get_cursor(0)[1] - 1
|
||||
|
||||
local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
|
||||
|
||||
if not buffer_diagnostics then
|
||||
return {}
|
||||
end
|
||||
|
||||
local diagnostics_by_line = M.diagnostics_group_by_line(buffer_diagnostics)
|
||||
return diagnostics_by_line[linenr] or {}
|
||||
end
|
||||
|
||||
function M.show_line_diagnostics()
|
||||
-- local marks = api.nvim_buf_get_extmarks(bufnr, diagnostic_ns, {line, 0}, {line, -1}, {})
|
||||
-- if #marks == 0 then
|
||||
-- return
|
||||
-- end
|
||||
local lines = {"Diagnostics:"}
|
||||
local highlights = {{0, "Bold"}}
|
||||
|
||||
local buffer_diagnostics = M.diagnostics_by_buf[bufnr]
|
||||
if not buffer_diagnostics then return end
|
||||
local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics)[line]
|
||||
local line_diagnostics = M.get_line_diagnostics()
|
||||
if not line_diagnostics then return end
|
||||
|
||||
for i, diagnostic in ipairs(line_diagnostics) do
|
||||
@@ -1044,14 +1053,26 @@ function M.try_trim_markdown_code_blocks(lines)
|
||||
end
|
||||
|
||||
local str_utfindex = vim.str_utfindex
|
||||
function M.make_position_params()
|
||||
local function make_position_param()
|
||||
local row, col = unpack(api.nvim_win_get_cursor(0))
|
||||
row = row - 1
|
||||
local line = api.nvim_buf_get_lines(0, row, row+1, true)[1]
|
||||
col = str_utfindex(line, col)
|
||||
return { line = row; character = col; }
|
||||
end
|
||||
|
||||
function M.make_position_params()
|
||||
return {
|
||||
textDocument = M.make_text_document_params();
|
||||
position = { line = row; character = col; }
|
||||
position = make_position_param()
|
||||
}
|
||||
end
|
||||
|
||||
function M.make_range_params()
|
||||
local position = make_position_param()
|
||||
return {
|
||||
textDocument = { uri = vim.uri_from_bufnr(0) },
|
||||
range = { start = position; ["end"] = position; }
|
||||
}
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user