|
| 1 | +diff --git a/src/treesit.c b/src/treesit.c |
| 2 | +index bf982de580bd..69751b5ea106 100644 |
| 3 | +--- a/src/treesit.c |
| 4 | ++++ b/src/treesit.c |
| 5 | +@@ -35,7 +35,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ |
| 6 | + # include "w32common.h" |
| 7 | + |
| 8 | + /* In alphabetical order. */ |
| 9 | ++#if TREE_SITTER_LANGUAGE_VERSION >= 15 |
| 10 | ++#undef ts_language_abi_version |
| 11 | ++#else |
| 12 | + #undef ts_language_version |
| 13 | ++#endif |
| 14 | + #undef ts_node_child |
| 15 | + #undef ts_node_child_by_field_name |
| 16 | + #undef ts_node_child_count |
| 17 | +@@ -90,7 +94,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ |
| 18 | + #undef ts_tree_get_changed_ranges |
| 19 | + #undef ts_tree_root_node |
| 20 | + |
| 21 | ++#if TREE_SITTER_LANGUAGE_VERSION >= 15 |
| 22 | ++DEF_DLL_FN (uint32_t, ts_language_abi_version, (const TSLanguage *)); |
| 23 | ++#else |
| 24 | + DEF_DLL_FN (uint32_t, ts_language_version, (const TSLanguage *)); |
| 25 | ++#endif |
| 26 | + DEF_DLL_FN (TSNode, ts_node_child, (TSNode, uint32_t)); |
| 27 | + DEF_DLL_FN (TSNode, ts_node_child_by_field_name, |
| 28 | + (TSNode, const char *, uint32_t)); |
| 29 | +@@ -167,7 +175,11 @@ init_treesit_functions (void) |
| 30 | + if (!library) |
| 31 | + return false; |
| 32 | + |
| 33 | ++#if TREE_SITTER_LANGUAGE_VERSION >= 15 |
| 34 | ++ LOAD_DLL_FN (library, ts_language_abi_version); |
| 35 | ++#else |
| 36 | + LOAD_DLL_FN (library, ts_language_version); |
| 37 | ++#endif |
| 38 | + LOAD_DLL_FN (library, ts_node_child); |
| 39 | + LOAD_DLL_FN (library, ts_node_child_by_field_name); |
| 40 | + LOAD_DLL_FN (library, ts_node_child_count); |
| 41 | +@@ -225,7 +237,11 @@ init_treesit_functions (void) |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
| 45 | ++#if TREE_SITTER_LANGUAGE_VERSION >= 15 |
| 46 | ++#define ts_language_abi_version fn_ts_language_abi_version |
| 47 | ++#else |
| 48 | + #define ts_language_version fn_ts_language_version |
| 49 | ++#endif |
| 50 | + #define ts_node_child fn_ts_node_child |
| 51 | + #define ts_node_child_by_field_name fn_ts_node_child_by_field_name |
| 52 | + #define ts_node_child_count fn_ts_node_child_count |
| 53 | +@@ -711,6 +727,22 @@ treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name, |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | ++/* This function is a compatibility shim. Tree-sitter 0.25 introduced |
| 58 | ++ ts_language_abi_version as a replacement for ts_language_version, and |
| 59 | ++ tree-sitter 0.26 removed ts_language_version. Here we use the fact |
| 60 | ++ that 0.25 bumped TREE_SITTER_LANGUAGE_VERSION to 15, to use the new |
| 61 | ++ function instead of the old one, when Emacs is compiled against |
| 62 | ++ tree-sitter version 0.25 or newer. */ |
| 63 | ++static uint32_t |
| 64 | ++treesit_language_abi_version (const TSLanguage *ts_lang) |
| 65 | ++{ |
| 66 | ++#if TREE_SITTER_LANGUAGE_VERSION >= 15 |
| 67 | ++ return ts_language_abi_version (ts_lang); |
| 68 | ++#else |
| 69 | ++ return ts_language_version (ts_lang); |
| 70 | ++#endif |
| 71 | ++} |
| 72 | ++ |
| 73 | + /* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer |
| 74 | + to the language definition. |
| 75 | + |
| 76 | +@@ -746,7 +778,7 @@ |
| 77 | + { |
| 78 | + *signal_symbol = Qtreesit_load_language_error; |
| 79 | + *signal_data = list2 (Qversion_mismatch, |
| 80 | +- make_fixnum (ts_language_version (lang))); |
| 81 | ++ make_fixnum (ts_language_abi_version (lang))); |
| 82 | + return NULL; |
| 83 | + } |
| 84 | + return lang; |
| 85 | +@@ -914,7 +946,7 @@ Return nil if a grammar library for LANGUAGE is not available. */) |
| 86 | + TSLanguage *ts_language = lang.lang; |
| 87 | + if (ts_language == NULL) |
| 88 | + return Qnil; |
| 89 | +- uint32_t version = ts_language_version (ts_language); |
| 90 | ++ uint32_t version = treesit_language_abi_version (ts_language); |
| 91 | + return make_fixnum((ptrdiff_t) version); |
| 92 | + } |
| 93 | + } |
0 commit comments