Skip to content

Commit 2b1bf99

Browse files
authored
add #log! query predicate (#1890)
This has proved useful as I struggle with treesitter queries. :) ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
1 parent 6ec84ad commit 2b1bf99

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ class AllowMultiple extends QueryPredicateOperator<AllowMultiple> {
161161
}
162162
}
163163

164+
/**
165+
* A predicate operator that logs a node, for debugging.
166+
*/
167+
class Log extends QueryPredicateOperator<Log> {
168+
name = "log!" as const;
169+
schema = z.tuple([q.node]);
170+
171+
run(nodeInfo: MutableQueryCapture) {
172+
console.log(`#log!: ${nodeInfo.name}@${nodeInfo.range}`);
173+
return true;
174+
}
175+
}
176+
164177
/**
165178
* A predicate operator that sets the insertion delimiter of the match. For
166179
* example, `(#insertion-delimiter! @foo ", ")` will set the insertion delimiter
@@ -178,6 +191,7 @@ class InsertionDelimiter extends QueryPredicateOperator<InsertionDelimiter> {
178191
}
179192

180193
export const queryPredicateOperators = [
194+
new Log(),
181195
new NotType(),
182196
new NotEmpty(),
183197
new NotParentType(),

0 commit comments

Comments
 (0)