local tagIdx = {} local tags = { [0] = '', [1] = 'FIX', [2] = 'TODO', [3] = 'WARN', [4] = 'NOTE', } local numTags = 0 for key, value in pairs(tags) do tagIdx[value] = key numTags = numTags + 1 end local todoFilter = function(view, inc) local f = view:get_filter 'tag' local tag = tags[((tagIdx[f and f.filter.tag] or 0) + inc) % numTags] view:filter({ tag = tag }, { id = 'tag', template = '{hl:Title}Filter:{hl} {tag}', del = tag == '', }) end local diagnosticsFilter = function(view, inc) local f = view:get_filter 'severity' local severity = ((f and f.filter.severity or 0) + inc) % 5 view:filter({ severity = severity }, { id = 'severity', template = '{hl:Title}Filter:{hl} {severity}', del = severity == 0, }) end return { 'folke/trouble.nvim', opts = { open_no_results = true, win = { size = 0.4, }, ---@type table modes = { diagnostics = { mode = 'diagnostics', keys = { s = { action = function(view) diagnosticsFilter(view, 1) end, desc = 'Cycle Severity Filter Forward', }, S = { action = function(view) diagnosticsFilter(view, -1) end, desc = 'Cycle Severity Filter Backward', }, }, }, todo = { mode = 'todo', keys = { s = { action = function(view) todoFilter(view, 1) end, desc = 'Cycle Tag Filter Forward', }, S = { action = function(view) todoFilter(view, -1) end, desc = 'Cycle Tag Filter Backward', }, }, }, }, }, cmd = 'Trouble', keys = { { 'te', 'Trouble diagnostics toggle focus=true', desc = 'Diagnostics (Trouble)', }, { 'to', 'Trouble todo toggle focus=true', desc = 'Todo (Trouble)', }, { 'ts', 'Trouble symbols toggle focus=true', desc = 'Symbols (Trouble)', }, { 'ti', 'Trouble lsp toggle focus=true win.position=right', desc = 'LSP Definitions / references / ... (Trouble)', }, { 'tl', 'Trouble loclist toggle focus=true', desc = 'Location List (Trouble)', }, { 'tq', 'Trouble qflist toggle focus=true', desc = 'Quickfix List (Trouble)', }, }, }