1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
---@param tbl table
---@return table
local tbl_uniq = function(tbl)
---@type table<string, boolean>
local added = {}
local res = {}
res = vim.tbl_filter(function(k)
if added[k] then
return false
end
added[k] = true
return true
end, tbl)
return res
end
return {
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
cmd = { "TSUpdateSync" },
event = { "BufReadPost", "BufNewFile" },
init = function()
vim.o.foldmethod = "expr"
vim.o.foldexpr = "nvim_treesitter#foldexpr()"
end,
opts = {
indent = { enable = true },
ensure_installed = { "query" },
ignore_install = {},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
-- disable for big files
disable = function(_, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats =
pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
},
query_linter = {
enable = true,
use_virtual_text = true,
lint_events = { "BufWrite", "CursorHold" },
},
},
config = function(_, opts)
if type(opts.ensure_installed) == "table" then
opts.ensure_installed = tbl_uniq(opts.ensure_installed)
end
require("nvim-treesitter.configs").setup(opts)
end,
},
}
|