Skip to content

Commit 0943c06

Browse files
Allow "return@" in Kotlin Tree sitter queries (#2752)
Fixes #2447 ## Checklist - [x] 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 34989d0 commit 0943c06

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

packages/cursorless-engine/src/languages/TreeSitterQuery/validateQueryCaptures.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ const testCases: { name: string; isOk: boolean; content: string }[] = [
5151
isOk: true,
5252
content: ";; (if_statement) @unknown",
5353
},
54+
{
55+
name: "@ ending string",
56+
isOk: true,
57+
content: '"return@"',
58+
},
5459
{
5560
name: "Unknown capture",
5661
isOk: false,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ for (const captureName of captureNames) {
5959
}
6060

6161
// Not a comment. ie line is not starting with `;;`
62+
// Not a string.
6263
// Capture starts with `@` and is followed by words and/or dots
63-
const capturePattern = new RegExp(`^(?!;;).*@([\\w.]*)`, "gm");
64+
const capturePattern = /^(?!;;).*(?<!"\w*)@([\w.]*)/gm;
6465

6566
export function validateQueryCaptures(file: string, rawQuery: string): void {
6667
const matches = rawQuery.matchAll(capturePattern);

queries/kotlin.scm

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,13 @@
437437
(_) @value
438438
) @_.domain
439439

440-
;; Disabled due to Cursorless error ("invalid capture") caused by "return@"
441-
;; (jump_expression
442-
;; "return@"
443-
;; .
444-
;; (label)
445-
;; .
446-
;; (_) @value
447-
;; ) @_.domain
440+
(jump_expression
441+
"return@"
442+
.
443+
(label)
444+
.
445+
(_) @value
446+
) @_.domain
448447

449448
(_
450449
(function_body

0 commit comments

Comments
 (0)