nvim/lua/treesitter.lua
xfy 5d40b6c245 Defer heavy modules and disable built-in plugins to reduce startup time
- Disable unused built-in plugins at top of init.lua

- Defer treesitter and lsp to VimEnter

- Use packadd for on-demand plugin loading (conform, lspconfig, fugitive)

- Defer clipboard initialization to avoid provider check blocking

- Wrap LSP/diagnostic keymaps in functions to defer module loading

- Defer mini.icons setup to VimEnter

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

59 lines
1.2 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 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",
}
vim.api.nvim_create_autocmd("VimEnter", {
once = true,
callback = 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,
})