Skip to content

Commit c93d38e

Browse files
feat!: update API to 0.26
1 parent 0202e02 commit c93d38e

File tree

10 files changed

+102
-152
lines changed

10 files changed

+102
-152
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tree-sitter"]
22
url = https://github.com/tree-sitter/tree-sitter
33
path = core
4-
branch = release-0.25
4+
branch = release-0.26

core

Submodule core updated 384 files

scripts/jextract.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ $lib = "$($args[0])/core/lib"
9090
--include-function ts_node_string `
9191
--include-function ts_node_symbol `
9292
--include-function ts_node_type `
93-
--include-function ts_parser_cancellation_flag `
9493
--include-function ts_parser_delete `
9594
--include-function ts_parser_included_ranges `
9695
--include-function ts_parser_language `
@@ -102,12 +101,10 @@ $lib = "$($args[0])/core/lib"
102101
--include-function ts_parser_parse_with_options `
103102
--include-function ts_parser_print_dot_graphs `
104103
--include-function ts_parser_reset `
105-
--include-function ts_parser_set_cancellation_flag `
106104
--include-function ts_parser_set_included_ranges `
107105
--include-function ts_parser_set_language `
108106
--include-function ts_parser_set_logger `
109-
--include-function ts_parser_set_timeout_micros `
110-
--include-function ts_parser_timeout_micros `
107+
--include-function ts_point_edit `
111108
--include-function ts_query_capture_count `
112109
--include-function ts_query_capture_name_for_id `
113110
--include-function ts_query_capture_quantifier_for_id `
@@ -121,11 +118,11 @@ $lib = "$($args[0])/core/lib"
121118
--include-function ts_query_cursor_next_match `
122119
--include-function ts_query_cursor_remove_match `
123120
--include-function ts_query_cursor_set_byte_range `
121+
--include-function ts_query_cursor_set_containing_byte_range `
122+
--include-function ts_query_cursor_set_containing_point_range `
124123
--include-function ts_query_cursor_set_match_limit `
125124
--include-function ts_query_cursor_set_max_start_depth `
126125
--include-function ts_query_cursor_set_point_range `
127-
--include-function ts_query_cursor_set_timeout_micros `
128-
--include-function ts_query_cursor_timeout_micros `
129126
--include-function ts_query_delete `
130127
--include-function ts_query_disable_capture `
131128
--include-function ts_query_disable_pattern `
@@ -139,6 +136,7 @@ $lib = "$($args[0])/core/lib"
139136
--include-function ts_query_start_byte_for_pattern `
140137
--include-function ts_query_string_count `
141138
--include-function ts_query_string_value_for_id `
139+
--include-function ts_range_edit `
142140
--include-function ts_tree_copy `
143141
--include-function ts_tree_cursor_copy `
144142
--include-function ts_tree_cursor_current_depth `
@@ -193,7 +191,7 @@ $lib = "$($args[0])/core/lib"
193191
--include-constant TSSymbolTypeAuxiliary `
194192
--include-constant TSSymbolTypeRegular `
195193
--include-constant TSSymbolTypeSupertype `
196-
--include-typedef DecodeFunction `
194+
--include-typedef TSDecodeFunction `
197195
--header-class-name TreeSitter `
198196
--output $output `
199197
-t $package `

