diff options
| author | fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> | 2021-03-04 15:01:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-04 15:01:17 +0100 |
| commit | 908752fc67f0aff43e35ffb175b5e6226874bad5 (patch) | |
| tree | 17a0874b107108fe07aca167184c83e2457be9fd /lua/telescope/utils.lua | |
| parent | 8dc00b08aa68ccfc259a35d31f55ff5eeedab17a (diff) | |
feat: workspace diagnostics, jump to and improved styling (#599)
Changes: `Telescope lsp_diagnostics` is now `Telescope lsp_document_diagnostics`
New: `Telescope lsp_workspace_diagnostics`
Co-authored-by: Fabian David Schmidt <fabian.david.schmidt@hotmail.com>
Co-authored-by: elianiva <dicha.arkana03@gmail.com>
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index cd58c13..4e8c1d3 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -84,36 +84,42 @@ 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 current_buf = vim.api.nvim_get_current_buf() local lsp_type_diagnostic = {[1] = "Error", [2] = "Warning", [3] = "Information", [4] = "Hint"} - local insert_diag = function(diag) + + local preprocess_diag = function(diag, bufnr) + local filename = vim.api.nvim_buf_get_name(bufnr) 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, { + local buffer_diag = { bufnr = bufnr, filename = filename, lnum = row + 1, col = col + 1, start = start, finish = finish, - text = vim.trim(line .. " | " .. diag.message), + -- remove line break to avoid display issues + text = vim.trim(diag.message:gsub("[\n]", "")), type = lsp_type_diagnostic[diag.severity] or lsp_type_diagnostic[1] - }) + } + table.sort(buffer_diag, function(a, b) return a.lnum < b.lnum end) + return buffer_diag end - for _, diag in ipairs(buffer_diags) do insert_diag(diag) end - - table.sort(items, function(a, b) return a.lnum < b.lnum end) + local buffer_diags = opts.get_all and vim.lsp.diagnostic.get_all() or + {[current_buf] = vim.lsp.diagnostic.get(current_buf, opts.client_id)} + for bufnr, diags in pairs(buffer_diags) do + for _, diag in pairs(diags) do + -- workspace diagnostics may include empty tables for unused bufnr + if not vim.tbl_isempty(diag) then + table.insert(items, preprocess_diag(diag, bufnr)) + end + end + end return items end |
