From 8825ee05854c9cc0dd55b899f72e57db06a4a473 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 5 Feb 2025 17:28:18 +0100 Subject: [PATCH 1/4] Update javascript scope facets --- .../branch.switchCase.iteration.scope | 9 ++- .../branch.try.iteration.scope | 24 ++++++ .../condition.switchCase.iteration.scope | 21 +++++ .../name.iteration.document.scope | 10 +++ .../javascript.core/statement.class.scope | 10 +++ .../scopes/javascript.core/value.yield.scope | 20 +++++ .../src/scopeSupportFacets/javascript.ts | 80 ++++++++++++++++--- .../scopeSupportFacetInfos.ts | 6 +- .../src/scopeSupportFacets/typescript.ts | 5 -- queries/javascript.core.scm | 11 ++- 10 files changed, 174 insertions(+), 22 deletions(-) create mode 100644 data/fixtures/scopes/javascript.core/branch.try.iteration.scope create mode 100644 data/fixtures/scopes/javascript.core/condition.switchCase.iteration.scope create mode 100644 data/fixtures/scopes/javascript.core/name.iteration.document.scope create mode 100644 data/fixtures/scopes/javascript.core/statement.class.scope create mode 100644 data/fixtures/scopes/javascript.core/value.yield.scope diff --git a/data/fixtures/scopes/javascript.core/branch.switchCase.iteration.scope b/data/fixtures/scopes/javascript.core/branch.switchCase.iteration.scope index e01445e1cd..44cc4ad233 100644 --- a/data/fixtures/scopes/javascript.core/branch.switchCase.iteration.scope +++ b/data/fixtures/scopes/javascript.core/branch.switchCase.iteration.scope @@ -4,7 +4,14 @@ switch (value) { } --- -[Range] = +[Range] = 0:16-3:0 + > +0| switch (value) { +1| case 0: { } +2| case 1: { } +3| } + < + [Domain] = 0:0-3:1 >---------------- 0| switch (value) { diff --git a/data/fixtures/scopes/javascript.core/branch.try.iteration.scope b/data/fixtures/scopes/javascript.core/branch.try.iteration.scope new file mode 100644 index 0000000000..639da14aee --- /dev/null +++ b/data/fixtures/scopes/javascript.core/branch.try.iteration.scope @@ -0,0 +1,24 @@ +try { + a +} +catch (e) { + b +} +finally { + c +} +--- + +[Range] = +[Domain] = 0:0-8:1 + >----- +0| try { +1| a +2| } +3| catch (e) { +4| b +5| } +6| finally { +7| c +8| } + -< diff --git a/data/fixtures/scopes/javascript.core/condition.switchCase.iteration.scope b/data/fixtures/scopes/javascript.core/condition.switchCase.iteration.scope new file mode 100644 index 0000000000..44cc4ad233 --- /dev/null +++ b/data/fixtures/scopes/javascript.core/condition.switchCase.iteration.scope @@ -0,0 +1,21 @@ +switch (value) { + case 0: { } + case 1: { } +} +--- + +[Range] = 0:16-3:0 + > +0| switch (value) { +1| case 0: { } +2| case 1: { } +3| } + < + +[Domain] = 0:0-3:1 + >---------------- +0| switch (value) { +1| case 0: { } +2| case 1: { } +3| } + -< diff --git a/data/fixtures/scopes/javascript.core/name.iteration.document.scope b/data/fixtures/scopes/javascript.core/name.iteration.document.scope new file mode 100644 index 0000000000..bc004e6a9e --- /dev/null +++ b/data/fixtures/scopes/javascript.core/name.iteration.document.scope @@ -0,0 +1,10 @@ +const aaa = 2; + +--- + +[Range] = +[Domain] = 0:0-1:0 + >-------------- +0| const aaa = 2; +1| + < diff --git a/data/fixtures/scopes/javascript.core/statement.class.scope b/data/fixtures/scopes/javascript.core/statement.class.scope new file mode 100644 index 0000000000..8449ae4834 --- /dev/null +++ b/data/fixtures/scopes/javascript.core/statement.class.scope @@ -0,0 +1,10 @@ +class Foo { } +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| class Foo { } + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/value.yield.scope b/data/fixtures/scopes/javascript.core/value.yield.scope new file mode 100644 index 0000000000..b30ffd0db3 --- /dev/null +++ b/data/fixtures/scopes/javascript.core/value.yield.scope @@ -0,0 +1,20 @@ +yield 5; +--- + +[Content] = 0:6-0:7 + >-< +0| yield 5; + +[Removal] = 0:5-0:7 + >--< +0| yield 5; + +[Leading delimiter] = 0:5-0:6 + >-< +0| yield 5; + +[Domain] = 0:0-0:7 + >-------< +0| yield 5; + +[Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/javascript.ts b/packages/common/src/scopeSupportFacets/javascript.ts index 30eafa68b5..da8782545e 100644 --- a/packages/common/src/scopeSupportFacets/javascript.ts +++ b/packages/common/src/scopeSupportFacets/javascript.ts @@ -7,21 +7,25 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { list: supported, map: supported, - ifStatement: supported, regularExpression: supported, switchStatementSubject: supported, fieldAccess: supported, disqualifyDelimiter: supported, pairDelimiter: supported, + "collectionItem.unenclosed": supported, + "textFragment.string.singleLine": supported, "textFragment.string.multiLine": supported, "textFragment.comment.line": supported, "textFragment.comment.block": supported, + ifStatement: supported, + statement: supported, "statement.iteration.document": supported, "statement.iteration.block": supported, + "statement.class": supported, class: supported, className: supported, @@ -67,6 +71,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "branch.if": supported, "branch.if.iteration": supported, "branch.try": supported, + "branch.try.iteration": supported, "branch.switchCase": supported, "branch.switchCase.iteration": supported, "branch.ternary": supported, @@ -77,6 +82,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "condition.for": supported, "condition.ternary": supported, "condition.switchCase": supported, + "condition.switchCase.iteration": supported, "name.argument.formal": supported, "name.argument.formal.iteration": supported, @@ -94,6 +100,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "name.constructor": supported, "name.class": supported, "name.field": supported, + "name.iteration.document": supported, "key.mapPair": supported, "key.mapPair.iteration": supported, @@ -113,8 +120,52 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "value.return": supported, "value.return.lambda": supported, "value.field": supported, - - "collectionItem.unenclosed": supported, + "value.yield": supported, + + // Unsupported + + "collectionItem.unenclosed.iteration": unsupported, + "branch.loop": unsupported, + "namedFunction.iteration": unsupported, + "functionName.iteration": unsupported, + + "class.iteration.block": unsupported, + "class.iteration.document": unsupported, + "className.iteration.block": unsupported, + "className.iteration.document": unsupported, + + "name.iteration.block": unsupported, + "name.resource": unsupported, + "name.resource.iteration": unsupported, + + "value.resource": unsupported, + "value.resource.iteration": unsupported, + + "interior.class": unsupported, + "interior.function": unsupported, + "interior.if": unsupported, + "interior.lambda": unsupported, + "interior.loop": unsupported, + "interior.switchCase": unsupported, + "interior.ternary": unsupported, + "interior.try": unsupported, + "interior.with": unsupported, + + // Not applicable + + "interior.cell": notApplicable, + "interior.command": notApplicable, + "name.argument.actual.iteration": notApplicable, + "name.argument.actual": notApplicable, + "value.argument.actual": notApplicable, + "value.argument.actual.iteration": notApplicable, + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + "textFragment.element": notApplicable, + command: notApplicable, + environment: notApplicable, + notebookCell: notApplicable, + section: notApplicable, }; export const javascriptJsxScopeSupport: LanguageScopeSupportFacetMap = { @@ -132,16 +183,25 @@ export const javascriptScopeSupport: LanguageScopeSupportFacetMap = { ...javascriptCoreScopeSupport, ...javascriptJsxScopeSupport, - "type.variable": notApplicable, - "type.argument.formal": notApplicable, + // Types are defined here because we don't want typescript to import them and + // accidentally forget to add support for them. + "value.typeAlias": notApplicable, + "type.alias": notApplicable, + "type.argument.formal.constructor.iteration": notApplicable, + "type.argument.formal.constructor": notApplicable, "type.argument.formal.iteration": notApplicable, - "type.argument.formal.method": notApplicable, "type.argument.formal.method.iteration": notApplicable, - "type.argument.formal.constructor": notApplicable, - "type.argument.formal.constructor.iteration": notApplicable, - "type.return": notApplicable, + "type.argument.formal.method": notApplicable, + "type.argument.formal": notApplicable, + "type.cast": notApplicable, + "type.class": notApplicable, + "type.enum": notApplicable, + "type.field.iteration": notApplicable, "type.field": notApplicable, "type.foreach": notApplicable, "type.interface": notApplicable, - command: notApplicable, + "type.return": notApplicable, + "type.typeArgument.iteration": notApplicable, + "type.typeArgument": notApplicable, + "type.variable": notApplicable, }; diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 76b56e95bd..8b49503b04 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -149,7 +149,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "namedFunction", }, "namedFunction.iteration": { - description: "Iteration scope for named functions", + description: "Iteration scope for named functions: code blocks", scopeType: "namedFunction", isIteration: true, }, @@ -172,7 +172,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "functionName", }, "functionName.method.iteration.class": { - description: "Iteration scope for function names: class bodies", + description: "Iteration scope for method names: class bodies", scopeType: "functionName", isIteration: true, }, @@ -181,7 +181,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "functionName", }, "functionName.iteration": { - description: "Iteration scope for function names", + description: "Iteration scope for function names: code blocks", scopeType: "functionName", isIteration: true, }, diff --git a/packages/common/src/scopeSupportFacets/typescript.ts b/packages/common/src/scopeSupportFacets/typescript.ts index 7dd70a41ae..9e259a71b1 100644 --- a/packages/common/src/scopeSupportFacets/typescript.ts +++ b/packages/common/src/scopeSupportFacets/typescript.ts @@ -7,8 +7,6 @@ const { supported } = ScopeSupportFacetLevel; export const typescriptScopeSupport: LanguageScopeSupportFacetMap = { ...javascriptCoreScopeSupport, - "name.field": supported, - "type.argument.formal": supported, "type.argument.formal.iteration": supported, "type.argument.formal.method": supported, @@ -23,8 +21,5 @@ export const typescriptScopeSupport: LanguageScopeSupportFacetMap = { "type.return": supported, "type.variable": supported, - "value.field": supported, "value.typeAlias": supported, - - disqualifyDelimiter: supported, }; diff --git a/queries/javascript.core.scm b/queries/javascript.core.scm index 510179ed0c..9c4b3479ec 100644 --- a/queries/javascript.core.scm +++ b/queries/javascript.core.scm @@ -607,9 +607,14 @@ (switch_default) @branch -;;!! switch () {} -;;! ^^^^^^^^^^^^ -(switch_statement) @branch.iteration @condition.iteration +;;!! switch () { } +;;! ^ +(switch_statement + body: (_ + "{" @branch.iteration.start.endOf @condition.iteration.start.endOf + "}" @branch.iteration.end.startOf @condition.iteration.end.startOf + ) +) @branch.iteration.domain @condition.iteration.domain ;;!! if () {} ;;! ^^^^^^^^ From da12886b82eca8f7247b5d1337ed7d78ad55717c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 6 Feb 2025 01:52:52 +0100 Subject: [PATCH 2/4] Update pattern --- queries/javascript.core.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/queries/javascript.core.scm b/queries/javascript.core.scm index 9c4b3479ec..d4ce227e94 100644 --- a/queries/javascript.core.scm +++ b/queries/javascript.core.scm @@ -611,8 +611,10 @@ ;;! ^ (switch_statement body: (_ + . "{" @branch.iteration.start.endOf @condition.iteration.start.endOf "}" @branch.iteration.end.startOf @condition.iteration.end.startOf + . ) ) @branch.iteration.domain @condition.iteration.domain From ff3acb2f5cca7a538e062d8ff094a9a6944a33c7 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 6 Feb 2025 17:22:54 +0100 Subject: [PATCH 3/4] Rename --- packages/common/src/scopeSupportFacets/javascript.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/javascript.ts b/packages/common/src/scopeSupportFacets/javascript.ts index da8782545e..ba769f4c42 100644 --- a/packages/common/src/scopeSupportFacets/javascript.ts +++ b/packages/common/src/scopeSupportFacets/javascript.ts @@ -126,8 +126,8 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "collectionItem.unenclosed.iteration": unsupported, "branch.loop": unsupported, - "namedFunction.iteration": unsupported, - "functionName.iteration": unsupported, + "namedFunction.iteration.block": unsupported, + "functionName.iteration.block": unsupported, "class.iteration.block": unsupported, "class.iteration.document": unsupported, From cf6e9d67e6517ed399c06fd039a534f5638cfa2b Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 6 Feb 2025 17:23:28 +0100 Subject: [PATCH 4/4] More renames --- packages/common/src/scopeSupportFacets/javascript.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/scopeSupportFacets/javascript.ts b/packages/common/src/scopeSupportFacets/javascript.ts index ba769f4c42..5bce8eed13 100644 --- a/packages/common/src/scopeSupportFacets/javascript.ts +++ b/packages/common/src/scopeSupportFacets/javascript.ts @@ -149,7 +149,7 @@ export const javascriptCoreScopeSupport: LanguageScopeSupportFacetMap = { "interior.switchCase": unsupported, "interior.ternary": unsupported, "interior.try": unsupported, - "interior.with": unsupported, + "interior.resource": unsupported, // Not applicable