diff --git a/lua/trouble/config.lua b/lua/trouble/config.lua index 96fc33b9..7f54b1bc 100644 --- a/lua/trouble/config.lua +++ b/lua/trouble/config.lua @@ -10,6 +10,8 @@ M.namespace = vim.api.nvim_create_namespace("Trouble") local defaults = { debug = false, cmd_options = {}, + group = true, -- group results by file + padding = 1, -- padding to use inside results window position = "bottom", -- position of the list can be: bottom, top, left, right height = 10, -- height of the trouble list when position is top or bottom width = 50, -- width of the list when position is left or right diff --git a/lua/trouble/init.lua b/lua/trouble/init.lua index bfb2d929..339e905e 100644 --- a/lua/trouble/init.lua +++ b/lua/trouble/init.lua @@ -69,14 +69,14 @@ function Trouble.toggle(...) if opts.mode and (opts.mode ~= config.options.mode) then config.options.mode = opts.mode - Trouble.open() + Trouble.open(...) return end if is_open() then Trouble.close() else - Trouble.open() + Trouble.open(...) end end diff --git a/lua/trouble/renderer.lua b/lua/trouble/renderer.lua index 4a95dc7b..4caad5f7 100644 --- a/lua/trouble/renderer.lua +++ b/lua/trouble/renderer.lua @@ -55,7 +55,9 @@ function renderer.render(view, opts) local text = Text:new() view.items = {} - text:nl() + if config.options.padding == 1 then + text:nl() + end -- render file groups for filename, group_items in pairs(grouped) do @@ -82,24 +84,26 @@ end function renderer.render_file(view, text, filename, items) view.items[text.lineNr + 1] = { filename = filename, is_file = true } - local count = util.count(items) + if view.group == true then + local count = util.count(items) - text:render(" ") + text:render(" ") - if folds.is_folded(filename) then - text:render(config.options.fold_closed, "FoldIcon", " ") - else - text:render(config.options.fold_open, "FoldIcon", " ") - end + if folds.is_folded(filename) then + text:render(config.options.fold_closed, "FoldIcon", " ") + else + text:render(config.options.fold_open, "FoldIcon", " ") + end - if config.options.icons then - local icon, icon_hl = get_icon(filename) - text:render(icon, icon_hl, { exact = true, append = " " }) - end + if config.options.icons then + local icon, icon_hl = get_icon(filename) + text:render(icon, icon_hl, { exact = true, append = " " }) + end - text:render(vim.fn.fnamemodify(filename, ":p:."), "File", " ") - text:render(" " .. count .. " ", "Count") - text:nl() + text:render(vim.fn.fnamemodify(filename, ":p:."), "File", " ") + text:render(" " .. count .. " ", "Count") + text:nl() + end if not folds.is_folded(filename) then renderer.render_diagnostics(view, text, items) @@ -119,8 +123,15 @@ function renderer.render_diagnostics(view, text, items) end local indent = " " - if config.options.indent_lines then - indent = " │ " + if config.options.padding == 1 then + indent = " " + if config.options.indent_lines then + indent = "│ " + end + else + if config.options.indent_lines then + indent = " │ " + end end local sign_hl = diag.sign_hl or ("TroubleSign" .. diag.type) diff --git a/lua/trouble/view.lua b/lua/trouble/view.lua index 9898010e..bcda97df 100644 --- a/lua/trouble/view.lua +++ b/lua/trouble/view.lua @@ -56,11 +56,20 @@ end function View:new(opts) opts = opts or {} + + local group + if opts.group ~= nil then + group = opts.group + else + group = config.options.group + end + local this = { buf = vim.api.nvim_get_current_buf(), win = opts.win or vim.api.nvim_get_current_win(), parent = opts.parent, items = {}, + group = group, } setmetatable(this, self) return this