diff --git a/nvim/lua/terminal.lua b/nvim/lua/terminal.lua index b810339..77b1829 100644 --- a/nvim/lua/terminal.lua +++ b/nvim/lua/terminal.lua @@ -35,7 +35,8 @@ local function toggle_terminal() vim.api.nvim_command("startinsert") end -vim.keymap.set("n", "t", function() + +utils.set_keymap_list({{ "t", function() toggle_terminal() require("window_management").autosize_windows() -end) +end }}) diff --git a/nvim/nvim-pack-lock.json b/nvim/nvim-pack-lock.json index c285d46..7fcab8d 100644 --- a/nvim/nvim-pack-lock.json +++ b/nvim/nvim-pack-lock.json @@ -30,10 +30,6 @@ "rev": "8b54c59bcb23366645ae10edca6edfb9d3a0853e", "src": "https://github.com/b0o/incline.nvim" }, - "live-rename.nvim": { - "rev": "3a3cddf23b89a17992f9ca67afc5858077769462", - "src": "https://github.com/saecki/live-rename.nvim" - }, "logger.nvim": { "rev": "63dd10c9b9a159fd6cfe08435d9606384ff103c5", "src": "https://github.com/rmagatti/logger.nvim" @@ -63,7 +59,7 @@ "src": "https://github.com/MunifTanjim/nui.nvim" }, "nvim-dap": { - "rev": "2a8799ad91a1495c6bdf753f9b2179b3ff0f5bba", + "rev": "45a69eba683a2c448dd9ecfc4de89511f0646b5f", "src": "https://github.com/mfussenegger/nvim-dap" }, "nvim-dap-go": { @@ -75,7 +71,7 @@ "src": "https://github.com/LiadOz/nvim-dap-repl-highlights" }, "nvim-dap-ui": { - "rev": "f5b6673f374626515401c5bc51b005f784a4f252", + "rev": "1a66cabaa4a4da0be107d5eda6d57242f0fe7e49", "src": "https://github.com/rcarriga/nvim-dap-ui" }, "nvim-dap-virtual-text": { @@ -94,6 +90,10 @@ "rev": "57e1fa7638e753efbd62e5aa53b82b08a80fed7e", "src": "https://github.com/LarssonMartin1998/nvim-norrsken" }, + "nvim-rephrase": { + "rev": "3391726e2768fd241e89d032f8523ea053099387", + "src": "git@github.com:LarssonMartin1998/nvim-rephrase" + }, "nvim-treesitter": { "rev": "7caec274fd19c12b55902a5b795100d21531391f", "src": "https://github.com/nvim-treesitter/nvim-treesitter", diff --git a/nvim/plugin/0-pack.lua b/nvim/plugin/0-pack.lua index 4fd30eb..e569e35 100644 --- a/nvim/plugin/0-pack.lua +++ b/nvim/plugin/0-pack.lua @@ -3,47 +3,27 @@ local function gh(repo) end vim.pack.add({ - -- Mini suite + -- Foundational gh("LarssonMartin1998/mini.nvim"), + { src = gh("nvim-treesitter/nvim-treesitter"), version = "main" }, -- Colorscheme gh("rktjmp/lush.nvim"), gh("LarssonMartin1998/nvim-norrsken"), - -- Treesitter - { src = gh("nvim-treesitter/nvim-treesitter"), version = "main" }, - gh("nvim-treesitter/nvim-treesitter-context"), - gh("nvim-treesitter/nvim-treesitter-textobjects"), - - -- Completion - gh("rafamadriz/friendly-snippets"), - { src = gh("L3MON4D3/LuaSnip"), version = vim.version.range("2.x") }, - { src = gh("saghen/blink.cmp"), version = vim.version.range("1.x") }, - -- UI gh("nvim-lualine/lualine.nvim"), gh("b0o/incline.nvim"), - gh("kosayoda/nvim-lightbulb"), - gh("rachartier/tiny-glimmer.nvim"), - gh("rachartier/tiny-inline-diagnostic.nvim"), - -- DAP - gh("mfussenegger/nvim-dap"), - gh("rcarriga/nvim-dap-ui"), - gh("nvim-neotest/nvim-nio"), - gh("LiadOz/nvim-dap-repl-highlights"), - gh("theHamsta/nvim-dap-virtual-text"), - gh("Weissle/persistent-breakpoints.nvim"), - gh("leoluz/nvim-dap-go"), + -- Motions + gh("mawkler/demicolon.nvim"), + gh("nvim-treesitter/nvim-treesitter-textobjects"), -- Misc gh("OXY2DEV/markview.nvim"), gh("MunifTanjim/nui.nvim"), - gh("xzbdmw/colorful-menu.nvim"), }) -require("colorful-menu").setup({}) - vim.cmd.packadd("nvim.undotree") vim.api.nvim_create_user_command("VimPackClean", function() diff --git a/nvim/plugin/00-treesitter.lua b/nvim/plugin/00-treesitter.lua index c786e0c..b2e93a7 100644 --- a/nvim/plugin/00-treesitter.lua +++ b/nvim/plugin/00-treesitter.lua @@ -45,10 +45,16 @@ vim.schedule(function() }) end) -require("treesitter-context").setup({ - max_lines = 2, - multiline_threshold = 3, - trim_scope = "inner", +vim.api.nvim_create_autocmd("CursorMoved", { + once = true, + callback = function() + vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter-context" }) + require("treesitter-context").setup({ + max_lines = 2, + multiline_threshold = 3, + trim_scope = "inner", + }) + end, }) -- Textobject helpers diff --git a/nvim/plugin/blink.lua b/nvim/plugin/blink.lua index e0ca733..1c8c93e 100644 --- a/nvim/plugin/blink.lua +++ b/nvim/plugin/blink.lua @@ -1,3 +1,55 @@ +local function gh(repo) + return "https://github.com/" .. repo +end + +vim.api.nvim_create_autocmd("ModeChanged", { + once = true, + callback = function() + vim.pack.add({ + gh("rafamadriz/friendly-snippets"), + { src = gh("L3MON4D3/LuaSnip"), version = vim.version.range("2.x") }, + { src = gh("saghen/blink.cmp"), version = vim.version.range("1.x") }, + gh("xzbdmw/colorful-menu.nvim"), + }) + + require("blink.cmp").setup({ + keymap = { preset = "super-tab" }, + appearance = { + nerd_font_variant = "mono", + }, + completion = { + documentation = { + auto_show = false, + }, + menu = { + draw = { + columns = { { "kind_icon" }, { "label", gap = 1 } }, + components = { + label = { + text = function(ctx) + return require("colorful-menu").blink_components_text(ctx) + end, + highlight = function(ctx) + return require("colorful-menu").blink_components_highlight(ctx) + end, + }, + }, + }, + }, + }, + snippets = { + preset = "luasnip", + active = function() return false end, + }, + sources = { + default = { "lsp", "path", "snippets", "buffer" }, + }, + fuzzy = { implementation = "prefer_rust_with_warning" }, + }) + require("colorful-menu").setup({}) + end, +}) + local ls = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() ls.filetype_extend("typescriptreact", { "html" }) @@ -6,38 +58,3 @@ ls.config.set_config({ enable_autosnippets = false, store_selection_keys = false, }) - -require("blink.cmp").setup({ - keymap = { preset = "super-tab" }, - appearance = { - nerd_font_variant = "mono", - }, - completion = { - documentation = { - auto_show = false, - }, - menu = { - draw = { - columns = { { "kind_icon" }, { "label", gap = 1 } }, - components = { - label = { - text = function(ctx) - return require("colorful-menu").blink_components_text(ctx) - end, - highlight = function(ctx) - return require("colorful-menu").blink_components_highlight(ctx) - end, - }, - }, - }, - }, - }, - snippets = { - preset = "luasnip", - active = function() return false end, - }, - sources = { - default = { "lsp", "path", "snippets", "buffer" }, - }, - fuzzy = { implementation = "prefer_rust_with_warning" }, -}) diff --git a/nvim/plugin/demicolon.lua b/nvim/plugin/demicolon.lua index 53aba28..3577ca4 100644 --- a/nvim/plugin/demicolon.lua +++ b/nvim/plugin/demicolon.lua @@ -1,8 +1,5 @@ -vim.schedule(function() - vim.pack.add({ "https://github.com/mawkler/demicolon.nvim" }) - require("demicolon").setup({ - keymaps = { - repeat_motions = "stateful", - }, - }) -end) +require("demicolon").setup({ + keymaps = { + repeat_motions = "stateful", + }, +}) diff --git a/nvim/plugin/goto-preview.lua b/nvim/plugin/goto-preview.lua index 6202af4..c0815f6 100644 --- a/nvim/plugin/goto-preview.lua +++ b/nvim/plugin/goto-preview.lua @@ -1,21 +1,26 @@ -vim.schedule(function() - vim.pack.add({ - "https://github.com/rmagatti/logger.nvim", - "https://github.com/rmagatti/goto-preview", - }) +local function gh(repo) + return "https://github.com/" .. repo +end - require("goto-preview").setup({ - border = { "↖", "─", "┐", "│", "┘", "─", "└", "│" }, - focus_on_open = true, - stack_floating_preview_windows = false, - preview_window_title = { enable = true, position = "left" }, - vim_ui_input = false, - }) +vim.api.nvim_create_autocmd("LspAttach", { + once = true, + callback = function() + vim.pack.add({ + gh("https://github.com/rmagatti/goto-preview"), + gh("rmagatti/logger.nvim") + }) + require("goto-preview").setup({ + border = { "↖", "─", "┐", "│", "┘", "─", "└", "│" }, + focus_on_open = true, + stack_floating_preview_windows = false, + preview_window_title = { enable = true, position = "left" }, + vim_ui_input = false, + }) - local utils = require("utils") - utils.set_keymap_list({ - { "gp", function() require("goto-preview").goto_preview_definition() end }, - { "gy", function() require("goto-preview").goto_preview_type_definition() end }, - { "q", function() require("goto-preview").close_all_win() end }, - }) -end) + require("utils").set_keymap_list({ + { "gp", function() require("goto-preview").goto_preview_definition() end }, + { "gy", function() require("goto-preview").goto_preview_type_definition() end }, + { "q", function() require("goto-preview").close_all_win() end }, + }) + end, +}) diff --git a/nvim/plugin/nvim-dap.lua b/nvim/plugin/nvim-dap.lua index d29f78a..7c91dd7 100644 --- a/nvim/plugin/nvim-dap.lua +++ b/nvim/plugin/nvim-dap.lua @@ -3,95 +3,148 @@ local inlay_hints_handler = require("inlay_hints_handler") local is_debug_mode_active = false -local dap = require("dap") +local function gh(repo) + return "https://github.com/" .. repo +end -require("nvim-dap-repl-highlights").setup({}) -require("nvim-dap-virtual-text").setup({}) -require("persistent-breakpoints").setup({ load_breakpoints_event = { "BufReadPost" } }) -require("dapui").setup({ - controls = { enabled = false }, - layouts = { - { - elements = { - { id = "watches", size = 0.5 }, - { id = "stacks", size = 0.5 }, - }, - position = "bottom", - size = 15, - }, - }, +vim.api.nvim_create_autocmd("BufReadPost", { + once = true, + callback = function() + vim.pack.add({ + gh("Weissle/persistent-breakpoints.nvim"), + }) + require("persistent-breakpoints").setup({ + load_breakpoints_event = { "BufReadPost" }, + }) + end, }) -require("dap-go").setup({}) -dap.adapters.codelldb = require("dap.codelldb") +local function setup_dap() + vim.pack.add({ + gh("mfussenegger/nvim-dap"), + gh("rcarriga/nvim-dap-ui"), + gh("nvim-neotest/nvim-nio"), + gh("LiadOz/nvim-dap-repl-highlights"), + gh("theHamsta/nvim-dap-virtual-text"), + gh("leoluz/nvim-dap-go"), + }) -local virtual_text = require("nvim-dap-virtual-text/virtual_text") -local breakpoint_api = require("persistent-breakpoints.api") + local dap = require("dap") -local stepping_keymaps = { - { "", function() dap.step_over() end }, - { "", function() dap.step_into() end }, - { "", function() dap.step_out() end }, - { - "dc", - function() - require("dapui").float_element("console", { - enter = true, - title = "output", - border = "rounded", - position = "center", - width = math.floor(vim.o.columns * 0.8), - height = math.floor(vim.o.lines * 0.6), - }) - end, - }, -} + require("nvim-dap-repl-highlights").setup({}) + require("nvim-dap-virtual-text").setup({}) + require("dapui").setup({ + controls = { enabled = false }, + layouts = { + { + elements = { + { id = "watches", size = 0.5 }, + { id = "stacks", size = 0.5 }, + }, + position = "bottom", + size = 15, + }, + }, + }) + require("dap-go").setup({}) -for _, sign in ipairs({ - { "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } }, - { "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } }, - { "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } }, -}) do - vim.fn.sign_define(unpack(sign)) + dap.adapters.codelldb = require("dap.codelldb") + + for _, sign in ipairs({ + { "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } }, + { "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } }, + { "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } }, + }) do + vim.fn.sign_define(unpack(sign)) + end + + local virtual_text = require("nvim-dap-virtual-text/virtual_text") + + local stepping_keymaps = { + { "", function() dap.step_over() end }, + { "", function() dap.step_into() end }, + { "", function() dap.step_out() end }, + { + "dc", + function() + require("dapui").float_element("console", { + enter = true, + title = "output", + border = "rounded", + position = "center", + width = math.floor(vim.o.columns * 0.8), + height = math.floor(vim.o.lines * 0.6), + }) + end, + }, + } + + local function enter_debug_mode() + if is_debug_mode_active then return end + utils.set_keymap_list(stepping_keymaps) + is_debug_mode_active = true + inlay_hints_handler.disable() + require("dapui").open() + end + + local function exit_debug_mode() + if not is_debug_mode_active then return end + utils.del_keymap_list(stepping_keymaps) + is_debug_mode_active = false + inlay_hints_handler.restore() + virtual_text.clear_virtual_text() + require("dapui").close() + end + + for _, request in ipairs({ "attach", "launch" }) do + dap.listeners.before[request]["dapui_config"] = enter_debug_mode + end + + for _, event in ipairs({ "event_terminated", "event_exited" }) do + dap.listeners.after[event]["dapui_config"] = exit_debug_mode + end end -local function enter_debug_mode() - if is_debug_mode_active then return end - utils.set_keymap_list(stepping_keymaps) - is_debug_mode_active = true - inlay_hints_handler.disable() - require("dapui").open() -end - -local function exit_debug_mode() - if not is_debug_mode_active then return end - utils.del_keymap_list(stepping_keymaps) - is_debug_mode_active = false - inlay_hints_handler.restore() - virtual_text.clear_virtual_text() - require("dapui").close() -end - -for _, request in ipairs({ "attach", "launch" }) do - dap.listeners.before[request]["dapui_config"] = enter_debug_mode -end - -for _, event in ipairs({ "event_terminated", "event_exited" }) do - dap.listeners.after[event]["dapui_config"] = exit_debug_mode -end - -local function dap_stop() - dap.terminate() - dap.close() - exit_debug_mode() +local function with_dap(fn) + return function(...) + setup_dap() + return fn(...) + end end utils.set_keymap_list({ - { "dr", dap.continue }, - { "bt", breakpoint_api.toggle_breakpoint }, - { "bc", breakpoint_api.set_conditional_breakpoint }, - { "br", breakpoint_api.clear_all_breakpoints }, - { "ds", dap_stop }, + { + "dr", + with_dap(function() + require("dap").continue() + end), + }, + { + "bt", + function() + require("persistent-breakpoints.api").toggle_breakpoint() + end, + }, + { + "bc", + function() + require("persistent-breakpoints.api").set_conditional_breakpoint() + end, + }, + { + "br", + function() + require("persistent-breakpoints.api").clear_all_breakpoints() + end, + }, + { + "ds", + with_dap(function() + local dap = require("dap") + dap.terminate() + dap.close() + end), + }, }) vim.api.nvim_create_user_command("LaunchTemplate", function() diff --git a/nvim/plugin/nvim-lightbulb.lua b/nvim/plugin/nvim-lightbulb.lua index 054e593..1779563 100644 --- a/nvim/plugin/nvim-lightbulb.lua +++ b/nvim/plugin/nvim-lightbulb.lua @@ -1,9 +1,15 @@ -require("nvim-lightbulb").setup({ - hide_in_unfocused_buffer = true, - code_lenses = false, -- 0.12 shows code lenses as virtual lines natively - sign = { enabled = true }, - virtual_text = { enabled = false }, - float = { enabled = false }, - status_text = { enabled = false }, - autocmd = { enabled = true, updatetime = 25 }, +vim.api.nvim_create_autocmd("LspAttach", { + once = true, + callback = function() + vim.pack.add({ "https://github.com/kosayoda/nvim-lightbulb" }) + require("nvim-lightbulb").setup({ + hide_in_unfocused_buffer = true, + code_lenses = false, -- 0.12 shows code lenses as virtual lines natively + sign = { enabled = true }, + virtual_text = { enabled = false }, + float = { enabled = false }, + status_text = { enabled = false }, + autocmd = { enabled = true, updatetime = 25 }, + }) + end, }) diff --git a/nvim/plugin/tiny-glimmer.lua b/nvim/plugin/tiny-glimmer.lua index 96f8efd..776cc1a 100644 --- a/nvim/plugin/tiny-glimmer.lua +++ b/nvim/plugin/tiny-glimmer.lua @@ -1,24 +1,30 @@ -require("tiny-glimmer").setup({ - refresh_interval_ms = 6, - overwrite = { - auto_map = true, - paste = { - enabled = true, - default_animation = { name = "fade", settings = { from_color = "DiffText" } }, - }, - undo = { - enabled = true, - default_animation = { name = "fade", settings = { from_color = "DiffDelete" } }, - }, - redo = { - enabled = true, - default_animation = { name = "fade", settings = { from_color = "DiffAdd" } }, - }, - }, - animations = { - fade = { - chars_for_max_duration = 1, - to_color = "Folded", - }, - }, +vim.api.nvim_create_autocmd("CursorMoved", { + once = true, + callback = function() + vim.pack.add({ "https://github.com/rachartier/tiny-glimmer.nvim" }) + require("tiny-glimmer").setup({ + refresh_interval_ms = 6, + overwrite = { + auto_map = true, + paste = { + enabled = true, + default_animation = { name = "fade", settings = { from_color = "DiffText" } }, + }, + undo = { + enabled = true, + default_animation = { name = "fade", settings = { from_color = "DiffDelete" } }, + }, + redo = { + enabled = true, + default_animation = { name = "fade", settings = { from_color = "DiffAdd" } }, + }, + }, + animations = { + fade = { + chars_for_max_duration = 1, + to_color = "Folded", + }, + }, + }) + end, }) diff --git a/nvim/plugin/tiny-inline-diagnostics.lua b/nvim/plugin/tiny-inline-diagnostics.lua index 1ac7b90..12c866a 100644 --- a/nvim/plugin/tiny-inline-diagnostics.lua +++ b/nvim/plugin/tiny-inline-diagnostics.lua @@ -1,11 +1,17 @@ -require("tiny-inline-diagnostic").setup({ - preset = "modern", - transparent_bg = false, - transparent_cursorline = false, - options = { - multilines = { - enabled = true, - always_show = true, - }, - }, +vim.api.nvim_create_autocmd("LspAttach", { + once = true, + callback = function() + vim.pack.add({ "https://github.com/rachartier/tiny-inline-diagnostic.nvim" }) + require("tiny-inline-diagnostic").setup({ + preset = "modern", + transparent_bg = false, + transparent_cursorline = false, + options = { + multilines = { + enabled = true, + always_show = true, + }, + }, + }) + end, })