From 81670818c4807542d902b3cf553857ae9d95246c Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Sat, 10 Feb 2024 20:49:26 -0600 Subject: feat(trouble): add trouble and todo comments --- lua/plugins/auto-session.lua | 2 + lua/plugins/todo-comments.lua | 64 ++++++++++++++++++++++++++ lua/plugins/trouble.lua | 101 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 lua/plugins/todo-comments.lua create mode 100644 lua/plugins/trouble.lua (limited to 'lua') diff --git a/lua/plugins/auto-session.lua b/lua/plugins/auto-session.lua index efbfef8..5737e3a 100644 --- a/lua/plugins/auto-session.lua +++ b/lua/plugins/auto-session.lua @@ -11,6 +11,8 @@ return { function() -- dirty way of handling neotree not being loaded yet (lazy load on nt) local _ = pcall(vim.cmd, 'Neotree close') + -- same thing for trouble + local _ = pcall(vim.cmd, 'TroubleClose') end, }, }, diff --git a/lua/plugins/todo-comments.lua b/lua/plugins/todo-comments.lua new file mode 100644 index 0000000..44bbcda --- /dev/null +++ b/lua/plugins/todo-comments.lua @@ -0,0 +1,64 @@ +return { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + -- these are just the default configs for reference + opts = { + signs = true, + sign_priority = 8, + -- keywords recognized as todo comments + keywords = { + FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" } }, + TODO = { icon = " ", color = "info" }, + HACK = { icon = " ", color = "warning" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + }, + gui_style = { + fg = "NONE", + bg = "BOLD", + }, + merge_keywords = true, -- when true, custom keywords will be merged with the defaults + -- highlighting of the line containing the todo comment + -- * before: highlights before the keyword (typically comment characters) + -- * keyword: highlights of the keyword + -- * after: highlights after the keyword (todo text) + highlight = { + multiline = true, -- enable multine todo comments + multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword + multiline_context = 10, -- extra lines that will be re-evaluated when changing a line + before = "", -- "fg" or "bg" or empty + keyword = "wide", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) + after = "fg", -- "fg" or "bg" or empty + pattern = [[.*<(KEYWORDS)\s*:]], -- pattern or table of patterns, used for highlighting (vim regex) + comments_only = true, -- uses treesitter to match keywords in comments only + max_line_len = 400, -- ignore lines longer than this + exclude = {}, -- list of file types to exclude highlighting + }, + -- list of named colors where we try to extract the guifg from the + -- list of highlight groups or use the hex color if hl not found as a fallback + colors = { + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + info = { "DiagnosticInfo", "#2563EB" }, + hint = { "DiagnosticHint", "#10B981" }, + default = { "Identifier", "#7C3AED" }, + test = { "Identifier", "#FF00FF" } + }, + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + -- regex that will be used to match keywords. + -- don't replace the (KEYWORDS) placeholder + pattern = [[\b(KEYWORDS):]], -- ripgrep regex + -- pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives + }, + } +} diff --git a/lua/plugins/trouble.lua b/lua/plugins/trouble.lua new file mode 100644 index 0000000..e1a3dac --- /dev/null +++ b/lua/plugins/trouble.lua @@ -0,0 +1,101 @@ +return { + 'folke/trouble.nvim', + dependencies = { "nvim-tree/nvim-web-devicons" }, + -- these are just the default configs for reference + opts = { + position = "bottom", -- can be: bottom, top, left, right + height = 10, + width = 50, + icons = true, -- use devicons for filenames + mode = "workspace_diagnostics", -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" + severity = nil, -- nil (ALL) or vim.diagnostic.severity.ERROR | WARN | INFO | HINT + fold_open = "", + fold_closed = "", + group = true, -- group results by file + padding = true, -- add an extra new line on top of the list + cycle_results = true, -- cycle item list when reaching beginning or end of list + -- map to {} to remove a mapping, for example: + -- close = {}, + action_keys = { + close = "q", -- close the list + cancel = "", -- cancel the preview and get back to your last window / buffer / cursor + refresh = "r", -- manually refresh + jump = { "", "", "<2-leftmouse>" }, -- jump to the diagnostic or open / close folds + open_split = { "" }, -- open buffer in new split + open_vsplit = { "" }, -- open buffer in new vsplit + open_tab = { "" }, -- open buffer in new tab + jump_close = { "o" }, -- jump to the diagnostic and close the list + toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode + switch_severity = "s", -- switch "diagnostics" severity filter level to HINT / INFO / WARN / ERROR + toggle_preview = "P", -- toggle auto_preview + hover = "K", -- opens a small popup with the full multiline message + preview = "p", -- preview the diagnostic location + open_code_href = "c", -- if present, open a URI with more information about the diagnostic error + close_folds = { "zM", "zm" }, -- close all folds + open_folds = { "zR", "zr" }, -- open all folds + toggle_fold = { "zA", "za" }, -- toggle fold of current file + previous = "k", -- previous item + next = "j", -- next item + help = "?", -- help menu + }, + + multiline = true, -- render multi-line messages + indent_lines = true, -- add an indent guide below the fold icons + win_config = { border = "single" }, -- window configuration for floating windows. See |nvim_open_win()|. + auto_open = false, -- automatically open the list when you have diagnostics + auto_close = false, -- automatically close the list when you have no diagnostics + auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window + auto_fold = false, -- automatically fold a file trouble list at creation + auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result + include_declaration = { + "lsp_references", + "lsp_implementations", + "lsp_definitions" + }, -- for the given modes, include the declaration of the current symbol in the results + -- icons / text used for a diagnostic + signs = { + error = "", + warning = "", + hint = "", + information = "", + other = "", + }, + use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client + }, + config = function(_, opts) + local trouble = require('trouble') + trouble.setup(opts) + + -- TODO: get this into a global util, kinda repeated on multiple plugins + local nmap = function(keys, func, desc) + if desc then + desc = 'trouble: ' .. desc + end + vim.keymap.set('n', keys, func, { desc = desc }) + end + + -- TODO: do I need all of these? + nmap("xx", function() trouble.toggle() end, 'toggle') + nmap("xw", function() trouble.toggle("workspace_diagnostics") end, 'toggle [w]orkspace diagnostics') + nmap("xd", function() trouble.toggle("document_diagnostics") end, 'toggle [d]ocument diagnostics') + nmap("xq", function() trouble.toggle("quickfix") end, 'toggle [q]uickfix') + nmap("xl", function() trouble.toggle("loclist") end, 'toggle [l]oclist') + nmap("gR", function() trouble.toggle("lsp_references") end, '[g]o to (lsp) [R]eference') + + -- TODO: add telescope integration? + -- taken from https://github.com/folke/trouble.nvim?tab=readme-ov-file#telescope + -- local actions = require("telescope.actions") + -- local trouble = require("trouble.providers.telescope") + -- + -- local telescope = require("telescope") + -- + -- telescope.setup { + -- defaults = { + -- mappings = { + -- i = { [""] = trouble.open_with_trouble }, + -- n = { [""] = trouble.open_with_trouble }, + -- }, + -- }, + -- } + end +} -- cgit v1.2.3-70-g09d2