update:code shift

This commit is contained in:
2026-04-13 22:16:08 +09:00
parent 429b561ff4
commit 2bd4cc0098
7 changed files with 98 additions and 72 deletions

View File

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

View File

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

View File

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

View File

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

View File

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