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
|
return {
"nvim-treesitter/nvim-treesitter",
branch = "main",
build = ":TSUpdate",
config = function()
local parsers = {
"lua",
"vim",
"vimdoc",
"query",
"python",
"bash",
"yaml",
"hcl",
"terraform",
"html",
"css",
"javascript",
"typescript",
"tsx",
"json",
"markdown",
"markdown_inline",
}
-- The `main` branch shells out to the `tree-sitter` CLI to build every
-- parser. Without it every single parser fails the same way, which
-- floods :messages with one error per parser on every startup — check
-- once up front and give a single, actionable warning instead.
if vim.fn.executable("tree-sitter") == 0 then
vim.notify(
"nvim-treesitter: 'tree-sitter' CLI not found on PATH, parsers "
.. "won't build (e.g. `brew install tree-sitter-cli` or "
.. "`npm install -g tree-sitter-cli`), then :TSUpdate.",
vim.log.levels.WARN
)
else
local ok, err = pcall(function()
require("nvim-treesitter").install(parsers)
end)
if not ok then
vim.notify("nvim-treesitter: parser install failed: " .. tostring(err), vim.log.levels.WARN)
end
end
-- Enable highlighting for any buffer whose filetype has an installed
-- parser; vim.treesitter.start() is a no-op (caught by pcall) otherwise.
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function()
pcall(vim.treesitter.start)
end,
})
end,
}
|