aboutsummaryrefslogtreecommitdiffstats
path: root/lua/simenandre/plugins/treesitter.lua
diff options
context:
space:
mode:
authorSimen A. W. Olsen <hello@simenandre.no>2026-10-08 10:02:43 +0200
committerSimen A. W. Olsen <hello@simenandre.no>2026-10-08 10:02:43 +0200
commitd85d183b35f69c74e1bc5f23fe43c787497f398c (patch)
tree90eea60c7c54dd407b2fba35c1199f066545bf44 /lua/simenandre/plugins/treesitter.lua
parentb6dda087fc86e78e589785a65c61fca23dc383f0 (diff)
downloadconfig.nvim-main.tar.gz
config.nvim-main.zip
fix: migrate treesitter to main branch and tidy configHEADmain
nvim-treesitter master is archived and its queries crash on Neovim 0.12. Move lazy-lock.json to stdpath(state) since the config dir is read-only.
Diffstat (limited to 'lua/simenandre/plugins/treesitter.lua')
-rw-r--r--lua/simenandre/plugins/treesitter.lua100
1 files changed, 59 insertions, 41 deletions
diff --git a/lua/simenandre/plugins/treesitter.lua b/lua/simenandre/plugins/treesitter.lua
index 77f617d..1eb9080 100644
--- a/lua/simenandre/plugins/treesitter.lua
+++ b/lua/simenandre/plugins/treesitter.lua
@@ -1,48 +1,66 @@
+local ensure_installed = {
+ "astro",
+ "bash",
+ "c",
+ "css",
+ "diff",
+ "gitcommit",
+ "gitignore",
+ "go",
+ "html",
+ "javascript",
+ "json",
+ "lua",
+ "luadoc",
+ "markdown",
+ "markdown_inline",
+ "nix",
+ "query",
+ "rust",
+ "ssh_config",
+ "toml",
+ "tsx",
+ "typescript",
+ "vim",
+ "vimdoc",
+ "yaml",
+ "zig",
+}
+
+local function start(buf, lang)
+ if not pcall(vim.treesitter.start, buf, lang) then
+ return
+ end
+ vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
+end
+
return {
- { -- Highlight, edit, and navigate code
+ { -- Parsers and queries; highlighting itself is native (vim.treesitter.start)
"nvim-treesitter/nvim-treesitter",
+ branch = "main",
+ lazy = false,
build = ":TSUpdate",
- main = "nvim-treesitter.configs", -- Sets main module to use for opts
- -- [[ Configure Treesitter ]] See `:help nvim-treesitter`
config = function()
- require("nvim-treesitter.configs").setup({
- ensure_installed = {
- "bash",
- "ssh_config",
- "c",
- "diff",
- "html",
- "css",
- "gitcommit",
- "gitignore",
- "lua",
- "luadoc",
- "go",
- "json",
- "javascript",
- "rust",
- "zig",
- "yaml",
- "toml",
- "tsx",
- "typescript",
- "markdown",
- "markdown_inline",
- "query",
- "vim",
- "vimdoc",
- "astro",
- },
- -- Autoinstall languages that are not installed
- auto_install = true,
- highlight = {
- enable = true,
- -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
- -- If you are experiencing weird indenting issues, add the language to
- -- the list of additional_vim_regex_highlighting and disabled languages for indent.
- additional_vim_regex_highlighting = { "ruby" },
- },
- indent = { enable = true, disable = { "ruby" } },
+ local ts = require("nvim-treesitter")
+ ts.install(ensure_installed)
+
+ vim.api.nvim_create_autocmd("FileType", {
+ group = vim.api.nvim_create_augroup("treesitter-start", { clear = true }),
+ callback = function(args)
+ local lang = vim.treesitter.language.get_lang(args.match)
+ if not lang then
+ return
+ end
+ if vim.list_contains(ts.get_installed(), lang) then
+ start(args.buf, lang)
+ elseif vim.list_contains(ts.get_available(), lang) then
+ ts.install(lang):await(vim.schedule_wrap(function()
+ if vim.api.nvim_buf_is_valid(args.buf) then
+ start(args.buf, lang)
+ end
+ end))
+ end
+ end,
})
end,
},