Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend builtin diagnostic to allow displayed text customization #3281

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,8 @@ builtin.diagnostics({opts}) *telescope.builtin.diagnostics()*
{sort_by} (string) sort order of the diagnostics
results; see above notes
(default: "buffer")
{text} (function|nil) allow to expand text displayed
(default: diagnostic.message)



Expand Down
8 changes: 7 additions & 1 deletion lua/telescope/builtin/__diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ local diagnostics_to_tbl = function(opts)
end

local preprocess_diag = function(diagnostic)
local text = vim.trim(diagnostic.message:gsub("[\n]", ""))

if type(opts.text) == "function" then
text = opts.text(diagnostic)
end

return {
bufnr = diagnostic.bufnr,
filename = bufnr_name_map[diagnostic.bufnr],
lnum = diagnostic.lnum + 1,
col = diagnostic.col + 1,
text = vim.trim(diagnostic.message:gsub("[\n]", "")),
text = text,
type = severities[diagnostic.severity] or severities[1],
}
end
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.buil
---@field namespace number: limit your diagnostics to a specific namespace
---@field disable_coordinates boolean: don't show the line & row numbers (default: false)
---@field sort_by string: sort order of the diagnostics results; see above notes (default: "buffer")
---@field text function|nil: allow to expand text displayed (default: diagnostic.message)
builtin.diagnostics = require_on_exported_call("telescope.builtin.__diagnostics").get

local apply_config = function(mod)
Expand Down