forge
Explore
Log in

Don't you dare go Hollow

Move treesitter to the new nvim-treesitter API

Browse files at this commit

e40e1f45d843507e010d52054bbe4d6dd7961c7aAhmet Kaan GümüşParent: 0257416
  • refactor
    • move treesitter to the new nvim-treesitter API
Show full message
♻️ refactor(nvim): move treesitter to the new nvim-treesitter API

The main branch dropped nvim-treesitter.configs. Start highlighting and
indent per buffer on FileType instead, installing a missing parser on
first use (the old auto_install behaviour).
.config/nvim/lua/plugins/nvim-treesitter.luamodified+30 -4
@@ -1,11 +1,37 @@
1 return {1 return {
2 "nvim-treesitter/nvim-treesitter",2 "nvim-treesitter/nvim-treesitter",
3+ lazy = false,
3 build = ":TSUpdate",4 build = ":TSUpdate",
4 config = function()5 config = function()
5- require("nvim-treesitter.configs").setup({6+ local ts = require("nvim-treesitter")
6- auto_install = true,7+ local available = {}
7- highlight = { enable = true },8+ for _, lang in ipairs(ts.get_available()) do
8- indent = { enable = true },9+ available[lang] = true
10+ end
11+
12+ local function enable(buf)
13+ if not vim.api.nvim_buf_is_valid(buf) or not pcall(vim.treesitter.start, buf) then
14+ return
15+ end
16+ vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
17+ end
18+
19+ vim.api.nvim_create_autocmd("FileType", {
20+ callback = function(args)
21+ local lang = vim.treesitter.language.get_lang(args.match)
22+ if not lang or not available[lang] then
23+ return
24+ end
25+ if vim.list_contains(ts.get_installed(), lang) then
26+ enable(args.buf)
27+ else
28+ ts.install(lang):await(function()
29+ vim.schedule(function()
30+ enable(args.buf)
31+ end)
32+ end)
33+ end
34+ end,
9 })35 })
10 end,36 end,
11 }37 }