From dc247c17af6fc7c89c856f8b061af59d302428f4 Mon Sep 17 00:00:00 2001 From: kokopi-dev Date: Wed, 15 Apr 2026 12:00:40 +0900 Subject: [PATCH] update:restructure --- nvim/init.lua | 2 +- nvim/lua/{utils => commands}/mason.lua | 1 + nvim/lua/commands/pack.lua | 81 +++++++++++++++++++ nvim/lua/plugins/ai.lua | 2 +- nvim/lua/plugins/autotag.lua | 2 +- nvim/lua/plugins/catppuccin.lua | 2 +- nvim/lua/plugins/cmp.lua | 2 +- nvim/lua/plugins/error-viewer.lua | 2 +- .../{lsp_tools.lua => lsp-manager.lua} | 0 nvim/lua/plugins/lsp.lua | 6 +- nvim/lua/plugins/mini.lua | 2 +- nvim/lua/plugins/search-replace.lua | 2 +- nvim/lua/plugins/telescope.lua | 2 +- nvim/lua/plugins/tools.lua | 60 -------------- nvim/lua/plugins/treesitter.lua | 2 +- nvim/lua/plugins/ui.lua | 2 +- nvim/lua/utils/lazy.lua | 1 + nvim/lua/utils/pack.lua | 72 ----------------- 18 files changed, 97 insertions(+), 146 deletions(-) rename nvim/lua/{utils => commands}/mason.lua (97%) create mode 100644 nvim/lua/commands/pack.lua rename nvim/lua/plugins/{lsp_tools.lua => lsp-manager.lua} (100%) delete mode 100644 nvim/lua/plugins/tools.lua diff --git a/nvim/init.lua b/nvim/init.lua index 1732de7..edf0bdf 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,7 +1,7 @@ vim.loader.enable() -- pack hooks/commands should be defined before plugin modules run -require("utils.pack").setup() +require("commands.pack").setup() -- editor settings and non-plugin keymaps require("settings.options") diff --git a/nvim/lua/utils/mason.lua b/nvim/lua/commands/mason.lua similarity index 97% rename from nvim/lua/utils/mason.lua rename to nvim/lua/commands/mason.lua index e743480..134f2d7 100644 --- a/nvim/lua/utils/mason.lua +++ b/nvim/lua/commands/mason.lua @@ -1,3 +1,4 @@ +-- custom mason commands local M = {} function M.setup_install_defaults_command(tools) diff --git a/nvim/lua/commands/pack.lua b/nvim/lua/commands/pack.lua new file mode 100644 index 0000000..3aa1e4e --- /dev/null +++ b/nvim/lua/commands/pack.lua @@ -0,0 +1,81 @@ +local M = {} + +local pack = require("utils.pack") + +M.registry = pack.registry +M.add = pack.add +M.names = pack.names + +function M.setup() + local group = vim.api.nvim_create_augroup("UserPackHooks", { clear = true }) + + vim.api.nvim_create_autocmd("PackChanged", { + group = group, + callback = function(ev) + local plugin_name, kind = ev.data.spec.name, ev.data.kind + if plugin_name == "nvim-treesitter" and kind == "update" then + if not ev.data.active then + vim.cmd.packadd("nvim-treesitter") + end + pcall(vim.cmd, "TSUpdate") + end + end, + }) + + vim.api.nvim_create_user_command("PackInstall", function() + M.add(M.names(), { + confirm = false, + load = function() end, + }) + vim.notify("PackInstall: ensured all configured plugins are installed", vim.log.levels.INFO) + end, { desc = "Install all configured vim.pack plugins without loading" }) + + vim.api.nvim_create_user_command("PackUpdate", function(opts) + local names = (#opts.fargs > 0) and opts.fargs or nil + vim.pack.update(names) + end, { + nargs = "*", + complete = function(arglead) + local out = {} + for _, name in ipairs(M.names()) do + if name:find("^" .. vim.pesc(arglead)) then + table.insert(out, name) + end + end + return out + end, + desc = "Update vim.pack plugins (optionally pass plugin names)", + }) + + vim.api.nvim_create_user_command("PackSync", function() + vim.pack.update(nil, { target = "lockfile" }) + end, { desc = "Sync installed plugins to nvim-pack-lock.json" }) + + vim.api.nvim_create_user_command("PackClean", function() + local stale = vim.iter(vim.pack.get()) + :filter(function(plugin) + return not plugin.active + end) + :map(function(plugin) + return plugin.spec.name + end) + :totable() + + if #stale == 0 then + vim.notify("PackClean: nothing to clean", vim.log.levels.INFO) + return + end + + local msg = "PackClean will remove:\n - " .. table.concat(stale, "\n - ") + local choice = vim.fn.confirm(msg, "&Yes\n&No", 2) + if choice ~= 1 then + vim.notify("PackClean: cancelled", vim.log.levels.INFO) + return + end + + vim.pack.del(stale) + vim.notify("PackClean: removed " .. #stale .. " plugin(s)", vim.log.levels.INFO) + end, { desc = "Delete inactive vim.pack plugins from disk" }) +end + +return M diff --git a/nvim/lua/plugins/ai.lua b/nvim/lua/plugins/ai.lua index 9fbf808..3b8af1c 100644 --- a/nvim/lua/plugins/ai.lua +++ b/nvim/lua/plugins/ai.lua @@ -1,6 +1,6 @@ local M = {} -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() vim.api.nvim_create_autocmd("InsertEnter", { diff --git a/nvim/lua/plugins/autotag.lua b/nvim/lua/plugins/autotag.lua index 5ad4c15..fa9ed23 100644 --- a/nvim/lua/plugins/autotag.lua +++ b/nvim/lua/plugins/autotag.lua @@ -1,6 +1,6 @@ local M = {} -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() vim.api.nvim_create_autocmd("FileType", { diff --git a/nvim/lua/plugins/catppuccin.lua b/nvim/lua/plugins/catppuccin.lua index bc86c57..743021c 100644 --- a/nvim/lua/plugins/catppuccin.lua +++ b/nvim/lua/plugins/catppuccin.lua @@ -1,7 +1,7 @@ local M = {} local ui = require("utils.ui") -local pack = require("utils.pack") +local pack = require("commands.pack") local function apply_theme_overrides() local transparent_groups = { diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua index 2e4b3eb..12d167d 100644 --- a/nvim/lua/plugins/cmp.lua +++ b/nvim/lua/plugins/cmp.lua @@ -1,7 +1,7 @@ local M = {} local ui = require("utils.ui") -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() pack.add({ "nvim-cmp", "cmp-nvim-lsp", "cmp-buffer", "cmp-path", "luasnip", "cmp_luasnip" }) diff --git a/nvim/lua/plugins/error-viewer.lua b/nvim/lua/plugins/error-viewer.lua index 685d34d..08f3ace 100644 --- a/nvim/lua/plugins/error-viewer.lua +++ b/nvim/lua/plugins/error-viewer.lua @@ -1,7 +1,7 @@ local M = {} local lazy = require("utils.lazy") -local pack = require("utils.pack") +local pack = require("commands.pack") local function with_trouble(fn) lazy.load_once("trouble", pack.registry({ "trouble.nvim" }), function() diff --git a/nvim/lua/plugins/lsp_tools.lua b/nvim/lua/plugins/lsp-manager.lua similarity index 100% rename from nvim/lua/plugins/lsp_tools.lua rename to nvim/lua/plugins/lsp-manager.lua diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index fa2133e..a4785b9 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -1,8 +1,8 @@ local M = {} -local pack = require("utils.pack") -local mason_utils = require("utils.mason") -local lsp_tools = require("plugins.lsp_tools") +local pack = require("commands.pack") +local mason_utils = require("commands.mason") +local lsp_tools = require("plugins.lsp-manager") function M.setup() pack.add({ "mason", "nvim-lspconfig", "conform", "symbol-usage" }) diff --git a/nvim/lua/plugins/mini.lua b/nvim/lua/plugins/mini.lua index 5583cee..070380a 100644 --- a/nvim/lua/plugins/mini.lua +++ b/nvim/lua/plugins/mini.lua @@ -1,6 +1,6 @@ local M = {} -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() pack.add({ "mini.nvim" }) diff --git a/nvim/lua/plugins/search-replace.lua b/nvim/lua/plugins/search-replace.lua index d6393ec..ce87b4f 100644 --- a/nvim/lua/plugins/search-replace.lua +++ b/nvim/lua/plugins/search-replace.lua @@ -1,7 +1,7 @@ local M = {} local lazy = require("utils.lazy") -local pack = require("utils.pack") +local pack = require("commands.pack") -- grug guide -- navigate splits: or diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua index fb896e9..253f5c4 100644 --- a/nvim/lua/plugins/telescope.lua +++ b/nvim/lua/plugins/telescope.lua @@ -1,7 +1,7 @@ local M = {} local lazy = require("utils.lazy") -local pack = require("utils.pack") +local pack = require("commands.pack") local function with_telescope(fn) lazy.load_once("telescope", pack.registry({ "plenary.nvim", "telescope.nvim" }), function() diff --git a/nvim/lua/plugins/tools.lua b/nvim/lua/plugins/tools.lua deleted file mode 100644 index 6c0f228..0000000 --- a/nvim/lua/plugins/tools.lua +++ /dev/null @@ -1,60 +0,0 @@ -local M = {} - -local lazy = require("utils.lazy") -local pack = require("utils.pack") - -local function with_trouble(fn) - lazy.load_once("trouble", pack.registry({ "trouble.nvim" }), function() - require("trouble").setup({}) - end) - fn() -end - --- grug guide --- navigate splits: or -local function with_grug(fn) - lazy.load_once("grug-far", pack.registry({ "grug-far.nvim" }), function() - require("grug-far").setup({}) - end) - fn(require("grug-far")) -end - -function M.setup() - vim.keymap.set("n", "xx", function() - with_trouble(function() - vim.cmd("Trouble diagnostics toggle") - end) - end, { desc = "Diagnostics (Trouble)" }) - - vim.keymap.set("n", "xX", function() - with_trouble(function() - vim.cmd("Trouble diagnostics toggle filter.buf=0") - end) - end, { desc = "Buffer diagnostics" }) - - vim.keymap.set("n", "xQ", function() - with_trouble(function() - vim.cmd("Trouble qflist toggle") - end) - end, { desc = "Quickfix list" }) - - vim.keymap.set("n", "S", function() - with_grug(function() - vim.cmd("GrugFar") - end) - end, { desc = "Search/replace project" }) - - vim.keymap.set("n", "s", function() - with_grug(function(grug) - grug.open({ prefills = { paths = vim.fn.expand("%") } }) - end) - end, { desc = "Search/replace current file" }) - - vim.keymap.set("x", "s", function() - with_grug(function(grug) - grug.open({ visualSelectionUsage = "operate-within-range" }) - end) - end, { desc = "Search/replace in selection" }) -end - -return M diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 06313f9..bdc96c3 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -1,6 +1,6 @@ local M = {} -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() pack.add({ "nvim-treesitter" }) diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua index 74e2426..569f151 100644 --- a/nvim/lua/plugins/ui.lua +++ b/nvim/lua/plugins/ui.lua @@ -1,6 +1,6 @@ local M = {} -local pack = require("utils.pack") +local pack = require("commands.pack") function M.setup() pack.add({ "nvim-web-devicons", "indent-blankline.nvim", "lualine.nvim", "bufferline.nvim" }) diff --git a/nvim/lua/utils/lazy.lua b/nvim/lua/utils/lazy.lua index e4c5c94..b8ce54d 100644 --- a/nvim/lua/utils/lazy.lua +++ b/nvim/lua/utils/lazy.lua @@ -1,3 +1,4 @@ +-- lazy loading function local M = {} local loaded = {} diff --git a/nvim/lua/utils/pack.lua b/nvim/lua/utils/pack.lua index 9e83e28..c77e1fb 100644 --- a/nvim/lua/utils/pack.lua +++ b/nvim/lua/utils/pack.lua @@ -14,76 +14,4 @@ function M.names() return registry.names() end -function M.setup() - local group = vim.api.nvim_create_augroup("UserPackHooks", { clear = true }) - - vim.api.nvim_create_autocmd("PackChanged", { - group = group, - callback = function(ev) - local plugin_name, kind = ev.data.spec.name, ev.data.kind - if plugin_name == "nvim-treesitter" and kind == "update" then - if not ev.data.active then - vim.cmd.packadd("nvim-treesitter") - end - pcall(vim.cmd, "TSUpdate") - end - end, - }) - - vim.api.nvim_create_user_command("PackInstall", function() - M.add(M.names(), { - confirm = false, - load = function() end, - }) - vim.notify("PackInstall: ensured all configured plugins are installed", vim.log.levels.INFO) - end, { desc = "Install all configured vim.pack plugins without loading" }) - - vim.api.nvim_create_user_command("PackUpdate", function(opts) - local names = (#opts.fargs > 0) and opts.fargs or nil - vim.pack.update(names) - end, { - nargs = "*", - complete = function(arglead) - local out = {} - for _, name in ipairs(M.names()) do - if name:find("^" .. vim.pesc(arglead)) then - table.insert(out, name) - end - end - return out - end, - desc = "Update vim.pack plugins (optionally pass plugin names)", - }) - - vim.api.nvim_create_user_command("PackSync", function() - vim.pack.update(nil, { target = "lockfile" }) - end, { desc = "Sync installed plugins to nvim-pack-lock.json" }) - - vim.api.nvim_create_user_command("PackClean", function() - local stale = vim.iter(vim.pack.get()) - :filter(function(plugin) - return not plugin.active - end) - :map(function(plugin) - return plugin.spec.name - end) - :totable() - - if #stale == 0 then - vim.notify("PackClean: nothing to clean", vim.log.levels.INFO) - return - end - - local msg = "PackClean will remove:\n - " .. table.concat(stale, "\n - ") - local choice = vim.fn.confirm(msg, "&Yes\n&No", 2) - if choice ~= 1 then - vim.notify("PackClean: cancelled", vim.log.levels.INFO) - return - end - - vim.pack.del(stale) - vim.notify("PackClean: removed " .. #stale .. " plugin(s)", vim.log.levels.INFO) - end, { desc = "Delete inactive vim.pack plugins from disk" }) -end - return M