Hi Xiyue,

Xiyue Deng <[email protected]> writes:

> Hi Loris,
>
> "Loris Bennett" <[email protected]> writes:
>
>> Hi Xiyue,
>>
>> Xiyue Deng <[email protected]> writes:
>>
>>> Hi Loris,
>>>
>>> "Loris Bennett" <[email protected]> writes:
>>>
>>>> Hi,
>>>>
>>>> I am on Debian 13 and am trying to install the Python language grammar for
>>>> tree sitter.  IIUC there is some ABI issue regarding the installed version 
>>>> of
>>>> libtree-sitter (on Debian 13: 0.22.6) and the version of the language 
>>>> grammar
>>>> one can install.
>>>>
>>>> However I have tried multiple versions of the grammar, from the very old to
>>>> the most recent and always get the error:
>>>>
>>>>   Warning (treesit): The installed language grammar for python cannot be 
>>>> located or has problems (version-mismatch): 15
>>>>
>>>> What am I doing wrong?
>>>>
>>>
>>> tree-sitter transitioned to ABI 15 since 0.23.x, which explains why you
>>> are seeing this issue on Trixie which has 0.22.6 as you've discovered.
>>> This would not be an issue if you regenerate everything in the language
>>> source code, but Emacs only cares about the generated parser code
>>> (usually src/parser.c and src/scanner.c), and if the release you use is
>>> generated using a newer tree-sitter you'll see this issue.
>>>
>>> A simple fix is to find the last release that was generated with
>>> tree-sitter on ABI 14.  For python, you can add the following to your
>>> init.el (I'm using boxquote and you can remove the prefixes using `M-x
>>> boxquote-unbox-region'):
>>>
>>> ,----[ tree-sitter-python for ABI 14 ]
>>> | (add-to-list 'treesit-language-source-alist
>>> |              `((python "https://github.com/tree-sitter/tree-sitter-python";
>>> |                        ,(if (< (treesit-library-abi-version) 15)
>>> |                             "v0.23.6"
>>> |                           "master"))))
>>> `----
>>>
>>> Hopefully we'll have some tree-sitter grammars shipped in Forky so that
>>> users can use the *-ts-mode without such hassle.
>>
>> Unfortunately the snippet above doesn't help.  I still get the version
>> mismatch error.  Even if I specify v0.23.6 explicitly when asked for the tag
>> or branch, an ABI 15 version of the grammar is still seems to be built.  I
>> even tried the oldest tag, v0.0.2, but still got the same error.
>>
>> I'm not sure what is going on.  The shared object files themselves certainly
>> seem to differ (I renamed the file generated with the tag v0.0.2):
>>
>>   [17:03:16] loris (2021) ~/.emacs.d.work/tree-sitter
>>   $ ll
>>   total 1236
>>   -rwxr-xr-x 1 loris users 777056 Feb 11 16:58 libtree-sitter-python.0.0.2.so
>>   -rwxr-xr-x 1 loris users 484112 Feb 11 17:01 libtree-sitter-python.so
>>
>> Any ideas?
>>
>
> If you have previously tried to compile a grammar library of ABI 15, it
> will produce a libtree-sitter-python.so anyway but fails to load in
> Emacs.  And after that, if you tried to compile a grammar library of ABI
> 14, it will show the same ABI mismatch error, but the produced
> libtree-sitter-python.so is actually correct and usable (at least this
> is what I observe on my Trixie system: I can enable python-ts-mode on a
> .py file just fine after this.)
>
> You can also try to remove the libtree-sitter-python.so file first,
> restart Emacs, and install the grammar again, which should then produce
> no errors.
>
> Let me know if any of these works (or not).

I started Emacs again this morning and now everything works.  Thanks!  It is
somewhat unfortunate that erroneous errors are produced (if indeed this is the
case), since the set-up for tree-sitter is already less straight forward than
it is for most Emacs packages.

However, yesterday enabling 'python-ts-mode' failed with the same version of
'libtree-sitter-python.so' that now worked, so maybe the restart is necessary.

I have a second laptop with essentially the same configuration where I want to
install tree-sitter, so I'll see whether the restart really is needed.

Cheers,

Loris

>> Cheers,
>>
>> Loris
>>
>>> P.S. For people using treesit-auto, I've been using a
>>> treesit-language-source-alist setting that should work with Trixie for
>>> most of the incompatible grammars that it supports.  Hope this is
>>> useful.
>>>
>>> Note: I have to fork some of the repos as Emacs doesn't seem to support
>>> checking out a specific commit and I need to create a branch for it to
>>> work.  Also tree-sitter-latex doesn't ship src/parser.c at all so I just
>>> regenerated the source code manually.  If you know of a better way to
>>> handle these do let me know :)
>>>
>>> ,----[ treesit-auto compatible settings for ABI 14 ]
>>> | (setq treesit-language-source-alist
>>> |       `((bash "https://github.com/tree-sitter/tree-sitter-bash";
>>> |               ,(if (< (treesit-library-abi-version) 15)
>>> |                    "v0.21.0"
>>> |                  "master"))
>>> |         (bibtex "https://github.com/manphiz/tree-sitter-bibtex";
>>> |                 ,(if (< (treesit-library-abi-version) 15)
>>> |                      "last-abi-14"
>>> |                    "master"))
>>> |         (c "https://github.com/tree-sitter/tree-sitter-c";
>>> |            ,(if (< (treesit-library-abi-version) 15)
>>> |                 "v0.23.1"
>>> |               "master"))
>>> |         (c-sharp "https://github.com/tree-sitter/tree-sitter-c-sharp";
>>> |                  ,(if (< (treesit-library-abi-version) 15)
>>> |                       "v0.21.3"
>>> |                     "master"))
>>> |         (css "https://github.com/tree-sitter/tree-sitter-css";
>>> |              ,(if (< (treesit-library-abi-version) 15)
>>> |                   "v0.21.1"
>>> |                 "master"))
>>> |         (go "https://github.com/tree-sitter/tree-sitter-go";
>>> |             ,(if (< (treesit-library-abi-version) 15)
>>> |                  "v0.21.2"
>>> |                "master"))
>>> |         (gomod "https://github.com/camdencheek/tree-sitter-go-mod";
>>> |                ,(if (< (treesit-library-abi-version) 15)
>>> |                     "v1.1.0"
>>> |                   "master"))
>>> |         (janet "https://github.com/manphiz/tree-sitter-janet";
>>> |                ,(if (< (treesit-library-abi-version) 15)
>>> |                     "last-abi-14"
>>> |                   "master"))
>>> |         (javascript 
>>> "https://github.com/tree-sitter/tree-sitter-javascript";
>>> |                     ,(if (< (treesit-library-abi-version) 15)
>>> |                          "v0.21.4"
>>> |                        "master"))
>>> |         (julia "https://github.com/tree-sitter/tree-sitter-julia";
>>> |                ,(if (< (treesit-library-abi-version) 15)
>>> |                     "v0.23.1"
>>> |                   "master"))
>>> |         (latex "https://github.com/manphiz/tree-sitter-latex"; 
>>> "manual-abi-14")
>>> |         (lua "https://github.com/tree-sitter-grammars/tree-sitter-lua";
>>> |              ,(if (< (treesit-library-abi-version) 15)
>>> |                   "v0.3.0"
>>> |                 "master"))
>>> |         (magik "https://github.com/krn-robin/tree-sitter-magik";
>>> |                ,(if (< (treesit-library-abi-version) 15)
>>> |                     "0.0.1"
>>> |                   "master"))
>>> |         (markdown 
>>> "https://github.com/tree-sitter-grammars/tree-sitter-markdown";
>>> |                   "main")
>>> |         (nu "https://github.com/manphiz/tree-sitter-nu";
>>> |             ,(if (< (treesit-library-abi-version) 15)
>>> |                  "last-abi-14"
>>> |                "master"))
>>> |         (perl "https://github.com/ganezdragon/tree-sitter-perl";
>>> |               ,(if (< (treesit-library-abi-version) 15)
>>> |                    "v1.1.1"
>>> |                  "master"))
>>> |         (python "https://github.com/tree-sitter/tree-sitter-python";
>>> |                 ,(if (< (treesit-library-abi-version) 15)
>>> |                      "v0.23.6"
>>> |                    "master"))
>>> |         (rust "https://github.com/tree-sitter/tree-sitter-rust";
>>> |               ,(if (< (treesit-library-abi-version) 15)
>>> |                    "v0.23.3"
>>> |                  "master"))
>>> |         (sql "https://github.com/manphiz/tree-sitter-sql";
>>> |              ,(if (< (treesit-library-abi-version) 15)
>>> |                   "last-abi-14"
>>> |                 "gh-pages"))
>>> |         (vue "https://github.com/manphiz/tree-sitter-vue";
>>> |              ,(if (< (treesit-library-abi-version) 15)
>>> |                   "last-abi-14"
>>> |                 "master"))
>>> |         (yaml "https://github.com/tree-sitter-grammars/tree-sitter-yaml";
>>> |               ,(if (< (treesit-library-abi-version) 15)
>>> |                    "v0.7.2"
>>> |                  "master"))))
>>> `----
>>>
>>>> Cheers,
>>>>
>>>> Loris
-- 
This signature is currently under constuction.

Reply via email to