update:restructure

This commit is contained in:
2026-04-15 12:00:40 +09:00
parent 28f36fc9ac
commit dc247c17af
18 changed files with 97 additions and 146 deletions

View File

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

View File

@@ -1,3 +1,4 @@
-- custom mason commands
local M = {}
function M.setup_install_defaults_command(tools)

View File

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

View File

@@ -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", {

View File

@@ -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", {

View File

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

View File

@@ -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" })

View File

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

View File

@@ -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" })

View File

@@ -1,6 +1,6 @@
local M = {}
local pack = require("utils.pack")
local pack = require("commands.pack")
function M.setup()
pack.add({ "mini.nvim" })

View File

@@ -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: <C+w><Left> or <Right>

View File

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

View File

@@ -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: <C+w><Left> or <Right>
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", "<leader>xx", function()
with_trouble(function()
vim.cmd("Trouble diagnostics toggle")
end)
end, { desc = "Diagnostics (Trouble)" })
vim.keymap.set("n", "<leader>xX", function()
with_trouble(function()
vim.cmd("Trouble diagnostics toggle filter.buf=0")
end)
end, { desc = "Buffer diagnostics" })
vim.keymap.set("n", "<leader>xQ", function()
with_trouble(function()
vim.cmd("Trouble qflist toggle")
end)
end, { desc = "Quickfix list" })
vim.keymap.set("n", "<leader>S", function()
with_grug(function()
vim.cmd("GrugFar")
end)
end, { desc = "Search/replace project" })
vim.keymap.set("n", "<leader>s", function()
with_grug(function(grug)
grug.open({ prefills = { paths = vim.fn.expand("%") } })
end)
end, { desc = "Search/replace current file" })
vim.keymap.set("x", "<leader>s", function()
with_grug(function(grug)
grug.open({ visualSelectionUsage = "operate-within-range" })
end)
end, { desc = "Search/replace in selection" })
end
return M

View File

@@ -1,6 +1,6 @@
local M = {}
local pack = require("utils.pack")
local pack = require("commands.pack")
function M.setup()
pack.add({ "nvim-treesitter" })

View File

@@ -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" })

View File

@@ -1,3 +1,4 @@
-- lazy loading function
local M = {}
local loaded = {}

View File

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