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>
This commit is contained in:
@@ -409,7 +409,8 @@ Built-in functions. Ready to be bound to any key you like. :smile:
|
|||||||
| `builtin.lsp_workspace_symbols` | Searches in LSP all workspace symbols. |
|
| `builtin.lsp_workspace_symbols` | Searches in LSP all workspace symbols. |
|
||||||
| `builtin.lsp_code_actions` | Lists LSP action to be trigged on enter. |
|
| `builtin.lsp_code_actions` | Lists LSP action to be trigged on enter. |
|
||||||
| `builtin.lsp_range_code_actions` | Lists LSP range code action to be trigged on enter. |
|
| `builtin.lsp_range_code_actions` | Lists LSP range code action to be trigged on enter. |
|
||||||
| `builtin.lsp_diagnostics` | Lists LSP Diagnostics in the current document. |
|
| `builtin.lsp_document_diagnostics` | Lists LSP Diagnostics in the current document. |
|
||||||
|
| `builtin.lsp_workspace_diagnostics` | Lists LSP Diagnostics in the workspace if supported and otherwise open buffers. |
|
||||||
| .................................. | Your next awesome picker function here :D |
|
| .................................. | Your next awesome picker function here :D |
|
||||||
|
|
||||||
### Git Pickers
|
### Git Pickers
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
|||||||
builtin.lsp_references = require('telescope.builtin.lsp').references
|
builtin.lsp_references = require('telescope.builtin.lsp').references
|
||||||
builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
|
builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
|
||||||
builtin.lsp_code_actions = require('telescope.builtin.lsp').code_actions
|
builtin.lsp_code_actions = require('telescope.builtin.lsp').code_actions
|
||||||
builtin.lsp_diagnostics = require('telescope.builtin.lsp').diagnostics
|
builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
|
||||||
|
builtin.lsp_workspace_diagnostics = require('telescope.builtin.lsp').workspace_diagnostics
|
||||||
builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_actions
|
builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_actions
|
||||||
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
|
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
|
||||||
|
|
||||||
|
|||||||
@@ -198,8 +198,9 @@ lsp.diagnostics = function(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.hide_filename = utils.get_default(opts.hide_filename, true)
|
||||||
pickers.new(opts, {
|
pickers.new(opts, {
|
||||||
prompt_title = 'LSP Diagnostics',
|
prompt_title = 'LSP Document Diagnostics',
|
||||||
finder = finders.new_table {
|
finder = finders.new_table {
|
||||||
results = locations,
|
results = locations,
|
||||||
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_diagnostics(opts)
|
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_diagnostics(opts)
|
||||||
@@ -212,6 +213,14 @@ lsp.diagnostics = function(opts)
|
|||||||
}):find()
|
}):find()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
lsp.workspace_diagnostics = function(opts)
|
||||||
|
opts = utils.get_default(opts, {})
|
||||||
|
opts.hide_filename = utils.get_default(opts.hide_filename, false)
|
||||||
|
opts.prompt_title = 'LSP Workspace Diagnostics'
|
||||||
|
opts.get_all = true
|
||||||
|
lsp.diagnostics(opts)
|
||||||
|
end
|
||||||
|
|
||||||
local function check_capabilities(feature)
|
local function check_capabilities(feature)
|
||||||
local clients = vim.lsp.buf_get_clients(0)
|
local clients = vim.lsp.buf_get_clients(0)
|
||||||
|
|
||||||
|
|||||||
@@ -862,15 +862,16 @@ function make_entry.gen_from_lsp_diagnostics(opts)
|
|||||||
for _, v in pairs(lsp_type_diagnostic) do
|
for _, v in pairs(lsp_type_diagnostic) do
|
||||||
signs[v] = vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. v)[1].text)
|
signs[v] = vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. v)[1].text)
|
||||||
end
|
end
|
||||||
-- expose line width for longer msg if opts.hide_filename
|
|
||||||
local line_width = utils.get_default(opts.line_width, 48)
|
local layout = {
|
||||||
|
{ width = 9 },
|
||||||
|
{ remaining = true }
|
||||||
|
}
|
||||||
|
local line_width = utils.get_default(opts.line_width, 47)
|
||||||
|
if not opts.hide_filename then table.insert(layout, 2, {width = line_width}) end
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "▏",
|
separator = "▏",
|
||||||
items = {
|
items = layout
|
||||||
{ width = 11 },
|
|
||||||
{ width = line_width },
|
|
||||||
{ remaining = true }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
@@ -890,12 +891,10 @@ function make_entry.gen_from_lsp_diagnostics(opts)
|
|||||||
string.format("%s %s", signs[entry.type], pos),
|
string.format("%s %s", signs[entry.type], pos),
|
||||||
string.format("LspDiagnosticsDefault%s", entry.type)
|
string.format("LspDiagnosticsDefault%s", entry.type)
|
||||||
}
|
}
|
||||||
-- remove line break to avoid display issues
|
|
||||||
local text = string.format("%-" .. line_width .."s", entry.text:gsub(".* | ", ""):gsub("[\n]", ""))
|
|
||||||
|
|
||||||
return displayer {
|
return displayer {
|
||||||
line_info,
|
line_info,
|
||||||
text,
|
entry.text,
|
||||||
filename,
|
filename,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -912,7 +911,6 @@ function make_entry.gen_from_lsp_diagnostics(opts)
|
|||||||
or ''
|
or ''
|
||||||
) .. ' ' .. entry.text,
|
) .. ' ' .. entry.text,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
bufnr = entry.bufnr,
|
|
||||||
filename = filename,
|
filename = filename,
|
||||||
type = entry.type,
|
type = entry.type,
|
||||||
lnum = entry.lnum,
|
lnum = entry.lnum,
|
||||||
|
|||||||
@@ -84,36 +84,42 @@ end
|
|||||||
|
|
||||||
utils.diagnostics_to_tbl = function(opts)
|
utils.diagnostics_to_tbl = function(opts)
|
||||||
opts = opts or {}
|
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 items = {}
|
||||||
|
local current_buf = vim.api.nvim_get_current_buf()
|
||||||
local lsp_type_diagnostic = {[1] = "Error", [2] = "Warning", [3] = "Information", [4] = "Hint"}
|
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 start = diag.range['start']
|
||||||
local finish = diag.range['end']
|
local finish = diag.range['end']
|
||||||
local row = start.line
|
local row = start.line
|
||||||
local col = start.character
|
local col = start.character
|
||||||
|
|
||||||
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
|
local buffer_diag = {
|
||||||
|
|
||||||
table.insert(items, {
|
|
||||||
bufnr = bufnr,
|
bufnr = bufnr,
|
||||||
filename = filename,
|
filename = filename,
|
||||||
lnum = row + 1,
|
lnum = row + 1,
|
||||||
col = col + 1,
|
col = col + 1,
|
||||||
start = start,
|
start = start,
|
||||||
finish = finish,
|
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]
|
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
|
end
|
||||||
|
|
||||||
for _, diag in ipairs(buffer_diags) do insert_diag(diag) 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)}
|
||||||
table.sort(items, function(a, b) return a.lnum < b.lnum end)
|
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
|
return items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user