scripts/jextract.sh

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ exec jextract \
9292
--include-function ts_node_string \
9393
--include-function ts_node_symbol \
9494
--include-function ts_node_type \
95-
--include-function ts_parser_cancellation_flag \
9695
--include-function ts_parser_delete \
9796
--include-function ts_parser_included_ranges \
9897
--include-function ts_parser_language \
@@ -104,12 +103,10 @@ exec jextract \
104103
--include-function ts_parser_parse_with_options \
105104
--include-function ts_parser_print_dot_graphs \
106105
--include-function ts_parser_reset \
107-
--include-function ts_parser_set_cancellation_flag \
108106
--include-function ts_parser_set_included_ranges \
109107
--include-function ts_parser_set_language \
110108
--include-function ts_parser_set_logger \
111-
--include-function ts_parser_set_timeout_micros \
112-
--include-function ts_parser_timeout_micros \
109+
--include-function ts_point_edit \
113110
--include-function ts_query_capture_count \
114111
--include-function ts_query_capture_name_for_id \
115112
--include-function ts_query_capture_quantifier_for_id \
@@ -123,11 +120,11 @@ exec jextract \
123120
--include-function ts_query_cursor_next_match \
124121
--include-function ts_query_cursor_remove_match \
125122
--include-function ts_query_cursor_set_byte_range \
123+
--include-function ts_query_cursor_set_containing_byte_range \
124+
--include-function ts_query_cursor_set_containing_point_range \
126125
--include-function ts_query_cursor_set_match_limit \
127126
--include-function ts_query_cursor_set_max_start_depth \
128127
--include-function ts_query_cursor_set_point_range \
129-
--include-function ts_query_cursor_set_timeout_micros \
130-
--include-function ts_query_cursor_timeout_micros \
131128
--include-function ts_query_delete \
132129
--include-function ts_query_disable_capture \
133130
--include-function ts_query_disable_pattern \
@@ -141,6 +138,7 @@ exec jextract \
141138
--include-function ts_query_start_byte_for_pattern \
142139
--include-function ts_query_string_count \
143140
--include-function ts_query_string_value_for_id \
141+
--include-function ts_range_edit \
144142
--include-function ts_tree_copy \
145143
--include-function ts_tree_cursor_copy \
146144
--include-function ts_tree_cursor_current_depth \
@@ -195,7 +193,7 @@ exec jextract \
195193
--include-constant TSSymbolTypeAuxiliary \
196194
--include-constant TSSymbolTypeRegular \
197195
--include-constant TSSymbolTypeSupertype \
198-
--include-typedef DecodeFunction \
196+
--include-typedef TSDecodeFunction \
199197
--header-class-name TreeSitter \
200198
--output "$output" \
201199
-t "$package" \

src/main/java/io/github/treesitter/jtreesitter/Parser.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Collections;
1010
import java.util.List;
1111
import java.util.Optional;
12-
import java.util.concurrent.atomic.AtomicLong;
1312
import java.util.function.Predicate;
1413
import org.jspecify.annotations.NullMarked;
1514
import org.jspecify.annotations.Nullable;
@@ -52,30 +51,6 @@ public Parser setLanguage(Language language) {
5251
return this;
5352
}
5453

55-
/**
56-
* Get the maximum duration in microseconds that
57-
* parsing should be allowed to take before halting.
58-
*
59-
* @deprecated Use {@link Options} instead.
60-
*/
61-
@Deprecated(since = "0.25.0")
62-
public @Unsigned long getTimeoutMicros() {
63-
return ts_parser_timeout_micros(self);
64-
}
65-
66-
/**
67-
* Set the maximum duration in microseconds that
68-
* parsing should be allowed to take before halting.
69-
*
70-
* @deprecated Use {@link Options} instead.
71-
*/
72-
@Deprecated(since = "0.25.0")
73-
@SuppressWarnings("DeprecatedIsStillUsed")
74-
public Parser setTimeoutMicros(@Unsigned long timeoutMicros) {
75-
ts_parser_set_timeout_micros(self, timeoutMicros);
76-
return this;
77-
}
78-
7954
/**
8055
* Set the logger that the parser will use during parsing.
8156
*
@@ -108,21 +83,6 @@ public Parser setLogger(@Nullable Logger logger) {
10883
return this;
10984
}
11085

111-
/**
112-
* Set the parser's current cancellation flag.
113-
*
114-
* <p>The parser will periodically read from this flag during parsing.
115-
* If it reads a non-zero value, it will halt early.
116-
*
117-
* @deprecated Use {@link Options} instead.
118-
*/
119-
@Deprecated(since = "0.25.0")
120-
@SuppressWarnings("DeprecatedIsStillUsed")
121-
public synchronized Parser setCancellationFlag(CancellationFlag cancellationFlag) {
122-
ts_parser_set_cancellation_flag(self, cancellationFlag.segment);
123-
return this;
124-
}
125-
12686
/**
12787
* Get the ranges of text that the parser should include when parsing.
12888
*
@@ -411,31 +371,4 @@ private boolean progressCallback(State state) {
411371
return progressCallback.test(state);
412372
}
413373
}
414-
415-
/**
416-
* A class representing a cancellation flag.
417-
*
418-
* @deprecated Use {@link Options} instead.
419-
*/
420-
@Deprecated(since = "0.25.0")
421-
@SuppressWarnings("DeprecatedIsStillUsed")
422-
public static class CancellationFlag {
423-
private final Arena arena = Arena.ofAuto();
424-
private final MemorySegment segment = arena.allocate(C_LONG_LONG);
425-
private final AtomicLong value = new AtomicLong();
426-
427-
/** Creates an uninitialized cancellation flag. */
428-
public CancellationFlag() {}
429-
430-
/** Get the value of the flag. */
431-
public long get() {
432-
return value.get();
433-
}
434-
435-
/** Set the value of the flag. */
436-
@SuppressWarnings("unused")
437-
public void set(long value) {
438-
segment.set(C_LONG_LONG, 0L, this.value.updateAndGet(_ -> value));
439-
}
440-
}
441374
}

