47 lines
1.5 KiB
Lua
47 lines
1.5 KiB
Lua
return {
|
||
{
|
||
-- 语法高亮:auto_install=true 自动装 parser,ignore_install 跳过 txt
|
||
'nvim-treesitter/nvim-treesitter',
|
||
config = function()
|
||
local treesitter_opt = {
|
||
indent = { enable = true },
|
||
ignore_install = {
|
||
"txt"
|
||
},
|
||
sync_install = false,
|
||
auto_install = true,
|
||
highlight = {
|
||
enable = true,
|
||
-- 大于 100KB 的文件关闭 treesitter 高亮(性能优化)
|
||
disable = function(_, buf)
|
||
local max_filesize = 100 * 1024 -- 100 KB
|
||
local ok, stats = pcall(G.loop.fs_stat, G.api.nvim_buf_get_name(buf))
|
||
if ok and stats and stats.size > max_filesize then
|
||
return true
|
||
end
|
||
end,
|
||
additional_vim_regex_highlighting = false,
|
||
},
|
||
-- 自定义 Vue parser:上游 tree-sitter-html 不识别 .vue 单文件组件
|
||
parsers = {
|
||
vue = {
|
||
install_info = {
|
||
url = "https://github.com/ikatyang/tree-sitter-vue",
|
||
files = { "src/parser.c" },
|
||
branch = "main",
|
||
},
|
||
},
|
||
},
|
||
}
|
||
require 'nvim-treesitter'.setup(treesitter_opt)
|
||
require 'nvim-treesitter.install'.prefer_git = true
|
||
if G.use_ssh then
|
||
local parsers = require 'nvim-treesitter.parsers'.get_parser_configs()
|
||
for _, p in pairs(parsers) do
|
||
p.install_info.url = p.install_info.url:gsub("https://github.com/", "git@github.com:")
|
||
end
|
||
end
|
||
end
|
||
},
|
||
}
|