feat: lsp diagnostics and prefiltering by entry attribute (#543)

prefiltering for lsp_document_symbols and lsp_workspace_symbols.
example: type `:var:` to show all vars
This commit is contained in:
fdschmidt93
2021-03-03 22:33:03 +01:00
committed by GitHub
parent 390e5fa9f5
commit db7615578b
9 changed files with 199 additions and 6 deletions

View File

@@ -82,6 +82,41 @@ utils.quickfix_items_to_entries = function(locations)
return results
end
utils.diagnostics_to_tbl = function(opts)
opts = opts or {}
local bufnr = vim.api.nvim_get_current_buf()
local filename = vim.api.nvim_buf_get_name(bufnr)
local buffer_diags = vim.lsp.diagnostic.get(bufnr, opts.client_id)
local items = {}
local lsp_type_diagnostic = {[1] = "Error", [2] = "Warning", [3] = "Information", [4] = "Hint"}
local insert_diag = function(diag)
local start = diag.range['start']
local finish = diag.range['end']
local row = start.line
local col = start.character
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
table.insert(items, {
bufnr = bufnr,
filename = filename,
lnum = row + 1,
col = col + 1,
start = start,
finish = finish,
text = vim.trim(line .. " | " .. diag.message),
type = lsp_type_diagnostic[diag.severity] or lsp_type_diagnostic[1]
})
end
for _, diag in ipairs(buffer_diags) do insert_diag(diag) end
table.sort(items, function(a, b) return a.lnum < b.lnum end)
return items
end
-- TODO: Figure out how to do this... could include in plenary :)
-- NOTE: Don't use this yet. It will segfault sometimes.
--