diff options
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 928b502..cd58c13 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -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. -- |
