Skip to content

Commit

Permalink
feat: made it easier to integrate with trouble
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 10, 2021
1 parent d10ee4b commit 1dd72c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lua/trouble/providers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ function M.get(win, buf, cb, options)
local name = options.mode
local provider = M.providers[name]

if not provider then
local ok, mod = pcall(require, "trouble.providers." .. name)
if ok then
M.providers[name] = mod
provider = mod
end
end

if not provider then
util.error(("invalid provider %q"):format(name))
return {}
Expand Down
6 changes: 4 additions & 2 deletions lua/trouble/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ function renderer.render_diagnostics(view, text, items)
for _, diag in ipairs(items) do
view.items[text.lineNr + 1] = diag

local sign = signs[string.lower(diag.type)]
local sign = diag.sign or signs[string.lower(diag.type)]
if not sign then sign = diag.type end

local indent = " "
if config.options.indent_lines then indent = "" end

local sign_hl = diag.sign_hl or ("LspTroubleSign" .. diag.type)

text:render(indent, "Indent")
text:render(sign .. " ", "Sign" .. diag.type)
text:render(sign .. " ", sign_hl, {exact = true})
text:render(diag.text, "Text" .. diag.type, " ")
-- text:render(diag.type, diag.type, " ")

Expand Down
2 changes: 2 additions & 0 deletions lua/trouble/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function M.process_item(item, bufnr)
col = col + 1,
start = start,
finish = finish,
sign = item.sign,
sign_hl = item.sign_hl,
-- remove line break to avoid display issues
text = vim.trim(item.message:gsub("[\n]", "")):sub(0, vim.o.columns),
line = line,
Expand Down

0 comments on commit 1dd72c2

Please sign in to comment.