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
|
-- Treesitter adds understanding of the source code text
-- (e.g. fields, methods, classes). nvim has built-in support
-- for tree-sitter, however, nvim-treesitter makes it easier
-- to automatically install tree-sitter parser files for each
-- language.
vim.api.nvim_create_autocmd('PackChanged', {
callback = function(event)
local name, kind = event.data.spec.name, event.data.kind
if name == 'nvim-treesitter' and (kind == 'update' or kind == 'install') then
vim.schedule(function()
-- If nvim-treesitter was updated, run ':TSUpdate' to
-- ensure the installed parsers are also updated.
vim.cmd 'TSUpdate all'
end)
end
end,
})
vim.pack.add {
{
name = 'nvim-treesitter',
src = 'https://github.com/nvim-treesitter/nvim-treesitter',
version = 'main',
},
{
name = 'nvim-treesitter-context',
src = 'https://github.com/nvim-treesitter/nvim-treesitter-context',
},
}
local langs = {
'bash',
'c',
'commonlisp',
'css',
'hcl',
'html',
'javascript',
'json',
'lua',
'make',
'python',
'sh',
'sql',
'tsx',
'typescript',
'yaml',
}
require 'nvim-treesitter'.install { ensure_installed = langs }
vim.api.nvim_create_autocmd('FileType', {
pattern = langs,
callback = function()
vim.treesitter.start()
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
require('treesitter-context').setup { multiline_threshold = 10}
|