NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.66k stars 13.11k forks source link

emacsPackages.tree-sitter-langs: Python grammar uses incompatible ABI version #209114

Open mcwitt opened 1 year ago

mcwitt commented 1 year ago

Describe the bug

Trying to use elisp-tree-sitter in Python buffers fails with the following error:

Language’s ABI is too new: 14, (13 . 13), "/nix/store/y5yzbhx8k4c5svc86aq9mrmljqciijbj-emacs-tree-sitter-grammars/langs/bin/python.so"

Steps To Reproduce

Steps to reproduce the behavior:

nix-shell -I nixpkgs=. -p 'emacsWithPackages (ps: with ps; [ tree-sitter tree-sitter-langs ])' --run "emacs -Q"

Execute the elisp commands:

(require 'tree-sitter)
(require 'tree-sitter-langs)

Finally, open a Python buffer and do M-x tree-sitter-hl-mode to reproduce the above error.

Expected behavior

elisp-tree-sitter should work in Python buffers. (This issue does not occur with Haskell or Nix buffers, for example).

Additional context

The cause seems to be that the upstream https://github.com/tree-sitter/tree-sitter-python generated the parser using ABI version 14 (which is now the default, since https://github.com/tree-sitter/tree-sitter/commit/e2fe380a08408ff42eada21f8723f653e6da6606), but elisp-tree-sitter does not support this since it uses an older tree-sitter version.

I'm able to work around this with the following nixpkgs overlay:

final: prev:
{
  tree-sitter-grammars = prev.tree-sitter-grammars // {
    tree-sitter-python = prev.tree-sitter-grammars.tree-sitter-python.overrideAttrs (_: {
      nativeBuildInputs = [ final.nodejs final.tree-sitter ];
      configurePhase = ''
        tree-sitter generate --abi 13 src/grammar.json
      '';
    });
  };
}

Related issue: https://github.com/emacs-tree-sitter/elisp-tree-sitter/issues/247

Notify maintainers

@pimeys , @adisbladis

Metadata

clhodapp commented 1 year ago

I'll raise that it seems like this comment is relevant to this situation: https://github.com/NixOS/nixpkgs/pull/230547#issuecomment-1537545156

xinyifly commented 1 year ago

I think this can be solved more or less by installing emacs29 and using built-in treesit now.

nixos-discourse commented 4 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tree-sitter-grammars-collide-with-each-other/41805/10