Skip to content

Commit f865155

Browse files
authored
emacs: backport tree-sitter 0.26 compat patch (#26831)
1 parent 28680dd commit f865155

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
}

mingw-w64-emacs/PKGBUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ source=("https://ftpmirror.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.x
4848
"003-aarch64-fixes.patch"
4949
"004-dll-versions.patch"
5050
"005-lseek.patch"
51+
"006-tree-sitter-0.26.patch"
5152
"emacs-ARM64.manifest")
5253
# source=("https://alpha.gnu.org/gnu/${_realname}/pretest/${_realname}-${pkgver}.tar.xz"{,.sig})
5354
sha256sums=('b3f36f18a6dd2715713370166257de2fae01f9d38cfe878ced9b1e6ded5befd9'
@@ -57,6 +58,7 @@ sha256sums=('b3f36f18a6dd2715713370166257de2fae01f9d38cfe878ced9b1e6ded5befd9'
5758
'd128982d87af1e524ae809147613168153f0e5c1efb0ef633793df47b762c9e1'
5859
'1fcba307b278a7794ecca4f09e7ce1a715b4ee255badd3fa376ca1ef1aa7246f'
5960
'b91e8a63f6afef93fad119f5b4b5bca132bb7f5564df6f26d085dcfa9e28c64c'
61+
'347865464b588212d77851741f2675efa852a9d5ba0d2922e23231ebaa1f2985'
6062
'bfe64602dbeeec85799c1156ca4f3837fdac42a076e83a4221768db3417220e1')
6163
validpgpkeys=('28D3BED851FDF3AB57FEF93C233587A47C207910'
6264
'17E90D521672C04631B1183EE78DAE0F3115E06B'
@@ -81,7 +83,8 @@ prepare() {
8183
002-clang-fixes.patch \
8284
003-aarch64-fixes.patch \
8385
004-dll-versions.patch \
84-
005-lseek.patch
86+
005-lseek.patch \
87+
006-tree-sitter-0.26.patch
8588

8689
# Fail if 004-dll-versions.patch needs to be updated
8790
_dllname_xml=$(dlltool --identify "${MINGW_PREFIX}/lib/libxml2.dll.a")

0 commit comments

Comments
 (0)