-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtreesitter-config.lua
More file actions
61 lines (53 loc) · 1.85 KB
/
treesitter-config.lua
File metadata and controls
61 lines (53 loc) · 1.85 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
local M = {
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
branch = 'main',
event = 'BufEnter',
dependencies = {
{ 'nvim-treesitter/nvim-treesitter-context', opts = { zindex = 5, max_lines = 3 } },
{ 'folke/ts-comments.nvim', opts = true },
},
}
M.config = function()
local ensure_installed = {
'regex',
'lua',
'vim',
'vimdoc',
'markdown',
'markdown_inline',
'bash',
'nu',
'yaml',
'tsx',
'javascript',
'css',
'scss',
'latex',
}
require('nvim-treesitter').install(ensure_installed)
-- NOTE: extra parser register if filetype not matched
-- vim.treesitter.language.register('ini', { 'dosini', 'confini' }) -- supported
vim.api.nvim_create_autocmd('FileType', {
group = vim.api.nvim_create_augroup('treesitter.setup', {}),
callback = function(args)
local buf = args.buf
local filetype = args.match
-- you need some mechanism to avoid running on buffers that do not
-- correspond to a language (like oil.nvim buffers), this implementation
-- checks if a parser exists for the current language
local language = vim.treesitter.language.get_lang(filetype) or filetype
if not vim.treesitter.language.add(language) then
return
end
-- replicate `fold = { enable = true }`
vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
-- replicate `highlight = { enable = true }`
vim.treesitter.start(buf, language)
-- replicate `indent = { enable = true }`
vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
end
return M