fix(treesitter): nvim-treesitter crashes - #3404
Conversation
There was a problem hiding this comment.
Pull request overview
Updates NvChad’s nvim-treesitter integration to accommodate the upstream rewrite (which is incompatible with lazy-loading and removed legacy commands), aiming to prevent editor crashes and improve stability.
Changes:
- Switch
nvim-treesitterto eager loading (lazy = false) and replace legacycmd/event/buildusage with a Luabuildfunction. - Add a
confighook intended to applyinstall_dir. - Update the custom
:TSInstallAllcommand to use the new install API withsummary = trueand add a command description.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lua/nvchad/plugins/init.lua | Makes Treesitter eager and adds new build/config logic to install/update parsers. |
| lua/nvchad/autocmds.lua | Updates :TSInstallAll to install configured parsers using the new API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local spec = require("lazy.core.config").plugins["nvim-treesitter"] | ||
| local opts = type(spec.opts) == "table" and spec.opts or {} | ||
|
|
||
| if opts.install_dir then | ||
| ts.setup { install_dir = opts.install_dir } | ||
| end | ||
|
|
||
| if opts.ensure_installed then | ||
| ts.install(opts.ensure_installed, { summary = true }):wait(300000) |
There was a problem hiding this comment.
spec.opts for this plugin is configured as a function (see opts = function() ... end below), so type(spec.opts) == "table" will be false and opts becomes {}. That means opts.install_dir / opts.ensure_installed are never applied during build, so no parsers get installed/updated as intended. Consider resolving opts when it’s a function (e.g., call it) and falling back to {} only when nil/invalid.
| return require "nvchad.configs.treesitter" | ||
| end, | ||
| config = function(_, opts) | ||
| require("nvim-treesitter").setup { install_dir = opts.install_dir } |
There was a problem hiding this comment.
Defining config here overrides lazy.nvim’s default behavior of calling the plugin’s setup with the full opts table. As written, only install_dir is passed to setup, so other opts (e.g. ensure_installed from nvchad.configs.treesitter) are ignored at runtime. Adjust config to apply the full opts (or merge install_dir into opts before calling setup).
| require("nvim-treesitter").setup { install_dir = opts.install_dir } | |
| require("nvim-treesitter").setup(opts) |
| local spec = require("lazy.core.config").plugins["nvim-treesitter"] | ||
| local opts = type(spec.opts) == "table" and spec.opts or {} | ||
| require("nvim-treesitter").install(opts.ensure_installed) | ||
| end, {}) | ||
|
|
||
| if opts.ensure_installed then | ||
| require("nvim-treesitter").install(opts.ensure_installed, { summary = true }) | ||
| end |
There was a problem hiding this comment.
Same issue as in the plugin spec: spec.opts is a function in this repo, so type(spec.opts) == "table" results in opts = {} and opts.ensure_installed is always nil. This makes :TSInstallAll a no-op. Resolve spec.opts when it’s a function (call it) before reading ensure_installed.
nvim-treesitter main is now an incompatible rewrite and explicitly does not support lazy-loading. NvChad already migrated partially, but the plugin spec still lazy-loads treesitter and still references removed legacy commands.
also made treesitter loaded eagerly, which helps a lot in stability of the editor experience.