]> git.eshelyaron.com Git - emacs.git/commitdiff
Support new tree-sitter grammar filename format (bug#78754)
authorYuan Fu <casouri@gmail.com>
Wed, 11 Jun 2025 05:55:58 +0000 (22:55 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 18 Jun 2025 08:08:12 +0000 (10:08 +0200)
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.

(cherry picked from commit 941158fc133f9722abbca8b89a0a346230b83998)

src/treesit.c

index 67dd2ee3a7ae55c8b56818a870a14dbcf5b6a124..5db0f838d3e7b6de47a40887e811ccc7edfd8fad 100644 (file)
@@ -682,14 +682,29 @@ treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name,
       Lisp_Object candidate1 = concat2 (lib_base_name, XCAR (suffixes));
 #ifndef WINDOWSNT
       /* On Posix hosts, support libraries named with ABI version
-         numbers.  In the foreseeable future we only need to support
-         version 0.0.  For more details, see
+         numbers.  Originally tree-sitter grammars are always versioned
+         at 0.0, so we first try that.  For more details, see
          https://lists.gnu.org/archive/html/emacs-devel/2023-04/msg00386.html.  */
       Lisp_Object candidate2 = concat2 (candidate1, Vtreesit_str_dot_0);
       Lisp_Object candidate3 = concat2 (candidate2, Vtreesit_str_dot_0);
 
       *path_candidates = Fcons (candidate3, *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
       *path_candidates = Fcons (candidate1, *path_candidates);
     }