Skip to content

Commit 4324f05

Browse files
feat(query): implement [gs]etTimeoutMicros
1 parent 800d736 commit 4324f05

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

scripts/jextract.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ $env:package = 'io.github.treesitter.jtreesitter.internal'
108108
--include-function ts_query_cursor_set_match_limit `
109109
--include-function ts_query_cursor_set_max_start_depth `
110110
--include-function ts_query_cursor_set_point_range `
111+
--include-function ts_query_cursor_set_timeout_micros `
112+
--include-function ts_query_cursor_timeout_micros `
111113
--include-function ts_query_delete `
112114
--include-function ts_query_disable_capture `
113115
--include-function ts_query_disable_pattern `

scripts/jextract.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ jextract \
108108
--include-function ts_query_cursor_set_match_limit \
109109
--include-function ts_query_cursor_set_max_start_depth \
110110
--include-function ts_query_cursor_set_point_range \
111+
--include-function ts_query_cursor_set_timeout_micros \
112+
--include-function ts_query_cursor_timeout_micros \
111113
--include-function ts_query_delete \
112114
--include-function ts_query_disable_capture \
113115
--include-function ts_query_disable_pattern \

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,25 @@ public Query setMatchLimit(@Unsigned int matchLimit) throws IllegalArgumentExcep
294294
return this;
295295
}
296296

297+
/**
298+
* Get the maximum duration in microseconds that query
299+
* execution should be allowed to take before halting.
300+
*
301+
* @apiNote Defaults to {@code 0} (unlimited).
302+
*/
303+
public @Unsigned long getTimeoutMicros() {
304+
return ts_query_cursor_timeout_micros(cursor);
305+
}
306+
307+
/**
308+
* Set the maximum duration in microseconds that query
309+
* execution should be allowed to take before halting.
310+
*/
311+
public Query setTimeoutMicros(@Unsigned long timeoutMicros) {
312+
ts_query_cursor_set_timeout_micros(cursor, timeoutMicros);
313+
return this;
314+
}
315+
297316
/**
298317
* Set the maximum start depth for the query.
299318
*

src/test/java/io/github/treesitter/jtreesitter/QueryTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@ void setMatchLimit() {
101101
});
102102
}
103103

104+
@Test
105+
void getTimeoutMicros() {
106+
assertQuery(query -> assertEquals(0, query.getTimeoutMicros()));
107+
}
108+
109+
@Test
110+
void setTimeoutMicros() {
111+
assertQuery(query -> {
112+
assertSame(query, query.setTimeoutMicros(10));
113+
assertEquals(10, query.getTimeoutMicros());
114+
});
115+
}
116+
104117
@Test
105118
void setMaxStartDepth() {
106119
assertQuery(query -> assertSame(query, query.setMaxStartDepth(10)));

0 commit comments

Comments
 (0)