Repository navigation
Expand file tree
/
Copy path02-treesitter.lua
More file actions
85 lines (78 loc) · 1.82 KB
/
Copy path02-treesitter.lua
File metadata and controls
85 lines (78 loc) · 1.82 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
vim.pack.add({
"https://github.com/nvim-treesitter/nvim-treesitter",
"https://github.com/nvim-treesitter/nvim-treesitter-context",
})
local ensure_installed = {
"bash",
"bibtex",
"c",
"cmake",
"comment",
"cpp",
"diff",
"dockerfile",
"fish",
"git_rebase",
"gitattributes",
"go",
"gomod",
"gowork",
"haskell",
"json",
"json5",
"latex",
"llvm",
"lua",
"make",
"markdown",
"markdown_inline",
"ninja",
"nix",
"perl",
"proto",
"python",
"rst",
"rust",
"sql",
"toml",
"vim",
"yaml",
"kdl",
"gn",
"typescript",
}
local treesitter = require("nvim-treesitter")
local sync_timeout_ms = 300000
vim.api.nvim_create_user_command("TSSyncParsers", function()
vim.notify("Syncing Tree-sitter parsers...", vim.log.levels.INFO)
local ok, result = pcall(function()
return treesitter.update(ensure_installed, { summary = true }):wait(sync_timeout_ms)
end)
if ok and result then
vim.notify("Tree-sitter parsers are up to date.", vim.log.levels.INFO)
else
vim.notify(
"Tree-sitter parser sync failed. Check :messages for details.",
vim.log.levels.ERROR
)
end
end, {
desc = "Install and update Tree-sitter parsers used by this config",
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function(args)
pcall(vim.treesitter.start, args.buf)
end,
})
vim.api.nvim_create_autocmd("PackChanged", {
callback = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if name == "nvim-treesitter" and kind == "update" then
if not ev.data.active then
vim.cmd.packadd("nvim-treesitter")
end
vim.cmd("TSUpdate")
end
end,
})