Skip to content

Commit deac8c7

Browse files
committed
Adopt new treesitter in nvim
1 parent 50dd96f commit deac8c7

2 files changed

Lines changed: 83 additions & 67 deletions

File tree

config/common/.config/nvim/lazy-lock.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"nvim-cmp": { "branch": "main", "commit": "a1d504892f2bc56c2e79b65c6faded2fd21f3eca" },
1717
"nvim-lightbulb": { "branch": "master", "commit": "e974b1a93c917c840545f51b9a66cfd72c520522" },
1818
"nvim-lspconfig": { "branch": "master", "commit": "a776085e04f7b15d0b59fae2244df07d98360ab4" },
19-
"nvim-treesitter": { "branch": "master", "commit": "cf12346a3414fa1b06af75c79faebe7f76df080a" },
20-
"nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" },
19+
"nvim-treesitter": { "branch": "main", "commit": "4916d6592ede8c07973490d9322f187e07dfefac" },
2120
"oil.nvim": { "branch": "master", "commit": "0fcc83805ad11cf714a949c98c605ed717e0b83e" },
2221
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
2322
"popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" },
Lines changed: 82 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,87 @@
1+
local ensure_installed = {
2+
'awk',
3+
'bash',
4+
'c',
5+
'cmake',
6+
'comment',
7+
'cpp',
8+
'css',
9+
'diff',
10+
'dockerfile',
11+
'fish',
12+
'git_config',
13+
'git_rebase',
14+
'gitattributes',
15+
'gitignore',
16+
'go',
17+
'gomod',
18+
'gosum',
19+
'gowork',
20+
'hcl',
21+
'html',
22+
'java',
23+
'javascript',
24+
'json',
25+
'jq',
26+
'kotlin',
27+
'lua',
28+
'luadoc',
29+
'make',
30+
'markdown',
31+
'ninja',
32+
'objc',
33+
'proto',
34+
'python',
35+
'regex',
36+
'ruby',
37+
'rust',
38+
'sql',
39+
'starlark',
40+
'sxhkdrc',
41+
'terraform',
42+
'toml',
43+
'typescript',
44+
'vim',
45+
'vimdoc',
46+
'yaml',
47+
}
48+
49+
local install_dir = vim.fn.stdpath('data') .. '/site'
50+
51+
local function setup_treesitter()
52+
local treesitter = require('nvim-treesitter')
53+
treesitter.setup({
54+
install_dir = install_dir,
55+
})
56+
57+
treesitter.install(ensure_installed)
58+
59+
-- Use existing parsers for custom filetypes.
60+
vim.treesitter.language.register('starlark', { 'tiltfile' })
61+
vim.treesitter.language.register('ruby', { 'brewfile' })
62+
63+
vim.api.nvim_create_autocmd('FileType', {
64+
group = vim.api.nvim_create_augroup('TreesitterHighlight', { clear = true }),
65+
callback = function(args)
66+
pcall(vim.treesitter.start, args.buf)
67+
end,
68+
})
69+
end
70+
71+
local function update_treesitter()
72+
local treesitter = require('nvim-treesitter')
73+
treesitter.setup({
74+
install_dir = install_dir,
75+
})
76+
treesitter.install(ensure_installed):wait(300000)
77+
end
78+
179
return {
280
{
381
'nvim-treesitter/nvim-treesitter',
4-
config = function()
5-
require('nvim-treesitter.configs').setup({
6-
ensure_installed = {
7-
'awk',
8-
'bash',
9-
'c',
10-
'cmake',
11-
'comment',
12-
'cpp',
13-
'css',
14-
'diff',
15-
'dockerfile',
16-
'fish',
17-
'git_config',
18-
'git_rebase',
19-
'gitattributes',
20-
'gitignore',
21-
'go',
22-
'gomod',
23-
'gosum',
24-
'gowork',
25-
'hcl',
26-
'html',
27-
'java',
28-
'javascript',
29-
'json',
30-
'jq',
31-
'kotlin',
32-
'lua',
33-
'luadoc',
34-
'make',
35-
'markdown',
36-
'ninja',
37-
'objc',
38-
'proto',
39-
'python',
40-
'regex',
41-
'ruby',
42-
'rust',
43-
'sql',
44-
'starlark',
45-
'sxhkdrc',
46-
'terraform',
47-
'toml',
48-
'typescript',
49-
'vim',
50-
'vimdoc',
51-
'yaml',
52-
},
53-
highlight = {
54-
enable = true,
55-
additional_vim_regex_highlighting = false,
56-
},
57-
})
58-
59-
-- Use the starlark config for custom filetype
60-
vim.treesitter.language.register('starlark', { 'tiltfile' })
61-
vim.treesitter.language.register('ruby', { 'brewfile' })
62-
end,
63-
build = function()
64-
pcall(require('nvim-treesitter.install').update({ with_sync = true }))
65-
end,
66-
dependencies = {
67-
'nvim-treesitter/nvim-treesitter-textobjects',
68-
},
82+
branch = 'main',
83+
lazy = false,
84+
config = setup_treesitter,
85+
build = update_treesitter,
6986
},
7087
}

0 commit comments

Comments
 (0)