Support new tree-sitter grammar filename format (bug#78754)

Previously Emacs only looks for filenames like
libtree-sitter-json.so.0.0.  Now Emacs also look for filenames
like libtree-sitter-json.so.15.0.

* src/treesit.c:
(treesit_load_language_push_for_each_suffix): Add versioned
candidate to candidate list too.
This commit is contained in:
Yuan Fu 2025-06-10 22:55:58 -07:00
parent 888f846d37
commit 941158fc13
No known key found for this signature in database
GPG key ID: 56E19BC57664A442

View file

@ -603,14 +603,29 @@ treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name,
Lisp_Object candidate1 = concat2 (lib_base_name, XCAR (suffixes)); Lisp_Object candidate1 = concat2 (lib_base_name, XCAR (suffixes));
#ifndef WINDOWSNT #ifndef WINDOWSNT
/* On Posix hosts, support libraries named with ABI version /* On Posix hosts, support libraries named with ABI version
numbers. In the foreseeable future we only need to support numbers. Originally tree-sitter grammars are always versioned
version 0.0. For more details, see at 0.0, so we first try that. For more details, see
https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00386.html. */ https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00386.html. */
Lisp_Object candidate2 = concat2 (candidate1, Vtreesit_str_dot_0); Lisp_Object candidate2 = concat2 (candidate1, Vtreesit_str_dot_0);
Lisp_Object candidate3 = concat2 (candidate2, Vtreesit_str_dot_0); Lisp_Object candidate3 = concat2 (candidate2, Vtreesit_str_dot_0);
*path_candidates = Fcons (candidate3, *path_candidates); *path_candidates = Fcons (candidate3, *path_candidates);
*path_candidates = Fcons (candidate2, *path_candidates); *path_candidates = Fcons (candidate2, *path_candidates);
/* Since 2025, tree-sitter grammars use their supported
TREE_SITTER_LANGUAGE_VERSION as the major version. So we need
to try all the version supported by the tree-sitter library
too. (See bug#78754) */
for (int version = TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION;
version <= TREE_SITTER_LANGUAGE_VERSION;
version++)
{
char ext[16]; // 16 should be enough until the end of universe.
snprintf ((char *) &ext, 16, ".%d.0", version);
Lisp_Object versioned_candidate = concat2 (candidate1,
build_string (ext));
*path_candidates = Fcons (versioned_candidate, *path_candidates);
}
#endif #endif
*path_candidates = Fcons (candidate1, *path_candidates); *path_candidates = Fcons (candidate1, *path_candidates);
} }