summaryrefslogtreecommitdiff
path: root/lua/telescope/make_entry.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2021-12-10 17:49:06 +0100
committerGitHub <noreply@github.com>2021-12-10 17:49:06 +0100
commit56325fefb21a8a9331a25e294c074887dfb2a60c (patch)
tree1b0c08e44dc437ed96824eae941a991a6a204ac1 /lua/telescope/make_entry.lua
parent61240ac75a93b3cdafb4325ab4e9d407f83965f4 (diff)
feat: migrate to Telescope diagnostics using vim.diagnostic (#1553)
Diffstat (limited to 'lua/telescope/make_entry.lua')
-rw-r--r--lua/telescope/make_entry.lua52
1 files changed, 25 insertions, 27 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 1e48c8c..2d53248 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -979,33 +979,33 @@ function make_entry.gen_from_ctags(opts)
end
end
-function make_entry.gen_from_lsp_diagnostics(opts)
+function make_entry.gen_from_diagnostics(opts)
opts = opts or {}
- local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity
-
- local signs
- if not opts.no_sign then
- signs = {}
- for severity, _ in pairs(lsp_type_diagnostic) do
- -- pcall to catch entirely unbound or cleared out sign hl group
- if type(severity) == "string" then
- local status, sign = pcall(function()
- return vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. severity)[1].text)
- end)
- if not status then
- sign = severity:sub(1, 1)
- end
- signs[severity] = sign
+ local signs = (function()
+ if opts.no_sign then
+ return
+ end
+ local signs = {}
+ local type_diagnostic = vim.diagnostic.severity
+ for _, severity in ipairs(type_diagnostic) do
+ local status, sign = pcall(function()
+ -- only the first char is upper all others are lowercalse
+ return vim.trim(vim.fn.sign_getdefined("DiagnosticSign" .. severity:lower():gsub("^%l", string.upper))[1].text)
+ end)
+ if not status then
+ sign = severity:sub(1, 1)
end
+ signs[severity] = sign
end
- end
+ return signs
+ end)()
local display_items = {
{ width = utils.if_nil(signs, 8, 10) },
{ remaining = true },
}
- local line_width = utils.get_default(opts.line_width, 0.5)
+ local line_width = vim.F.if_nil(opts.line_width, 0.5)
if not utils.is_path_hidden(opts) then
table.insert(display_items, 2, { width = line_width })
end
@@ -1021,9 +1021,13 @@ function make_entry.gen_from_lsp_diagnostics(opts)
local pos = string.format("%4d:%2d", entry.lnum, entry.col)
local line_info = {
(signs and signs[entry.type] .. " " or "") .. pos,
- "LspDiagnosticsDefault" .. entry.type,
+ "Diagnostic" .. entry.type,
}
+ --TODO(conni2461): I dont like that this is symbol lnum:col | msg | filename
+ -- i want: symbol filename:lnum:col | msg
+ -- or : symbol lnum:col | msg
+ -- I think this is more natural
return displayer {
line_info,
entry.text,
@@ -1032,21 +1036,15 @@ function make_entry.gen_from_lsp_diagnostics(opts)
end
return function(entry)
- local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
-
return {
- valid = true,
-
value = entry,
- ordinal = (not opts.ignore_filename and filename or "") .. " " .. entry.text,
+ ordinal = ("%s %s"):format(not opts.ignore_filename and entry.filename or "", entry.text),
display = make_display,
- filename = filename,
+ filename = entry.filename,
type = entry.type,
lnum = entry.lnum,
col = entry.col,
text = entry.text,
- start = entry.start,
- finish = entry.finish,
}
end
end