diff options
author | Jesse <github@jessebakker.com> | 2020-05-16 01:18:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-16 01:18:59 +0200 |
commit | f559e5249e3aa155687b335272da8f0c73255ee4 (patch) | |
tree | 1f2ebdabff710220c717011c57d386fae2cdfd17 /runtime/lua/vim/lsp/util.lua | |
parent | c37d9fa3da3cea303915f29e75665f50c4c13b41 (diff) | |
download | rneovim-f559e5249e3aa155687b335272da8f0c73255ee4.tar.gz rneovim-f559e5249e3aa155687b335272da8f0c73255ee4.tar.bz2 rneovim-f559e5249e3aa155687b335272da8f0c73255ee4.zip |
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
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 099a77099b..c92a317d0c 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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 |