emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
815 stars 73 forks source link

tsc-lang-abi-too-new when installing new language #247

Open leotrs opened 1 year ago

leotrs commented 1 year ago

I have a tree-sitter parser that I'm trying to add to emacs-tree-sitter. However, when running (tree-sitter-require 'rsm), I get the following error ("rsm" is the name of my language):

Debugger entered--Lisp error: (tsc-lang-abi-too-new 14 (13 . 13) "/home/leo/.tree-sitter/bin/rsm.so")
  tsc--load-language("/home/leo/.tree-sitter/bin/rsm.so" "tree_sitter_rsm" rsm)
  (let ((language (tsc--load-language full-path native-symbol-name lang-symbol))) (let* ((key lang-symbol) (v language)) (condition-case nil (with-no-warnings (map-put! tree-sitter-languages key v nil)) (map-not-inplace (setq tree-sitter-languages (map-insert tree-sitter-languages key v)) v))) language)
  (let* ((lang-name (symbol-name lang-symbol)) (fallback-name (replace-regexp-in-string "-" "_" lang-name)) (native-symbol-name (or native-symbol-name (format "tree_sitter_%s" fallback-name))) (files (if file (list file) (cons lang-name (if (string= lang-name fallback-name) nil (list fallback-name))))) (full-path (seq-some #'(lambda (base-name) (locate-file base-name tree-sitter-load-path tree-sitter-load-suffixes)) files))) (if full-path nil (error "Cannot find shared library for language: %S" lang-symbol)) (let ((language (tsc--load-language full-path native-symbol-name lang-symbol))) (let* ((key lang-symbol) (v language)) (condition-case nil (with-no-warnings (map-put! tree-sitter-languages key v nil)) (map-not-inplace (setq tree-sitter-languages (map-insert tree-sitter-languages key v)) v))) language))
  tree-sitter-load(rsm nil nil)
  (or (alist-get lang-symbol tree-sitter-languages) (tree-sitter-load lang-symbol file native-symbol-name))
  tree-sitter-require(rsm)
  (progn (tree-sitter-require 'rsm))
  elisp--eval-last-sexp(t)
  eval-last-sexp(t)
  eval-print-last-sexp(nil)
  funcall-interactively(eval-print-last-sexp nil)
  command-execute(eval-print-last-sexp)

The only other mention of this error tsc-lang-abi-too-new is here. Following that comment, I downgraded tree-sitter-cli from 0.20 to 0.19.5, and that fixed the issue.

Is there any reason why emacs won't load parsers generated with cli-v0.20? Can we expect this to be solved in the next release? Thanks.

sogaiu commented 1 year ago

May be it has to do with:

Note: versions 0.20+ cannot be used, as they introduce a breaking change in binary storage location

References

leotrs commented 1 year ago

Thanks for the references.

As far as I can tell, one major change was moving some files from ~/.tree-sitter/ to ~/.config/tree-sitter/. Is this the main reason 0.20 is not yet supported?

sogaiu commented 1 year ago

I haven't wrapped my head around the details.

I suspect that @ubolonton and/or @ethan-leba (participants of https://github.com/emacs-tree-sitter/tree-sitter-langs/issues/80) might know though.

ethan-leba commented 1 year ago

As far as I understand it, the issue is exactly what is says on the tin. In the commit https://github.com/tree-sitter/tree-sitter/commit/eaf9b170f1abd79f0a1b39cffbaa580910918205 (v0.20.7), they make a breaking change to the ABI, bumping it to v14. However emacs-tree-sitter depends on tree-sitter v0.20.0, which only supports up to v13. Note that you can use the --abi flag to lower the ABI version to 13 without downgrading TS.

leotrs commented 1 year ago

Note that you can use the --abi flag to lower the ABI version to 13 without downgrading TS.

Ooooh that's a good one!

sogaiu commented 1 year ago

TIL!

leotrs commented 1 year ago

As far as I understand it, the issue is exactly what is says on the tin. In the commit tree-sitter/tree-sitter@eaf9b17 (v0.20.7), they make a breaking change to the ABI, bumping it to v14. However emacs-tree-sitter depends on tree-sitter v0.20.0, which only supports up to v13. Note that you can use the --abi flag to lower the ABI version to 13 without downgrading TS.

So is it just a matter of figuring out why emacs-tree-sitter depends on v0.20.0? I gather that the location of shared libraries is one such reason. Are there other known problems?

ethan-leba commented 1 year ago

I think the overarching issue here is that development has frozen on this project. Especially now that tree sitter is integrated into Emacs 29, there doesn't seem much of a reason to put any further work into this package.

leotrs commented 1 year ago

Ah. Well that makes sense. Thanks for all the hard work!

Nebucatnetzer commented 1 year ago

Is there a variable where one can add the flag?

snowman commented 1 year ago

Is there a variable where one can add the flag?

$ tree-sitter --version
tree-sitter 0.20.8

$ git clone https://github.com/casouri/tree-sitter-module
$ cd tree-sitter-module
# modify build.sh, add below lines after 'git clone "https://github.com/${org}/${repo}.git"', and comment out `rm -rf "${lang}"`
cd elisp
tree-sitter generate --abi 13 src/grammar.json
cd ..

# then run
$ ./build.sh elisp

You should modify tree-sitter-langs--init-major-mode-alist in tree-sitter-langs.el by add (emacs-lisp-mode . elisp) to support emacs lisp mode.

Copy dist/libtree-sitter-elisp.so to tree-sitter-langs/bin/elisp.so