diff options
| author | Eli Zaretskii | 2025-10-17 14:15:41 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2025-10-17 14:15:41 +0300 |
| commit | d587ce8c65a0e22ab0a63ef2873a3dfcfbeba166 (patch) | |
| tree | 29f696dd57a51faea42bc2c6ccf0f6d45bb9c22a /src | |
| parent | bd0a141d094315663731420043936293f566f510 (diff) | |
| download | emacs-d587ce8c65a0e22ab0a63ef2873a3dfcfbeba166.tar.gz emacs-d587ce8c65a0e22ab0a63ef2873a3dfcfbeba166.zip | |
Support Tree-sitter version 0.26 and later
* src/treesit.c (init_treesit_functions)
[TREE_SITTER_LANGUAGE_VERSION >= 15]: Define prototype for, and
load 'ts_language_abi_version' instead of the deprecated (and
removed in tree-sitter 0.26) 'ts_language_version'.
(ts_language_abi_version) [TREE_SITTER_LANGUAGE_VERSION >= 15]:
Define on WINDOWSNT, instead of 'ts_language_version'.
(treesit_language_abi_version): New compatibility function.
(treesit_load_language, Ftreesit_language_abi_version): Use
'treesit_language_abi_version' instead of 'ts_language_version'.
(Bug#79627)
Diffstat (limited to 'src')
| -rw-r--r-- | src/treesit.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/treesit.c b/src/treesit.c index bf982de580b..69751b5ea10 100644 --- a/src/treesit.c +++ b/src/treesit.c | |||
| @@ -35,7 +35,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 35 | # include "w32common.h" | 35 | # include "w32common.h" |
| 36 | 36 | ||
| 37 | /* In alphabetical order. */ | 37 | /* In alphabetical order. */ |
| 38 | #if TREE_SITTER_LANGUAGE_VERSION >= 15 | ||
| 39 | #undef ts_language_abi_version | ||
| 40 | #else | ||
| 38 | #undef ts_language_version | 41 | #undef ts_language_version |
| 42 | #endif | ||
| 39 | #undef ts_node_child | 43 | #undef ts_node_child |
| 40 | #undef ts_node_child_by_field_name | 44 | #undef ts_node_child_by_field_name |
| 41 | #undef ts_node_child_count | 45 | #undef ts_node_child_count |
| @@ -90,7 +94,11 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 90 | #undef ts_tree_get_changed_ranges | 94 | #undef ts_tree_get_changed_ranges |
| 91 | #undef ts_tree_root_node | 95 | #undef ts_tree_root_node |
| 92 | 96 | ||
| 97 | #if TREE_SITTER_LANGUAGE_VERSION >= 15 | ||
| 98 | DEF_DLL_FN (uint32_t, ts_language_abi_version, (const TSLanguage *)); | ||
| 99 | #else | ||
| 93 | DEF_DLL_FN (uint32_t, ts_language_version, (const TSLanguage *)); | 100 | DEF_DLL_FN (uint32_t, ts_language_version, (const TSLanguage *)); |
| 101 | #endif | ||
| 94 | DEF_DLL_FN (TSNode, ts_node_child, (TSNode, uint32_t)); | 102 | DEF_DLL_FN (TSNode, ts_node_child, (TSNode, uint32_t)); |
| 95 | DEF_DLL_FN (TSNode, ts_node_child_by_field_name, | 103 | DEF_DLL_FN (TSNode, ts_node_child_by_field_name, |
| 96 | (TSNode, const char *, uint32_t)); | 104 | (TSNode, const char *, uint32_t)); |
| @@ -167,7 +175,11 @@ init_treesit_functions (void) | |||
| 167 | if (!library) | 175 | if (!library) |
| 168 | return false; | 176 | return false; |
| 169 | 177 | ||
| 178 | #if TREE_SITTER_LANGUAGE_VERSION >= 15 | ||
| 179 | LOAD_DLL_FN (library, ts_language_abi_version); | ||
| 180 | #else | ||
| 170 | LOAD_DLL_FN (library, ts_language_version); | 181 | LOAD_DLL_FN (library, ts_language_version); |
| 182 | #endif | ||
| 171 | LOAD_DLL_FN (library, ts_node_child); | 183 | LOAD_DLL_FN (library, ts_node_child); |
| 172 | LOAD_DLL_FN (library, ts_node_child_by_field_name); | 184 | LOAD_DLL_FN (library, ts_node_child_by_field_name); |
| 173 | LOAD_DLL_FN (library, ts_node_child_count); | 185 | LOAD_DLL_FN (library, ts_node_child_count); |
| @@ -225,7 +237,11 @@ init_treesit_functions (void) | |||
| 225 | return true; | 237 | return true; |
| 226 | } | 238 | } |
| 227 | 239 | ||
| 240 | #if TREE_SITTER_LANGUAGE_VERSION >= 15 | ||
| 241 | #define ts_language_abi_version fn_ts_language_abi_version | ||
| 242 | #else | ||
| 228 | #define ts_language_version fn_ts_language_version | 243 | #define ts_language_version fn_ts_language_version |
| 244 | #endif | ||
| 229 | #define ts_node_child fn_ts_node_child | 245 | #define ts_node_child fn_ts_node_child |
| 230 | #define ts_node_child_by_field_name fn_ts_node_child_by_field_name | 246 | #define ts_node_child_by_field_name fn_ts_node_child_by_field_name |
| 231 | #define ts_node_child_count fn_ts_node_child_count | 247 | #define ts_node_child_count fn_ts_node_child_count |
| @@ -711,6 +727,22 @@ treesit_load_language_push_for_each_suffix (Lisp_Object lib_base_name, | |||
| 711 | } | 727 | } |
| 712 | } | 728 | } |
| 713 | 729 | ||
| 730 | /* This function is a compatibility shim. Tree-sitter 0.25 introduced | ||
| 731 | ts_language_abi_version as a replacement for ts_language_version, and | ||
| 732 | tree-sitter 0.26 removed ts_language_version. Here we use the fact | ||
| 733 | that 0.25 bumped TREE_SITTER_LANGUAGE_VERSION to 15, to use the new | ||
| 734 | function instead of the old one, when Emacs is compiled against | ||
| 735 | tree-sitter version 0.25 or newer. */ | ||
| 736 | static uint32_t | ||
| 737 | treesit_language_abi_version (const TSLanguage *ts_lang) | ||
| 738 | { | ||
| 739 | #if TREE_SITTER_LANGUAGE_VERSION >= 15 | ||
| 740 | return ts_language_abi_version (ts_lang); | ||
| 741 | #else | ||
| 742 | return ts_language_version (ts_lang); | ||
| 743 | #endif | ||
| 744 | } | ||
| 745 | |||
| 714 | /* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer | 746 | /* Load the dynamic library of LANGUAGE_SYMBOL and return the pointer |
| 715 | to the language definition. | 747 | to the language definition. |
| 716 | 748 | ||
| @@ -832,7 +864,7 @@ treesit_load_language (Lisp_Object language_symbol, | |||
| 832 | build_string ("%s's ABI version is %d, but supported versions are %d-%d"); | 864 | build_string ("%s's ABI version is %d, but supported versions are %d-%d"); |
| 833 | Lisp_Object formatted_msg = | 865 | Lisp_Object formatted_msg = |
| 834 | CALLN (Fformat_message, fmt, loaded_lib, | 866 | CALLN (Fformat_message, fmt, loaded_lib, |
| 835 | make_fixnum (ts_language_version (lang)), | 867 | make_fixnum (treesit_language_abi_version (lang)), |
| 836 | make_fixnum (TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION), | 868 | make_fixnum (TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION), |
| 837 | make_fixnum (TREE_SITTER_LANGUAGE_VERSION)); | 869 | make_fixnum (TREE_SITTER_LANGUAGE_VERSION)); |
| 838 | *signal_symbol = Qtreesit_load_language_error; | 870 | *signal_symbol = Qtreesit_load_language_error; |
| @@ -914,7 +946,7 @@ Return nil if a grammar library for LANGUAGE is not available. */) | |||
| 914 | TSLanguage *ts_language = lang.lang; | 946 | TSLanguage *ts_language = lang.lang; |
| 915 | if (ts_language == NULL) | 947 | if (ts_language == NULL) |
| 916 | return Qnil; | 948 | return Qnil; |
| 917 | uint32_t version = ts_language_version (ts_language); | 949 | uint32_t version = treesit_language_abi_version (ts_language); |
| 918 | return make_fixnum((ptrdiff_t) version); | 950 | return make_fixnum((ptrdiff_t) version); |
| 919 | } | 951 | } |
| 920 | } | 952 | } |