Skip to content

[BUG] <BUG> Configuring treesitter grammars in conjunction with the home manager module causes incompatible tree-sitter queries (not from nvim-treesitter) to be loaded #4208

@NickHu

Description

@NickHu

Plugin

nvim-treesitter

Nixpkgs Release

unstable

Home Manager Release

unstable

I have read the FAQ

  • I have read the FAQ and my bug is not listed there.

Description

The nvim-treesitter plugin presumes that you do not use queries from upstream treesitter grammars, only parsers, and supplies its own queries.
Since the move to the main branch, if you try to use upstream queries you will definitely run into issues.
One such is that highlighting will break in nix files if you use the upstream query (not updated for 3 years) from https://github.com/nix-community/tree-sitter-nix, with constant error messages which are effectively undismissable.

Upstream parsers+queries are supplied in attributes like nixpkgs#tree-sitter-grammars.tree-sitter-nix; when the treesitter module in nixvim is configured, it is supposed to take the parsers from these packages and use the queries from nvim-treesitter, bundling it all together with some symlink join machinery in a nvim-treesitter-grammars directory.

Nixvim generates the packdir which contains this directory as pack/myNeovimPackages/start/nvim-treesitter-grammars/ (see :set packpath?).
When you configure plugins.treesitter.grammarPackages to include a custom treesitter grammar, as in the documentation, this machinery somehow breaks down and starts bundling the (broken) upstream queries in this directory instead of the ones from nvim-treesitter.

Here are the md5sums of the good and bad queries for nix highlighting.

899de2fbc2a749d339c397bf34a33745  queries/nix/highlights.scm # GOOD, comes from nvim-treesitter
53f4ea999ef677f6546b9f1ae7e77450  queries/nix/highlights.scm # BAD, comes from tree-sitter-nix

This does not happen if you use nixvim in standalone mode, which instead works properly (queries from nvim-treesitter are used), which boggles the mind (I cannot figure out why this is affecting the behaviour of the symlink join which generates nvim-treesitter-grammars in the packdir).

It also only seems to be happening on Linux, and not on darwin, which is again mind-boggling.

Minimal, Reproducible Example (MRE)

programs.nixvim = {
    enable = true;
    defaultEditor = true;
    plugins.treesitter =
      let
        treesitter-nu-grammar = pkgs.tree-sitter.buildGrammar {
          language = "nu";
          version = "0.0.0+rev=0bb9a60";
          src = pkgs.fetchFromGitHub {
            owner = "nushell";
            repo = "tree-sitter-nu";
            rev = "0bb9a602d9bc94b66fab96ce51d46a5a227ab76c";
            hash = "sha256-A5GiOpITOv3H0wytCv6t43buQ8IzxEXrk3gTlOrO0K0=";
          };
          meta.homepage = "https://github.com/nushell/tree-sitter-nu";
        };
      in
      {
        enable = true;
        grammarPackages = pkgs.vimPlugins.nvim-treesitter.allGrammars ++ [ treesitter-nu-grammar ];
        highlight.enable = true;
      };
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions