Skip to content

Commit

Permalink
refactor: move indent to config
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent d590491 commit 9cf827d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
14 changes: 14 additions & 0 deletions lua/trouble/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ local defaults = {
auto_open = false,
auto_close = false,
auto_preview = true,
---@type trouble.Render.opts
render = {
-- stylua: ignore
---@type trouble.Indent.symbols
indent = {
top = "",
middle = "├╴",
last = "└╴",
-- last = "╰╴", -- rounded
fold_open = "",
fold_closed = "",
ws = " ",
},
},
---@type table<string, trouble.Mode>
modes = {
diagnostics_buffer = {
Expand Down
18 changes: 4 additions & 14 deletions lua/trouble/view/indent.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local Config = require("trouble.config")
local Util = require("trouble.util")

---@alias trouble.Indent.type "top"|"middle"|"last"|"fold_open"|"fold_closed"|"ws"
Expand All @@ -11,24 +12,13 @@ local Util = require("trouble.util")
local M = {}
M.__index = M

---@type trouble.Indent.symbols
-- stylua: ignore
M.symbols = {
top = "",
middle = "├╴",
last = "└╴",
-- last = "╰╴", -- rounded
fold_open = "",
fold_closed = "",
ws = " ",
}

---@param symbols? trouble.Indent.symbols
function M.new(symbols)
local self = setmetatable({}, M)
symbols = vim.tbl_deep_extend("force", Config.render.indent, symbols or {})
self.symbols = {}
for k, v in pairs(M.symbols) do
local symbol = symbols and symbols[k] or v
for k, v in pairs(symbols) do
local symbol = v
self.symbols[k] = type(symbol) == "string" and { str = symbol } or { str = symbol[1], hl = symbol[2] }
self.symbols[k].type = k
self.symbols[k].hl = self.symbols[k].hl or ("TroubleIndent" .. Util.camel(k))
Expand Down
8 changes: 6 additions & 2 deletions lua/trouble/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ local Text = require("trouble.view.text")
---@field root_nodes trouble.Node[]
---@field foldlevel? number
---@field max_depth number
---@field opts trouble.Render.opts
local M = setmetatable({}, Text)
M.__index = M

---@param opts? trouble.Text.opts
---@class trouble.Render.opts: trouble.Text.opts
---@field indent? trouble.Indent.symbols

---@param opts? trouble.Render.opts|trouble.Text.opts
function M.new(opts)
local text = Text.new(opts)
---@type trouble.Render
Expand Down Expand Up @@ -93,7 +97,7 @@ function M:section(section, nodes)
self.max_depth = math.max(self.max_depth, #section.groups)
for n, node in ipairs(nodes) do
table.insert(self.root_nodes, node)
self:node(node, section, Indent.new(), n == #nodes)
self:node(node, section, Indent.new(self.opts.indent), n == #nodes)
end
end

Expand Down

0 comments on commit 9cf827d

Please sign in to comment.