Skip to content

Commit 710127d

Browse files
pbolingstackmystack
authored andcommitted
bump: tree-sitter: v0.26.3
- Updated to tree-sitter v0.26.3 - **Breaking Changes in tree-sitter 0.26.x API**: - `ts_language_version` renamed to `ts_language_abi_version` - `TSInputEncodingUTF16` split into `TSInputEncodingUTF16LE` and `TSInputEncodingUTF16BE` (now using UTF16LE as default for backward compatibility) - Cancellation flag API (`ts_parser_cancellation_flag`, `ts_parser_set_cancellation_flag`) removed - `Parser#cancellation_flag` and `Parser#cancellation_flag=` are now no-ops for backward compatibility - Timeout API (`ts_parser_timeout_micros`, `ts_parser_set_timeout_micros`) removed - `Parser#timeout_micros` and `Parser#timeout_micros=` are now no-ops for backward compatibility - Use `TSParseOptions` with `progress_callback` for cancellation/timeout functionality in 0.26+ - `TREE_SITTER_LANGUAGE_VERSION` is now 15 (was 14) - `TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION` is now 13 (was 6) - Grammar files (.so) must be built against tree-sitter 0.26+ to work with this version Closes #94
1 parent 944e10f commit 710127d

9 files changed

Lines changed: 75 additions & 21 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.gemfile
44
*.lock
55
*.log
6+
*.o
67
*.so
78

89
logs
@@ -15,3 +16,9 @@ logs
1516
/tree-sitter
1617
/tree-sitter-parsers
1718
/vendor
19+
20+
# Build artifacts in ext/tree_sitter/
21+
/ext/tree_sitter/Makefile
22+
/ext/tree_sitter/extconf.h
23+
/ext/tree_sitter/tree-sitter-*/
24+

.justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ setup-bundler:
9494
setup-ts:
9595
#!/usr/bin/env bash
9696
set -euo pipefail
97+
version=$(sed -nE 's/^tree-sitter-version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' parsers.toml)
9798
if [ -d tree-sitter ]; then
9899
cd tree-sitter
99100
git reset --hard HEAD
@@ -103,7 +104,7 @@ setup-ts:
103104
git init
104105
git remote add origin https://github.com/tree-sitter/tree-sitter
105106
fi
106-
git fetch origin --depth 1 v0.22.6
107+
git fetch origin --depth 1 "v${version}"
107108
git reset --hard FETCH_HEAD
108109
make
109110
echo "now you can:"

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ source 'https://rubygems.org'
55
gemspec
66

77
group :development, :test do
8-
gem 'bundler', '~> 2.3'
98
gem 'debug', '~> 1.9', require: false
109
gem 'gemstash', require: false
10+
gem 'ostruct'
1111
gem 'rake', '~> 13.2'
1212
gem 'rake-compiler', '~> 1.2'
1313
gem 'rake-compiler-dock', '~> 1.5'
14-
gem 'rubocop', '~> 1.39.0', require: false
14+
gem 'rubocop'
1515
gem 'ruby-lsp', '~> 0.17', require: false
1616
gem 'ruby_memcheck', '~> 1.3'
1717
gem 'tapioca', '~> 0.11', require: false

News.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
# [unreleaseed]
44

5+
## API Changes for tree-sitter 0.26.3 compatibility
6+
7+
- Updated to tree-sitter v0.26.3
8+
- **Breaking Changes in tree-sitter 0.26.x API**:
9+
- `ts_language_version` renamed to `ts_language_abi_version`
10+
- `TSInputEncodingUTF16` split into `TSInputEncodingUTF16LE` and `TSInputEncodingUTF16BE`
11+
(now using UTF16LE as default for backward compatibility)
12+
- Cancellation flag API (`ts_parser_cancellation_flag`, `ts_parser_set_cancellation_flag`) removed
13+
- `Parser#cancellation_flag` and `Parser#cancellation_flag=` are now no-ops for backward compatibility
14+
- Timeout API (`ts_parser_timeout_micros`, `ts_parser_set_timeout_micros`) removed
15+
- `Parser#timeout_micros` and `Parser#timeout_micros=` are now no-ops for backward compatibility
16+
- Use `TSParseOptions` with `progress_callback` for cancellation/timeout functionality in 0.26+
17+
- `TREE_SITTER_LANGUAGE_VERSION` is now 15 (was 14)
18+
- `TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION` is now 13 (was 6)
19+
- Grammar files (.so) must be built against tree-sitter 0.26+ to work with this version
20+
521
# v2.0.0 (22-01-2025)
622

