nvim/lua/treesitter.lua
xfy 2c524fc30d Refactor lazy loading: unify treesitter/LSP deferral via lazy.on_event
- Move VimEnter autocmd from init.lua to pack.lua using lazy.on_event
- Convert treesitter.lua to modular M.setup() pattern
- Simplify lsp.lua: remove redundant comment, inline diagnostic config
- Reorganize pack.lua: group finders, add fugitive keymaps, adjust header indent

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-28 15:07:01 +08:00

60 lines
1.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local M = {}
local ensure_installed = {
"lua",
"vim",
"vimdoc",
-- Web
"javascript",
"typescript",
"tsx",
"jsdoc",
"json",
"html",
"css",
"yaml",
-- Backend
"c",
"rust",
"toml",
"go",
"gomod",
"gosum",
"gowork",
-- Infra
"dockerfile",
"make",
}
M.setup = function()
vim.cmd.packadd("nvim-treesitter")
local treesitter = require("nvim-treesitter")
-- 延迟安装 parser避免阻塞
vim.defer_fn(function()
treesitter.install(ensure_installed)
end, 100)
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function(args)
local buf = args.buf
local ft = vim.bo[buf].filetype
local lang = vim.treesitter.language.get_lang(ft)
if not lang then
return
end
local ok_add = pcall(vim.treesitter.language.add, lang)
if not ok_add then
return
end
pcall(vim.treesitter.start, buf, lang)
end,
})
end
return M