Skip to content

Commit

Permalink
feat: rendering messages from provider (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
eatgrass committed Jul 16, 2023
1 parent d99e2ab commit a66a78b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 14 additions & 1 deletion lua/trouble/providers/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ local util = require("trouble.util")
---@class Lsp
local M = {}

local severity = {
[1] = "ERROR",
[2] = "WARN",
[3] = "INFO",
[4] = "HINT",
}

---@param options TroubleOptions
---@return Item[]
function M.diagnostics(_, buf, cb, options)
Expand All @@ -23,7 +30,13 @@ function M.diagnostics(_, buf, cb, options)
items = util.locations_to_items(diags, 1)
end

cb(items)
local messages = {}
if options.severity ~= nil then
table.insert(messages, { text = "filter:", group = "Information" })
table.insert(messages, { text = severity[options.severity], group = "Sign" .. util.severity[options.severity] })
end

cb(items, messages)
end

function M.get_signs()
Expand Down
4 changes: 2 additions & 2 deletions lua/trouble/providers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function M.get(win, buf, cb, options)
end,
}, options.sort_keys)

provider(win, buf, function(items)
provider(win, buf, function(items, messages)
table.sort(items, function(a, b)
for _, key in ipairs(sort_keys) do
local ak = type(key) == "string" and a[key] or key(a)
Expand All @@ -62,7 +62,7 @@ function M.get(win, buf, cb, options)
end
end
end)
cb(items)
cb(items, messages)
end, options)
end

Expand Down
7 changes: 6 additions & 1 deletion lua/trouble/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
function renderer.render(view, opts)
opts = opts or {}
local buf = vim.api.nvim_win_get_buf(view.parent)
providers.get(view.parent, buf, function(items)
providers.get(view.parent, buf, function(items, messages)
local auto_jump = vim.tbl_contains(config.options.auto_jump, opts.mode)
if opts.on_open and #items == 1 and auto_jump and not opts.auto then
view:close()
Expand All @@ -60,6 +60,11 @@ function renderer.render(view, opts)
view.items = {}

if config.options.padding then
if messages ~= nil then
for _, msg in ipairs(messages) do
text:render(" " .. msg.text, msg.group, { append = " " })
end
end
text:nl()
end

Expand Down

0 comments on commit a66a78b

Please sign in to comment.