From 891c3be3a55af8c8278a09bc8bf7f887505682e0 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 24 Mar 2022 12:53:44 +0000 Subject: [PATCH 1/3] Initial query experiments --- .vscode/tasks.json | 6 ++++ queries/typescript/scopeTypes.scm | 56 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 queries/typescript/scopeTypes.scm 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..821240a723 --- /dev/null +++ b/queries/typescript/scopeTypes.scm @@ -0,0 +1,56 @@ +(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) From 169038b0cb2a2278a8cc306431e777134605988b Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 24 Mar 2022 13:02:16 +0000 Subject: [PATCH 2/3] Tweak formatting --- queries/typescript/scopeTypes.scm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/queries/typescript/scopeTypes.scm b/queries/typescript/scopeTypes.scm index 821240a723..f767be8534 100644 --- a/queries/typescript/scopeTypes.scm +++ b/queries/typescript/scopeTypes.scm @@ -39,9 +39,10 @@ (pair key: (_) @key . - ":" @key.delimiter.trailing) - @key.searchScope) - @key.iterationScope) + ":" @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 @@ -51,6 +52,6 @@ (pair key: (_) @key (#set! "delimiter" ":") - ) - @key.searchScope) - @key.iterationScope) + ) @key.searchScope + ) @key.iterationScope +) From 41facd42400bdda5f487cf8a04699410bcf815df Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Apr 2022 13:11:12 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- queries/typescript/scopeTypes.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/typescript/scopeTypes.scm b/queries/typescript/scopeTypes.scm index f767be8534..36e6bf47d0 100644 --- a/queries/typescript/scopeTypes.scm +++ b/queries/typescript/scopeTypes.scm @@ -8,7 +8,7 @@ ; [ ; (arrow_function) ; (function) -; ] @anonymousFunction +; ] @anonymousFunction ; The following doesn't work because we can't have a `(` before the field name (`key`) ; (