723
- Bump minimum supported Ruby version to 3.1.

ext/tree_sitter/encoding.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ TSInputEncoding value_to_encoding(VALUE encoding) {
1414

1515
// NOTE: should we emit a warning instead of defaulting to UTF8?
1616
if (enc == u16) {
17-
return TSInputEncodingUTF16;
17+
// tree-sitter 0.26+ split UTF16 into UTF16LE and UTF16BE
18+
return TSInputEncodingUTF16LE;
1819
} else {
1920
return TSInputEncodingUTF8;
2021
}

ext/tree_sitter/language.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <stdint.h>
44
#include <stdio.h>
55

6-
typedef TSLanguage *(tree_sitter_lang)(void);
6+
// tree-sitter 0.26+ returns const TSLanguage*
7+
typedef const TSLanguage *(tree_sitter_lang)(void);
78
const char *tree_sitter_prefix = "tree_sitter_";
89

910
extern VALUE mTreeSitter;
@@ -40,23 +41,29 @@ static VALUE language_load(VALUE self, VALUE name, VALUE path) {
4041
VALUE path_s = rb_funcall(path, rb_intern("to_s"), 0);
4142
char *path_cstr = StringValueCStr(path_s);
4243
void *lib = dlopen(path_cstr, RTLD_NOW);
43-
const char *err = dlerror();
44-
if (err != NULL) {
44+
if (lib == NULL) {
45+
const char *err = dlerror();
4546
VALUE parser_not_found = rb_const_get(mTreeSitter, rb_intern("ParserNotFoundError"));
4647
rb_raise(parser_not_found,
47-
"Could not load shared library `%s'.\nReason: %s", path_cstr, err);
48+
"Could not load shared library `%s'.\nReason: %s", path_cstr, err ? err : "unknown error");
4849
}
4950

5051
char buf[256];
5152
snprintf(buf, sizeof(buf), "tree_sitter_%s", StringValueCStr(name));
53+
54+
// Clear any previous error before dlsym (POSIX requirement)
55+
dlerror();
56+
5257
tree_sitter_lang *make_ts_language = dlsym(lib, buf);
53-
err = dlerror();
54-
if (err != NULL) {
58+
59+
// Only check dlerror if dlsym returned NULL
60+
if (make_ts_language == NULL) {
61+
const char *err = dlerror();
5562
dlclose(lib);
5663
VALUE symbol_not_found = rb_const_get(mTreeSitter, rb_intern("SymbolNotFoundError"));
5764
rb_raise(symbol_not_found,
58-
"Could not load symbol `%s' from library `%s'.\nReason:%s",
59-
StringValueCStr(name), path_cstr, err);
65+
"Could not load symbol `%s' from library `%s'.\nReason: %s",
66+
buf, path_cstr, err ? err : "symbol not found");
6067
}
6168

6269
TSLanguage *lang = make_ts_language();
@@ -69,7 +76,8 @@ static VALUE language_load(VALUE self, VALUE name, VALUE path) {
6976
StringValueCStr(name), path_cstr);
7077
}
7178

72-
uint32_t version = ts_language_version(lang);
79+
// tree-sitter 0.26+ renamed ts_language_version to ts_language_abi_version
80+
uint32_t version = ts_language_abi_version(lang);
7381
if (version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION) {
7482
VALUE version_error = rb_const_get(mTreeSitter, rb_intern("ParserVersionError"));
7583
rb_raise(version_error,
@@ -194,7 +202,8 @@ static VALUE language_symbol_type(VALUE self, VALUE symbol) {
194202
* @see Parser#language=
195203
*/
196204
static VALUE language_version(VALUE self) {
197-
return UINT2NUM(ts_language_version(SELF));
205+
// tree-sitter 0.26+ renamed ts_language_version to ts_language_abi_version
206+
return UINT2NUM(ts_language_abi_version(SELF));
198207
}
199208

200209
void init_language(void) {
@@ -220,4 +229,5 @@ void init_language(void) {
220229
rb_define_method(cLanguage, "symbol_name", language_symbol_name, 1);
221230
rb_define_method(cLanguage, "symbol_type", language_symbol_type, 1);
222231
rb_define_method(cLanguage, "version", language_version, 0);
232+
rb_define_method(cLanguage, "abi_version", language_version, 0);
223233
}

ext/tree_sitter/parser.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ static VALUE parser_allocate(VALUE klass) {
4444
* Get the parser's current cancellation flag pointer.
4545
*
4646
* @return [Integer]
47+
*
48+
* @note DEPRECATED in tree-sitter 0.26+. This API was removed.
49+
* Use TSParseOptions with progress_callback instead.
4750
*/
4851
static VALUE parser_get_cancellation_flag(VALUE self) {
49-
return SIZET2NUM(*ts_parser_cancellation_flag(SELF));
52+
// tree-sitter 0.26+ removed cancellation_flag API
53+
// Return the stored value for backward compatibility
54+
return SIZET2NUM(unwrap(self)->cancellation_flag);
5055
}
5156

5257
/**
@@ -58,13 +63,15 @@ static VALUE parser_get_cancellation_flag(VALUE self) {
5863
*
5964
* @see parse
6065
*
61-
* @note This is not well-tested in the bindings.
66+
* @note DEPRECATED in tree-sitter 0.26+. This API was removed.
67+
* Use TSParseOptions with progress_callback instead.
6268
*
6369
* @return nil
6470
*/
6571
static VALUE parser_set_cancellation_flag(VALUE self, VALUE flag) {
72+
// tree-sitter 0.26+ removed cancellation_flag API
73+
// Store the value for backward compatibility but it won't affect parsing
6674
unwrap(self)->cancellation_flag = NUM2SIZET(flag);
67-
ts_parser_set_cancellation_flag(SELF, &unwrap(self)->cancellation_flag);
6875
return Qnil;
6976
}
7077

@@ -349,9 +356,15 @@ static VALUE parser_reset(VALUE self) {
349356
* Get the duration in microseconds that parsing is allowed to take.
350357
*
351358
* @return [Integer]
359+
*
360+
* @note DEPRECATED in tree-sitter 0.26+. This API was removed.
361+
* Use TSParseOptions with progress_callback instead.
352362
*/
353363
static VALUE parser_get_timeout_micros(VALUE self) {
354-
return ULL2NUM(ts_parser_timeout_micros(SELF));
364+
// tree-sitter 0.26+ removed timeout_micros API
365+
// Return 0 to indicate no timeout (was the default behavior)
366+
(void)self; // suppress unused parameter warning
367+
return ULL2NUM(0);
355368
}
356369

357370
/**
@@ -362,12 +375,18 @@ static VALUE parser_get_timeout_micros(VALUE self) {
362375
*
363376
* @see parse
364377
*
378+
* @note DEPRECATED in tree-sitter 0.26+. This API was removed.
379+
* Use TSParseOptions with progress_callback instead.
380+
*
365381
* @param timeout [Integer]
366382
*
367383
* @return [nil]
368384
*/
369385
static VALUE parser_set_timeout_micros(VALUE self, VALUE timeout) {
370-
ts_parser_set_timeout_micros(SELF, NUM2ULL(timeout));
386+
// tree-sitter 0.26+ removed timeout_micros API
387+
// This is a no-op for backward compatibility
388+
(void)self; // suppress unused parameter warning
389+
(void)timeout; // suppress unused parameter warning
371390
return Qnil;
372391
}
373392

lib/tree_sitter/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module TreeSitter
44
# The version of the tree-sitter library.
5-
TREESITTER_VERSION = '0.24.7'
5+
TREESITTER_VERSION = '0.26.3'
66
# The current version of the gem.
77
VERSION = '2.0.0'
88
end

parsers.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build-dir = "vendor/parsers/build"
22
out-dir = "vendor/parsers"
3-
tree-sitter-version = "0.24.7"
3+
tree-sitter-version = "0.26.3"
44

55
[parsers]
66
embedded-template = "0.23.2"

0 commit comments

Comments
 (0)