Skip to content

bug: Treesitter artefact install dir gets removed from runtimepath on bootstrap #2153

Description

@ivanisakov99

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.12.1

Operating system/version

MacOS 25.4.1

Describe the bug

During initial bootstrap of the configs, lazy seems to remove the vim.fn.stdpath("data") .. "/site" directory from the runtimepath, even though it gets set explicitly. Given that the /site subdirectory might not exist during the bootstrap phase, it will get populated when nvim-treesitter plugin gets loaded and downloads parsers.

This causes cascading issues since, at that time, neovim is unaware of the newly installed parsers, due to being missing from rtp, and fails to start treesitter when a matching filetype is opened because parsers aren't located.

Note

This all happens within the initial/first session of neovim. This gets fixed once one closes and re-opens a new session, since the /site directory is now populated.

Code

It seems that the following line is the one that's corrupting the rtp (due to the implementation omitting empty directories):

local rtp = vim.api.nvim_get_runtime_file("", true)

RTP after Error

nvim/runtime,/nix/store/ymyc1pa4rgqv308l19di15rqcsv4fiz3-neovim-unwrapped-0.12.1/share/nvim/runtime/pack/dist/opt/netrw,/nix/store/ymyc1pa4rgqv308l19di15rqcsv4fiz3-neovim-unwrapped-0.12.1/share/nvim/runtime/pack/dist/opt/matchit,/nix/store/ymyc1pa4rgqv308l19di15
rqcsv4fiz3-neovim-unwrapped-0.12.1/lib/nvim

Steps To Reproduce

Example with bash parser:

  1. echo '# vim: filetype=bash' > test.sh (This will allow the filetype to be properly set to bash)
  2. nvim -u repro.lua test.sh
  3. Should see a classic treesitter error to appear:
Error in BufReadPost Autocommands for "*":
Lua callback: ...-neovim-unwrapped-0.12.1/share/nvim/runtime/filetype.lua:28: BufReadPost Autocommands for "*"..FileType Autocommands for "*": Vim(append):Lua callback: ...wrapped-0.12.1/share/nvim/runtime/lua/vim/treesitter.lua:449: Parser could not be created
for buffer 1 and language "bash"
stack traceback:
...

Expected Behavior

The new treesitter parser directory at vim.fn.stdpath("data") .. "/site" gets added here, if options.performance.rtp.reset option is true. And should persist after plugins are loaded and configured, so that treesitter can start highlights, etc. (without having to reopen a new session).

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    {
      "nvim-treesitter/nvim-treesitter",
      build = ":TSUpdate",
      lazy = false,
      config = function()
        require("nvim-treesitter").install("bash"):wait()

        local augroup = vim.api.nvim_create_augroup("TreesitterSetup", { clear = true })
        vim.api.nvim_create_autocmd("FileType", {
          group = augroup,
          callback = function(event)
            local lang = vim.treesitter.language.get_lang(event.match)
            if lang ~= "bash" then
              return
            end
            vim.treesitter.start(event.buf, lang)
          end,
        })
      end,
    },
  },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions