This repository was archived by the owner on Oct 18, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/com/itsaky/androidide/treesitter
test/java/com/itsaky/androidide/treesitter Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1919
2020public class TSQuery implements AutoCloseable {
2121 final long pointer ;
22-
2322 private int errorOffset ;
2423 private int errorType ;
2524
25+ private String [] captureNames = null ;
26+
2627 /**
2728 * Create a new query from a string containing one or more S-expression patterns. The query is
2829 * associated with a particular language, and can only be run on syntax nodes parsed with that
@@ -72,6 +73,16 @@ public int getStringCount() {
7273 return Native .stringCount (this .pointer );
7374 }
7475
76+ public String [] getCaptureNames () {
77+ if (captureNames == null ) {
78+ captureNames = new String [getCaptureCount ()];
79+ for (int i = 0 ; i < getCaptureCount (); i ++) {
80+ captureNames [i ] = getCaptureNameForId (i );
81+ }
82+ }
83+ return captureNames ;
84+ }
85+
7586 public int getStartByteForPattern (int pattern ) {
7687 validatePatternIndex (pattern );
7788 return Native .startByteForPattern (this .pointer , pattern );
Original file line number Diff line number Diff line change @@ -55,6 +55,14 @@ public void queryTest() throws Exception {
5555 assertThat (match .getCaptures ()).isNotNull ();
5656 assertThat (match .getCaptures ()).hasLength (1 );
5757 assertThat (cursor .nextMatch ()).isNull ();
58+
59+ var captureNames = query .getCaptureNames ();
60+ assertThat (captureNames ).hasLength (query .getCaptureCount ());
61+ captureNames = new String [query .getCaptureCount ()];
62+ for (int i = 0 ; i < captureNames .length ; i ++) {
63+ captureNames [i ] = query .getCaptureNameForId (0 );
64+ }
65+
5866 query .close ();
5967 cursor .close ();
6068
@@ -66,6 +74,7 @@ public void queryTest() throws Exception {
6674 assertThat (match .getCaptures ()).isNotNull ();
6775 assertThat (match .getCaptures ()).hasLength (1 );
6876 assertThat (cursor .nextMatch ()).isNull ();
77+
6978 query .close ();
7079 cursor .close ();
7180 } catch (Throwable err ) {
You can’t perform that action at this time.
0 commit comments