diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 1388ca7403..67a47d51a3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -41,6 +41,12 @@ "reveal": "never" }, "group": "build" + }, + { + "label": "Parse quarry", + "type": "shell", + "command": "npx tree-sitter query scopeTypes.scm ts-test.ts", + "presentation": {} } ] } diff --git a/queries/typescript/scopeTypes.scm b/queries/typescript/scopeTypes.scm new file mode 100644 index 0000000000..36e6bf47d0 --- /dev/null +++ b/queries/typescript/scopeTypes.scm @@ -0,0 +1,57 @@ +(object) @map + +(arrow_function) @anonymousFunction +(function) @anonymousFunction + +; We could also have used an alternation here, but the above style is clean and +; seems to be more commonly used. +; [ +; (arrow_function) +; (function) +; ] @anonymousFunction + +; The following doesn't work because we can't have a `(` before the field name (`key`) +; ( +; (object +; (pair +; (key: (_) @key +; . +; ":") @key.removalRange +; ) @key.searchScope +; ) @key.iterationScope +; ) + +; As a workaround, we could allow defining the end of an annotation +( + (object + (pair + key: (_) @key + . + ":" @key.removalRange.end + ) @key.searchScope + ) @key.iterationScope +) + +; We could instead tag the delimiter itself. Gives us a bit more information, +; so maybe that's better? +( + (object + (pair + key: (_) @key + . + ":" @key.delimiter.trailing + ) @key.searchScope + ) @key.iterationScope +) + +; We could also try setting an attribute. This approach is likely how we'd +; handle comma-separated lists, because they'd be a bit painful to define as +; parse tree patterns +( + (object + (pair + key: (_) @key + (#set! "delimiter" ":") + ) @key.searchScope + ) @key.iterationScope +)