src/main/java/io/github/treesitter/jtreesitter/Point.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.github.treesitter.jtreesitter;
22

3+
import static io.github.treesitter.jtreesitter.internal.TreeSitter.*;
4+
35
import io.github.treesitter.jtreesitter.internal.TSPoint;
6+
import java.lang.foreign.Arena;
47
import java.lang.foreign.MemorySegment;
58
import java.lang.foreign.SegmentAllocator;
69

@@ -35,6 +38,23 @@ public int compareTo(Point other) {
3538
return Integer.compareUnsigned(column, other.column);
3639
}
3740

41+
/**
42+
* Edit the point to keep it in-sync with source code that has been edited.
43+
*
44+
* <p>This function updates the point's byte offset and row/column position based on an edit
45+
* operation. This is useful for editing points without requiring a tree or node instance.
46+
*
47+
* @return The new start byte of the point.
48+
* @since 0.26.0
49+
*/
50+
public @Unsigned int edit(InputEdit edit) {
51+
try (var alloc = Arena.ofConfined()) {
52+
var start_byte = alloc.allocate(C_INT.byteSize(), C_INT.byteAlignment());
53+
ts_point_edit(into(alloc), start_byte, edit.into(alloc));
54+
return start_byte.get(C_INT, 0);
55+
}
56+
}
57+
3858
@Override
3959
public String toString() {
4060
return "Point[row=%s, column=%s]".formatted(Integer.toUnsignedString(row), Integer.toUnsignedString(column));

src/main/java/io/github/treesitter/jtreesitter/QueryCursor.java

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,31 +55,6 @@ public QueryCursor setMatchLimit(@Unsigned int matchLimit) throws IllegalArgumen
5555
return this;
5656
}
5757

