feat: add a patternIndex field to QueryCapture
This lets users look up the predicates associated with a given `QueryCapture`, by using the `patternIndex` field and calling `predicatesForPattern`
This commit is contained in:
parent
d60c6f163d
commit
e874d2d8f8
2 changed files with 19 additions and 10 deletions
|
|
@ -2,7 +2,7 @@ import { Edit, INTERNAL, Point, Range, SIZE_OF_INT, SIZE_OF_NODE, SIZE_OF_POINT,
|
|||
import { Node } from "./node";
|
||||
import { Tree } from "./tree";
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { Query, type QueryMatch } from "./query";
|
||||
import { Query, QueryCapture, type QueryMatch } from "./query";
|
||||
import { TreeCursor } from "./tree_cursor";
|
||||
import { TRANSFER_BUFFER } from "./parser";
|
||||
|
||||
|
|
@ -11,13 +11,19 @@ import { TRANSFER_BUFFER } from "./parser";
|
|||
*
|
||||
* Unmarshals a {@link QueryMatch} to the transfer buffer.
|
||||
*/
|
||||
export function unmarshalCaptures(query: Query, tree: Tree, address: number, result: {name: string, node: Node}[]) {
|
||||
export function unmarshalCaptures(
|
||||
query: Query,
|
||||
tree: Tree,
|
||||
address: number,
|
||||
patternIndex: number,
|
||||
result: QueryCapture[]
|
||||
) {
|
||||
for (let i = 0, n = result.length; i < n; i++) {
|
||||
const captureIndex = C.getValue(address, 'i32');
|
||||
address += SIZE_OF_INT;
|
||||
const node = unmarshalNode(tree, address)!;
|
||||
address += SIZE_OF_NODE;
|
||||
result[i] = {name: query.captureNames[captureIndex], node};
|
||||
result[i] = {patternIndex, name: query.captureNames[captureIndex], node};
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue