From 2bd4cc0098aed4fe7eba7fd2a1fddce774c92ebb Mon Sep 17 00:00:00 2001 From: kokopi-dev Date: Mon, 13 Apr 2026 22:16:08 +0900 Subject: [PATCH] update:code shift --- nvim/lua/plugins/catppuccin.lua | 2 +- nvim/lua/plugins/lsp.lua | 79 +++++++-------------------------- nvim/lua/plugins/lsp_tools.lua | 46 +++++++++++++++++++ nvim/lua/plugins/mini.lua | 6 --- nvim/lua/plugins/ui.lua | 2 +- nvim/lua/utils/mason.lua | 31 +++++++++++++ nvim/nvim-pack-lock.json | 4 ++ 7 files changed, 98 insertions(+), 72 deletions(-) create mode 100644 nvim/lua/plugins/lsp_tools.lua create mode 100644 nvim/lua/utils/mason.lua diff --git a/nvim/lua/plugins/catppuccin.lua b/nvim/lua/plugins/catppuccin.lua index d607cde..bc86c57 100644 --- a/nvim/lua/plugins/catppuccin.lua +++ b/nvim/lua/plugins/catppuccin.lua @@ -30,7 +30,7 @@ local function apply_theme_overrides() end function M.setup() - pack.add({ "catppuccin", "nvim-web-devicons" }) + pack.add({ "catppuccin" }) local theme_group = vim.api.nvim_create_augroup("UserThemeTweaks", { clear = true }) vim.api.nvim_create_autocmd("ColorScheme", { diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index 8d106ad..e083c32 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -1,25 +1,8 @@ local M = {} local pack = require("utils.pack") - -local tools = { - { kind = "lsp", lsp = "lua_ls", mason = "lua-language-server" }, - { kind = "lsp", lsp = "bashls", mason = "bash-language-server" }, - { kind = "lsp", lsp = "astro", mason = "astro-language-server" }, - { kind = "lsp", lsp = "tailwindcss", mason = "tailwindcss-language-server" }, - { kind = "lsp", lsp = "ts_ls", mason = "typescript-language-server" }, - { kind = "lsp", lsp = "html", mason = "html-lsp" }, - { kind = "lsp", lsp = "pyright", mason = "pyright" }, - { kind = "lsp", lsp = "templ", mason = "templ" }, - { kind = "lsp", lsp = "gopls", mason = "gopls" }, - { kind = "lsp", lsp = "emmet_ls", mason = "emmet-language-server" }, - { kind = "lsp", lsp = "rust_analyzer", mason = "rust-analyzer" }, - { kind = "formatter", mason = "stylua", ft = { "lua" } }, - { kind = "formatter", mason = "shfmt", ft = { "sh", "bash" } }, - { kind = "formatter", mason = "isort", ft = { "python" } }, - { kind = "formatter", mason = "black", ft = { "python" } }, - { kind = "formatter", mason = "prettierd", ft = { "javascript", "typescript", "astro", "html", "css", "json", "jsonc" } }, -} +local mason_utils = require("utils.mason") +local lsp_tools = require("plugins.lsp_tools") function M.setup() pack.add({ "mason", "nvim-lspconfig", "conform" }) @@ -42,7 +25,16 @@ function M.setup() }, }, }, - filetypes = { "htmldjango", "templ", "html", "css", "javascript", "typescript", "jsx", "tsx" }, + filetypes = { + "htmldjango", + "templ", + "html", + "css", + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + }, }) vim.lsp.config("html", { filetypes = { "html", "htmldjango", "templ" } }) vim.lsp.config("lua_ls", { @@ -56,58 +48,17 @@ function M.setup() }, }) - local lsp_names = {} - for _, t in ipairs(tools) do - if t.kind == "lsp" then - table.insert(lsp_names, t.lsp) - end - end - vim.lsp.enable(lsp_names) + vim.lsp.enable(lsp_tools.lsp_names()) require("conform").setup({ - formatters_by_ft = { - lua = { "stylua" }, - sh = { "shfmt" }, - bash = { "shfmt" }, - python = { "isort", "black" }, - javascript = { "prettierd" }, - typescript = { "prettierd" }, - astro = { "prettierd" }, - html = { "prettierd" }, - css = { "prettierd" }, - json = { "prettierd" }, - jsonc = { "prettierd" }, - }, + formatters_by_ft = lsp_tools.formatters_by_ft(), }) vim.keymap.set("n", "F", function() require("conform").format({ async = true, lsp_fallback = true }) end, { desc = "Format buffer" }) - vim.api.nvim_create_user_command("MasonInstallDefaults", function() - local registry = require("mason-registry") - registry.refresh(function() - local seen, to_install = {}, {} - for _, t in ipairs(tools) do - if t.mason and not seen[t.mason] then - seen[t.mason] = true - local ok, pkg = pcall(registry.get_package, t.mason) - if ok and not pkg:is_installed() then - table.insert(to_install, pkg) - end - end - end - - if #to_install == 0 then - vim.notify("MasonInstallDefaults: all tools already installed", vim.log.levels.INFO) - return - end - for _, pkg in ipairs(to_install) do - pkg:install() - end - vim.notify(("MasonInstallDefaults: installing %d tool(s)"):format(#to_install), vim.log.levels.INFO) - end) - end, { desc = "Install missing Mason tools from `tools` table" }) + mason_utils.setup_install_defaults_command(lsp_tools.tools) vim.diagnostic.config({ virtual_text = false }) diff --git a/nvim/lua/plugins/lsp_tools.lua b/nvim/lua/plugins/lsp_tools.lua new file mode 100644 index 0000000..d2d2a75 --- /dev/null +++ b/nvim/lua/plugins/lsp_tools.lua @@ -0,0 +1,46 @@ +local M = {} + +M.tools = { + { kind = "lsp", lsp = "lua_ls", mason = "lua-language-server" }, + { kind = "lsp", lsp = "bashls", mason = "bash-language-server" }, + { kind = "lsp", lsp = "astro", mason = "astro-language-server" }, + { kind = "lsp", lsp = "tailwindcss", mason = "tailwindcss-language-server" }, + { kind = "lsp", lsp = "ts_ls", mason = "typescript-language-server" }, + { kind = "lsp", lsp = "html", mason = "html-lsp" }, + { kind = "lsp", lsp = "pyright", mason = "pyright" }, + { kind = "lsp", lsp = "templ", mason = "templ" }, + { kind = "lsp", lsp = "gopls", mason = "gopls" }, + { kind = "lsp", lsp = "emmet_ls", mason = "emmet-language-server" }, + { kind = "lsp", lsp = "rust_analyzer", mason = "rust-analyzer" }, + { kind = "formatter", mason = "stylua", ft = { "lua" } }, + { kind = "formatter", mason = "shfmt", ft = { "sh", "bash" } }, + { kind = "formatter", mason = "isort", ft = { "python" } }, + { kind = "formatter", mason = "black", ft = { "python" } }, + { kind = "formatter", mason = "prettierd", ft = { "javascript", "typescript", "astro", "html", "css", "json", "jsonc" } }, +} + +function M.lsp_names() + local names = {} + for _, tool in ipairs(M.tools) do + if tool.kind == "lsp" then + table.insert(names, tool.lsp) + end + end + return names +end + +function M.formatters_by_ft() + local by_ft = {} + for _, tool in ipairs(M.tools) do + if tool.kind == "formatter" and tool.ft then + local formatter = tool.conform or tool.mason + for _, ft in ipairs(tool.ft) do + by_ft[ft] = by_ft[ft] or {} + table.insert(by_ft[ft], formatter) + end + end + end + return by_ft +end + +return M diff --git a/nvim/lua/plugins/mini.lua b/nvim/lua/plugins/mini.lua index bc6c7c4..5583cee 100644 --- a/nvim/lua/plugins/mini.lua +++ b/nvim/lua/plugins/mini.lua @@ -9,12 +9,6 @@ function M.setup() options = { custom_commentstring = function() local ft = vim.bo.filetype - if ft == "typescriptreact" then - return "{/* %s */}" - end - if ft == "htmldjango" then - return "{# %s #}" - end if ft == "templ" then return "// %s" end diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua index 7d27514..74e2426 100644 --- a/nvim/lua/plugins/ui.lua +++ b/nvim/lua/plugins/ui.lua @@ -3,7 +3,7 @@ local M = {} local pack = require("utils.pack") function M.setup() - pack.add({ "indent-blankline.nvim", "lualine.nvim", "bufferline.nvim" }) + pack.add({ "nvim-web-devicons", "indent-blankline.nvim", "lualine.nvim", "bufferline.nvim" }) require("ibl").setup({ indent = { char = "▏" }, diff --git a/nvim/lua/utils/mason.lua b/nvim/lua/utils/mason.lua new file mode 100644 index 0000000..e743480 --- /dev/null +++ b/nvim/lua/utils/mason.lua @@ -0,0 +1,31 @@ +local M = {} + +function M.setup_install_defaults_command(tools) + pcall(vim.api.nvim_del_user_command, "MasonInstallDefaults") + vim.api.nvim_create_user_command("MasonInstallDefaults", function() + local registry = require("mason-registry") + registry.refresh(function() + local seen, to_install = {}, {} + for _, tool in ipairs(tools) do + if tool.mason and not seen[tool.mason] then + seen[tool.mason] = true + local ok, pkg = pcall(registry.get_package, tool.mason) + if ok and not pkg:is_installed() then + table.insert(to_install, pkg) + end + end + end + + if #to_install == 0 then + vim.notify("MasonInstallDefaults: all tools already installed", vim.log.levels.INFO) + return + end + for _, pkg in ipairs(to_install) do + pkg:install() + end + vim.notify(("MasonInstallDefaults: installing %d tool(s)"):format(#to_install), vim.log.levels.INFO) + end) + end, { desc = "Install missing Mason tools from tool registry" }) +end + +return M diff --git a/nvim/nvim-pack-lock.json b/nvim/nvim-pack-lock.json index 69e9ca2..6d37d0b 100644 --- a/nvim/nvim-pack-lock.json +++ b/nvim/nvim-pack-lock.json @@ -68,6 +68,10 @@ "rev": "4916d6592ede8c07973490d9322f187e07dfefac", "src": "https://github.com/nvim-treesitter/nvim-treesitter" }, + "nvim-ts-autotag": { + "rev": "8e1c0a389f20bf7f5b0dd0e00306c1247bda2595", + "src": "https://github.com/windwp/nvim-ts-autotag" + }, "nvim-web-devicons": { "rev": "c72328a5494b4502947a022fe69c0c47e53b6aa6", "src": "https://github.com/nvim-tree/nvim-web-devicons"