NVIM: Many updates

- new: Refactor plugin
- new: Dial plugin
- update: Trouble plugin updated to v3 and new API adopted
- fix: Fidget plugin was giving more LSP messages, tried to reduce
- fix: Harpoon settings synced with LazyNvim
- update: Shortcut for listing all notifications
- fix: Tmux navigation was being blocked by kitty-navigator. Fixed by
  adding keymaps to kitty-navigator
This commit is contained in:
Pratik Tripathy
2024-05-19 12:22:12 +05:30
parent b2a32b6a89
commit 0e35923ad0
5 changed files with 323 additions and 3 deletions

View File

@@ -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

View File

@@ -241,7 +241,7 @@ return {
},
},
keys = {
{ "<leader>o", "<cmd>Trouble symbols toggle focus=true<cr>", desc = "Code: Toggle Symbol Outline" },
{ "<leader>o", "<cmd>Trouble symbols toggle preview.type=main focus=true<cr>", desc = "Code: Toggle Symbol Outline" },
{ "<leader>dd", "<cmd>Trouble project_errors toggle focus=true<cr>", desc = "Trouble: Document Diagnostics" },
{ "<leader>dw", "<cmd>Trouble most_severe toggle focus=true<cr>", 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 = {
{
"<leader>rs",
function()
require("telescope").extensions.refactoring.refactors()
end,
mode = "v",
desc = "Refactor",
},
{
"<leader>ri",
function()
require("refactoring").refactor("Inline Variable")
end,
mode = { "n", "v" },
desc = "Inline Variable",
},
{
"<leader>rb",
function()
require("refactoring").refactor("Extract Block")
end,
desc = "Extract Block",
},
{
"<leader>rf",
function()
require("refactoring").refactor("Extract Block To File")
end,
desc = "Extract Block To File",
},
{
"<leader>rP",
function()
require("refactoring").debug.printf({ below = false })
end,
desc = "Debug Print",
},
{
"<leader>rp",
function()
require("refactoring").debug.print_var({ normal = true })
end,
desc = "Debug Print Variable",
},
{
"<leader>rc",
function()
require("refactoring").debug.cleanup({})
end,
desc = "Debug Cleanup",
},
{
"<leader>rf",
function()
require("refactoring").refactor("Extract Function")
end,
mode = "v",
desc = "Extract Function",
},
{
"<leader>rF",
function()
require("refactoring").refactor("Extract Function To File")
end,
mode = "v",
desc = "Extract Function To File",
},
{
"<leader>rx",
function()
require("refactoring").refactor("Extract Variable")
end,
mode = "v",
desc = "Extract Variable",
},
{
"<leader>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 = {
["<leader>r"] = { name = "+refactor" },
},
},
},
}

View File

@@ -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
},
},

View File

@@ -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", "<leader>cR", require("telescope.builtin").lsp_references, { desc = "Code: List References for word under cursor" })
-- vim.keymap.set("n", "<leader>cs", require("telescope.builtin").lsp_document_symbols, { desc = "Document Symbols" })
vim.keymap.set("n", "<leader>nn", "<cmd>Telescope notify<cr>", { desc = "List past notifications" })
end,
},
}

View File

@@ -1,4 +1,180 @@
local M = {}
---@type table<string, table<string, string[]>>
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 <Ctrl+a>
{
"monaqa/dial.nvim",
-- stylua: ignore
keys = {
{ "<C-a>", function() return M.dial(true) end, expr = true, desc = "Increment", mode = {"n", "v"} },
{ "<C-x>", function() return M.dial(false) end, expr = true, desc = "Decrement", mode = {"n", "v"} },
{ "g<C-a>", function() return M.dial(true, true) end, expr = true, desc = "Increment", mode = {"n", "v"} },
{ "g<C-x>", 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 = {
{ "<C-S-h>", "<cmd>KittyNavigateLeft<cr>" },
{ "<C-S-j>", "<cmd>KittyNavigateDown<cr>" },
{ "<C-S-k>", "<cmd>KittyNavigateUp<cr>" },
{ "<C-S-l>", "<cmd>KittyNavigateRight<cr>" },
},
},
-- Open Kitty terminal scrollback as buffer
@@ -53,8 +235,9 @@ return {
["<leader>g"] = { name = "Git", _ = "which_key_ignore" },
["<leader>h"] = { name = "Harpoon", _ = "which_key_ignore" },
["<leader>l"] = { name = "List Things", _ = "which_key_ignore" },
["<leader>n"] = { name = "NVIM Operations", _ = "which_key_ignore" },
["<leader>n"] = { name = "NVIM Things", _ = "which_key_ignore" },
["<leader>q"] = { name = "Database Query", _ = "which_key_ignore" },
["<leader>r"] = { name = "Refactor Code", _ = "which_key_ignore" },
["<leader>s"] = { name = "Search/Grep Things", _ = "which_key_ignore" },
["<leader>t"] = { name = "Unit Test Operations", _ = "which_key_ignore" },
["<leader>x"] = { name = "Delete/Remove Something", _ = "which_key_ignore" },