Xinqi Bao's Git

4d17d51e464ea73b01a83ccf37fe8a6dcf6a7598
[dotfiles.git] / .config / nvim / lua / plugin-config / nvim-treesitter.lua
1 local treesitter = require('nvim-treesitter')
2
3 treesitter.setup {
4 install_dir = vim.fn.stdpath('data') .. '/site',
5 }
6
7 treesitter.install {
8 'bash',
9 'c',
10 'cmake',
11 'cpp',
12 'json',
13 'lua',
14 'markdown',
15 'markdown_inline',
16 'python',
17 'query',
18 'toml',
19 'vim',
20 'vimdoc',
21 'yaml',
22 }
23
24 local function enable(buf)
25 if not pcall(vim.treesitter.start, buf) then
26 return
27 end
28
29 vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
30 vim.wo[0][0].foldmethod = 'expr'
31 end
32
33 vim.api.nvim_create_autocmd('FileType', {
34 callback = function(args) enable(args.buf) end,
35 })
36
37 -- Startup filetype detection can precede this config being sourced.
38 if vim.bo.filetype ~= '' then
39 enable(0)
40 end