diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua index 061934d..460576c 100644 --- a/common/.config/nvim/init.lua +++ b/common/.config/nvim/init.lua @@ -15,6 +15,7 @@ -- l+: [L]ist Things -- n+: [N]eoVim Stuff -- q+: DB [Q]ueries +-- r+: [R]efactor Things -- s+: Grep/[S]earch Things -- t+: [T]est runner stuff -- x+: close/dismiss something diff --git a/common/.config/nvim/lua/plugins/code-generic.lua b/common/.config/nvim/lua/plugins/code-generic.lua index bb28823..29bb911 100644 --- a/common/.config/nvim/lua/plugins/code-generic.lua +++ b/common/.config/nvim/lua/plugins/code-generic.lua @@ -241,7 +241,7 @@ return { }, }, keys = { - { "o", "Trouble symbols toggle focus=true", desc = "Code: Toggle Symbol Outline" }, + { "o", "Trouble symbols toggle preview.type=main focus=true", desc = "Code: Toggle Symbol Outline" }, { "dd", "Trouble project_errors toggle focus=true", desc = "Trouble: Document Diagnostics" }, { "dw", "Trouble most_severe toggle focus=true", desc = "Trouble: List Project Diagnostics" }, @@ -409,4 +409,136 @@ return { }, }, }, + + -- Refactor code: Refactoring book by Martin Fowler + { + "ThePrimeagen/refactoring.nvim", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-treesitter/nvim-treesitter", + }, + keys = { + { + "rs", + function() + require("telescope").extensions.refactoring.refactors() + end, + mode = "v", + desc = "Refactor", + }, + { + "ri", + function() + require("refactoring").refactor("Inline Variable") + end, + mode = { "n", "v" }, + desc = "Inline Variable", + }, + { + "rb", + function() + require("refactoring").refactor("Extract Block") + end, + desc = "Extract Block", + }, + { + "rf", + function() + require("refactoring").refactor("Extract Block To File") + end, + desc = "Extract Block To File", + }, + { + "rP", + function() + require("refactoring").debug.printf({ below = false }) + end, + desc = "Debug Print", + }, + { + "rp", + function() + require("refactoring").debug.print_var({ normal = true }) + end, + desc = "Debug Print Variable", + }, + { + "rc", + function() + require("refactoring").debug.cleanup({}) + end, + desc = "Debug Cleanup", + }, + { + "rf", + function() + require("refactoring").refactor("Extract Function") + end, + mode = "v", + desc = "Extract Function", + }, + { + "rF", + function() + require("refactoring").refactor("Extract Function To File") + end, + mode = "v", + desc = "Extract Function To File", + }, + { + "rx", + function() + require("refactoring").refactor("Extract Variable") + end, + mode = "v", + desc = "Extract Variable", + }, + { + "rp", + function() + require("refactoring").debug.print_var() + end, + mode = "v", + desc = "Debug Print Variable", + }, + }, + opts = { + prompt_func_return_type = { + go = false, + java = false, + cpp = false, + c = false, + h = false, + hpp = false, + cxx = false, + }, + prompt_func_param_type = { + go = false, + java = false, + cpp = false, + c = false, + h = false, + hpp = false, + cxx = false, + }, + printf_statements = {}, + print_var_statements = {}, + }, + config = function(_, opts) + require("refactoring").setup(opts) + pcall(require("telescope").load_extension, "refactoring") + end, + }, + + -- which key integration + { + "folke/which-key.nvim", + optional = true, + opts = { + defaults = { + ["r"] = { name = "+refactor" }, + }, + }, + }, } diff --git a/common/.config/nvim/lua/plugins/code-lsp.lua b/common/.config/nvim/lua/plugins/code-lsp.lua index 307793b..931e4da 100644 --- a/common/.config/nvim/lua/plugins/code-lsp.lua +++ b/common/.config/nvim/lua/plugins/code-lsp.lua @@ -167,11 +167,12 @@ return { display = { render_limit = 1, -- How many LSP messages to show at once - skip_history = true, -- Whether progress notifications should be omitted from history + -- skip_history = true, -- Whether progress notifications should be omitted from history }, }, notification = { + poll_rate = 2, -- How often to udate and render notifications filter = vim.log.levels.WARN, -- Minimum notifications level }, }, diff --git a/common/.config/nvim/lua/plugins/navigate-files.lua b/common/.config/nvim/lua/plugins/navigate-files.lua index c98ee6c..2ac7339 100644 --- a/common/.config/nvim/lua/plugins/navigate-files.lua +++ b/common/.config/nvim/lua/plugins/navigate-files.lua @@ -77,6 +77,7 @@ return { setup = { settings = { save_on_change = true, + save_on_toggle = false, mark_branch = true, }, }, @@ -297,6 +298,8 @@ return { -- vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "Code: List References for word under cursor" }) -- vim.keymap.set("n", "cs", require("telescope.builtin").lsp_document_symbols, { desc = "Document Symbols" }) + + vim.keymap.set("n", "nn", "Telescope notify", { desc = "List past notifications" }) end, }, } diff --git a/common/.config/nvim/lua/plugins/utility-plugs.lua b/common/.config/nvim/lua/plugins/utility-plugs.lua index 8a86027..81d2320 100644 --- a/common/.config/nvim/lua/plugins/utility-plugs.lua +++ b/common/.config/nvim/lua/plugins/utility-plugs.lua @@ -1,4 +1,180 @@ +local M = {} +---@type table> +M.dials_by_ft = {} + +---@param increment boolean +---@param g? boolean +function M.dial(increment, g) + local mode = vim.fn.mode(true) + -- Use visual commands for VISUAL 'v', VISUAL LINE 'V' and VISUAL BLOCK '\22' + local is_visual = mode == "v" or mode == "V" or mode == "\22" + local func = (increment and "inc" or "dec") .. (g and "_g" or "_") .. (is_visual and "visual" or "normal") + local group = M.dials_by_ft[vim.bo.filetype] or "default" + return require("dial.map")[func](group) +end + return { + -- Better increment/decrement with + { + "monaqa/dial.nvim", + -- stylua: ignore + keys = { + { "", function() return M.dial(true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, + { "", function() return M.dial(false) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, + { "g", function() return M.dial(true, true) end, expr = true, desc = "Increment", mode = {"n", "v"} }, + { "g", function() return M.dial(false, true) end, expr = true, desc = "Decrement", mode = {"n", "v"} }, + }, + opts = function() + local augend = require("dial.augend") + + local logical_alias = augend.constant.new({ + elements = { "&&", "||" }, + word = false, + cyclic = true, + }) + + local ordinal_numbers = augend.constant.new({ + -- elements through which we cycle. When we increment, we go down + -- On decrement we go up + elements = { + "first", + "second", + "third", + "fourth", + "fifth", + "sixth", + "seventh", + "eighth", + "ninth", + "tenth", + }, + -- if true, it only matches strings with word boundary. firstDate wouldn't work for example + word = false, + -- do we cycle back and forth (tenth to first on increment, first to tenth on decrement). + -- Otherwise nothing will happen when there are no further values + cyclic = true, + }) + + local weekdays = augend.constant.new({ + elements = { + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", + }, + word = true, + cyclic = true, + }) + + local months = augend.constant.new({ + elements = { + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + }, + word = true, + cyclic = true, + }) + + local capitalized_boolean = augend.constant.new({ + elements = { + "True", + "False", + }, + word = true, + cyclic = true, + }) + + return { + dials_by_ft = { + css = "css", + javascript = "typescript", + javascriptreact = "typescript", + json = "json", + lua = "lua", + markdown = "markdown", + python = "python", + sass = "css", + scss = "css", + typescript = "typescript", + typescriptreact = "typescript", + cs = "csharp", + }, + groups = { + default = { + augend.integer.alias.decimal, -- nonnegative decimal number (0, 1, 2, 3, ...) + augend.integer.alias.hex, -- nonnegative hex number (0x01, 0x1a1f, etc.) + augend.date.alias["%Y/%m/%d"], -- date (2022/02/19, etc.) + }, + typescript = { + augend.integer.alias.decimal, -- nonnegative and negative decimal number + augend.constant.alias.bool, -- boolean value (true <-> false) + logical_alias, + augend.constant.new({ elements = { "let", "const" } }), + ordinal_numbers, + weekdays, + months, + }, + css = { + augend.integer.alias.decimal, -- nonnegative and negative decimal number + augend.hexcolor.new({ + case = "lower", + }), + augend.hexcolor.new({ + case = "upper", + }), + }, + markdown = { + augend.misc.alias.markdown_header, + ordinal_numbers, + weekdays, + months, + }, + json = { + augend.integer.alias.decimal, -- nonnegative and negative decimal number + augend.semver.alias.semver, -- versioning (v1.1.2) + }, + lua = { + augend.integer.alias.decimal, -- nonnegative and negative decimal number + augend.constant.alias.bool, -- boolean value (true <-> false) + augend.constant.new({ + elements = { "and", "or" }, + word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc. + cyclic = true, -- "or" is incremented into "and". + }), + ordinal_numbers, + weekdays, + months, + }, + python = { + augend.integer.alias.decimal, -- nonnegative and negative decimal number + capitalized_boolean, + logical_alias, + ordinal_numbers, + weekdays, + months, + }, + }, + } + end, + config = function(_, opts) + require("dial.config").augends:register_group(opts.groups) + M.dials_by_ft = opts.dials_by_ft + end, + }, + -- Navigate between NVIM & Tmux splits seamlessly { "christoomey/vim-tmux-navigator" }, @@ -6,6 +182,12 @@ return { { "knubie/vim-kitty-navigator", build = "cp ./*.py ~/.config/kitty/", + keys = { + { "", "KittyNavigateLeft" }, + { "", "KittyNavigateDown" }, + { "", "KittyNavigateUp" }, + { "", "KittyNavigateRight" }, + }, }, -- Open Kitty terminal scrollback as buffer @@ -53,8 +235,9 @@ return { ["g"] = { name = "Git", _ = "which_key_ignore" }, ["h"] = { name = "Harpoon", _ = "which_key_ignore" }, ["l"] = { name = "List Things", _ = "which_key_ignore" }, - ["n"] = { name = "NVIM Operations", _ = "which_key_ignore" }, + ["n"] = { name = "NVIM Things", _ = "which_key_ignore" }, ["q"] = { name = "Database Query", _ = "which_key_ignore" }, + ["r"] = { name = "Refactor Code", _ = "which_key_ignore" }, ["s"] = { name = "Search/Grep Things", _ = "which_key_ignore" }, ["t"] = { name = "Unit Test Operations", _ = "which_key_ignore" }, ["x"] = { name = "Delete/Remove Something", _ = "which_key_ignore" },