58-
/**
59-
* Get the maximum duration in microseconds that query
60-
* execution should be allowed to take before halting.
61-
*
62-
* @apiNote Defaults to {@code 0} (unlimited).
63-
*
64-
* @deprecated Use {@link Options} instead.
65-
*/
66-
@Deprecated(since = "0.25.0")
67-
public @Unsigned long getTimeoutMicros() {
68-
return ts_query_cursor_timeout_micros(self);
69-
}
70-
71-
/**
72-
* Set the maximum duration in microseconds that query
73-
* execution should be allowed to take before halting.
74-
*
75-
* @deprecated Use {@link Options} instead.
76-
*/
77-
@Deprecated(since = "0.25.0")
78-
public QueryCursor setTimeoutMicros(@Unsigned long timeoutMicros) {
79-
ts_query_cursor_set_timeout_micros(self, timeoutMicros);
80-
return this;
81-
}
82-
8358
/**
8459
* Set the maximum start depth for the query.
8560
*
@@ -93,6 +68,7 @@ public QueryCursor setMaxStartDepth(@Unsigned int maxStartDepth) {
9368

9469
/**
9570
* Set the range of bytes in which the query will be executed.
71+
*
9672
* <p>The query cursor will return matches that intersect with the given range.
9773
* This means that a match may be returned even if some of its captures fall
9874
* outside the specified range, as long as at least part of the match
@@ -111,6 +87,25 @@ public QueryCursor setByteRange(@Unsigned int startByte, @Unsigned int endByte)
11187
return this;
11288
}
11389

90+
/**
91+
* Set the byte range within which all matches must be fully contained.
92+
*
93+
* <p>In contrast to {@link #setByteRange(int, int)}, this will restrict the query cursor
94+
* to only return matches where <em>all</em> nodes are <em>fully</em> contained within
95+
* the given range. Both functions can be used together, e.g. to search for any matches
96+
* that intersect line 5000, as long as they are fully contained within lines 4500-5500.
97+
*
98+
* @throws IllegalArgumentException If {@code endByte > startByte}.
99+
* @since 0.26.0
100+
*/
101+
public QueryCursor setContainingByteRange(@Unsigned int startByte, @Unsigned int endByte)
102+
throws IllegalArgumentException {
103+
if (!ts_query_cursor_set_containing_byte_range(self, startByte, endByte)) {
104+
throw new IllegalArgumentException("Invalid byte range");
105+
}
106+
return this;
107+
}
108+
114109
/**
115110
* Set the range of points in which the query will be executed.
116111
*
@@ -135,6 +130,27 @@ public QueryCursor setPointRange(Point startPoint, Point endPoint) throws Illega
135130
return this;
136131
}
137132

133+
/**
134+
* Set the point range within which all matches must be fully contained.
135+
*
136+
* <p>In contrast to {@link #setPointRange(Point, Point)}, this will restrict the query cursor
137+
* to only return matches where <em>all</em> nodes are <em>fully</em> contained within
138+
* the given range. Both functions can be used together, e.g. to search for any matches
139+
* that intersect line 5000, as long as they are fully contained within lines 4500-5500.
140+
*
141+
* @throws IllegalArgumentException If {@code endPoint > startPoint}.
142+
* @since 0.26.0
143+
*/
144+
public QueryCursor setContainingPointRange(Point startPoint, Point endPoint) throws IllegalArgumentException {
145+
try (var alloc = Arena.ofConfined()) {
146+
MemorySegment start = startPoint.into(alloc), end = endPoint.into(alloc);
147+
if (!ts_query_cursor_set_containing_point_range(self, start, end)) {
148+
throw new IllegalArgumentException("Invalid point range");
149+
}
150+
}
151+
return this;
152+
}
153+
138154
/**
139155
* Check if the query exceeded its maximum number of
140156
* in-progress matches during its last execution.
@@ -298,14 +314,21 @@ public static class Options {
298314
private final @Nullable Predicate<State> progressCallback;
299315
private final @Nullable BiPredicate<QueryPredicate, QueryMatch> predicateCallback;
300316

317+
/**
318+
* @since 0.26.0
319+
*/
320+
public Options() {
321+
this.progressCallback = null;
322+
this.predicateCallback = null;
323+
}
324+
301325
/**
302326
* @param progressCallback Progress handler. Return {@code true} to cancel query execution,
303327
* {@code false} to continue query execution.
304328
* @param predicateCallback Custom predicate handler.
329+
* @since 0.26.0
305330
*/
306-
public Options(
307-
@Nullable Predicate<State> progressCallback,
308-
@Nullable BiPredicate<QueryPredicate, QueryMatch> predicateCallback) {
331+
public Options(Predicate<State> progressCallback, BiPredicate<QueryPredicate, QueryMatch> predicateCallback) {
309332
this.progressCallback = progressCallback;
310333
this.predicateCallback = predicateCallback;
311334
}

src/main/java/io/github/treesitter/jtreesitter/Range.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.github.treesitter.jtreesitter;
22

3+
import static io.github.treesitter.jtreesitter.internal.TreeSitter.*;
4+
35
import io.github.treesitter.jtreesitter.internal.TSRange;
6+
import java.lang.foreign.Arena;
47
import java.lang.foreign.MemorySegment;
58
import java.lang.foreign.SegmentAllocator;
69
import org.jspecify.annotations.NullMarked;
@@ -44,6 +47,20 @@ MemorySegment into(SegmentAllocator allocator) {
4447
return range;
4548
}
4649

50+
/**
51+
* Edit the range to keep it in-sync with source code that has been edited.
52+
*
53+
* <p>This function updates the range's byte offset and row/column position based on an edit
54+
* operation. This is useful for editing ranges without requiring a tree or node instance.
55+
*
56+
* @since 0.26.0
57+
*/
58+
public void edit(InputEdit edit) {
59+
try (var alloc = Arena.ofConfined()) {
60+
ts_range_edit(into(alloc), edit.into(alloc));
61+
}
62+
}
63+
4764
@Override
4865
public String toString() {
4966
return String.format(

0 commit comments

Comments
 (0)