From a8c0b21c4cd4acbf4a834d973e09e2d5fc0ecdcc Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 10:41:45 +0100 Subject: [PATCH 01/12] Started working on r scope facets --- .../scopes/r/{ => name}/name.assignment.scope | 0 .../r/{ => name}/name.assignment2.scope | 0 .../scopes/r/{ => name}/name.function.scope | 0 .../name.variable.initialized.scope | 0 .../r/{ => value}/value.assignment.scope | 0 .../r/{ => value}/value.assignment2.scope | 0 .../scopes/r/{ => value}/value.variable.scope | 0 packages/common/src/scopeSupportFacets/r.ts | 370 ++++++++++++++---- 8 files changed, 299 insertions(+), 71 deletions(-) rename data/fixtures/scopes/r/{ => name}/name.assignment.scope (100%) rename data/fixtures/scopes/r/{ => name}/name.assignment2.scope (100%) rename data/fixtures/scopes/r/{ => name}/name.function.scope (100%) rename data/fixtures/scopes/r/{ => name}/name.variable.initialized.scope (100%) rename data/fixtures/scopes/r/{ => value}/value.assignment.scope (100%) rename data/fixtures/scopes/r/{ => value}/value.assignment2.scope (100%) rename data/fixtures/scopes/r/{ => value}/value.variable.scope (100%) diff --git a/data/fixtures/scopes/r/name.assignment.scope b/data/fixtures/scopes/r/name/name.assignment.scope similarity index 100% rename from data/fixtures/scopes/r/name.assignment.scope rename to data/fixtures/scopes/r/name/name.assignment.scope diff --git a/data/fixtures/scopes/r/name.assignment2.scope b/data/fixtures/scopes/r/name/name.assignment2.scope similarity index 100% rename from data/fixtures/scopes/r/name.assignment2.scope rename to data/fixtures/scopes/r/name/name.assignment2.scope diff --git a/data/fixtures/scopes/r/name.function.scope b/data/fixtures/scopes/r/name/name.function.scope similarity index 100% rename from data/fixtures/scopes/r/name.function.scope rename to data/fixtures/scopes/r/name/name.function.scope diff --git a/data/fixtures/scopes/r/name.variable.initialized.scope b/data/fixtures/scopes/r/name/name.variable.initialized.scope similarity index 100% rename from data/fixtures/scopes/r/name.variable.initialized.scope rename to data/fixtures/scopes/r/name/name.variable.initialized.scope diff --git a/data/fixtures/scopes/r/value.assignment.scope b/data/fixtures/scopes/r/value/value.assignment.scope similarity index 100% rename from data/fixtures/scopes/r/value.assignment.scope rename to data/fixtures/scopes/r/value/value.assignment.scope diff --git a/data/fixtures/scopes/r/value.assignment2.scope b/data/fixtures/scopes/r/value/value.assignment2.scope similarity index 100% rename from data/fixtures/scopes/r/value.assignment2.scope rename to data/fixtures/scopes/r/value/value.assignment2.scope diff --git a/data/fixtures/scopes/r/value.variable.scope b/data/fixtures/scopes/r/value/value.variable.scope similarity index 100% rename from data/fixtures/scopes/r/value.variable.scope rename to data/fixtures/scopes/r/value/value.variable.scope diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 5a1f796544..3e7e1e3a24 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -1,16 +1,25 @@ import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; +const { supported, notApplicable } = ScopeSupportFacetLevel; export const rScopeSupport: LanguageScopeSupportFacetMap = { + disqualifyDelimiter: supported, anonymousFunction: supported, + list: supported, + "argument.actual.singleLine": supported, "argument.actual.multiLine": supported, "argument.actual.iteration": supported, + "argument.actual.method.singleLine": supported, + "argument.actual.method.multiLine": supported, + "argument.actual.method.iteration": supported, "argument.formal.singleLine": supported, "argument.formal.multiLine": supported, "argument.formal.iteration": supported, + "argument.formal.lambda.singleLine": supported, + "argument.formal.lambda.multiLine": supported, + "argument.formal.lambda.iteration": supported, "argumentList.actual.empty": supported, "argumentList.actual.singleLine": supported, @@ -25,105 +34,324 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.lambda.singleLine": supported, "argumentList.formal.lambda.multiLine": supported, + "collectionItem.unenclosed.singleLine": supported, + "collectionItem.unenclosed.multiLine": supported, + "collectionItem.unenclosed.iteration": supported, + + "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, + "branch.if.iteration": supported, + "branch.try": supported, + "branch.try.iteration": supported, + "branch.switchCase": supported, + "branch.switchCase.iteration": supported, + + "comment.line": supported, + + "condition.if": supported, + "condition.while": supported, + functionCall: supported, "functionCall.method": supported, functionCallee: supported, "functionCallee.method": supported, - "comment.line": supported, ifStatement: supported, + + "statement.function": supported, + "statement.functionCall": supported, + "statement.if": supported, + "statement.try": supported, + "statement.switch": supported, + "statement.foreach": supported, + "statement.while": supported, + "statement.assignment": supported, + "statement.variable.initialized": supported, + "statement.return": supported, + "statement.break": supported, + "statement.continue": supported, + "statement.misc": supported, + "statement.iteration.document": supported, + "statement.iteration.block": supported, + + "string.singleLine": supported, + "string.multiLine": supported, + + "textFragment.comment.line": supported, + "textFragment.string.singleLine": supported, + "textFragment.string.multiLine": supported, + + "name.argument.actual": supported, + "name.argument.actual.iteration": supported, + "name.argument.formal": supported, + "name.argument.formal.iteration": supported, + "name.argument.formal.lambda": supported, + "name.argument.formal.lambda.iteration": supported, "name.assignment": supported, "name.function": supported, "name.variable.initialized": supported, + "name.foreach": supported, + "name.iteration.document": supported, + "name.iteration.block": supported, + namedFunction: supported, + "namedFunction.iteration.document": supported, + + "value.argument.actual": supported, + "value.argument.actual.iteration": supported, + "value.argument.formal": supported, + "value.argument.formal.iteration": supported, "value.assignment": supported, + "value.foreach": supported, + "value.return": supported, + "value.switch": supported, "value.variable": supported, + "value.iteration.document": supported, + "value.iteration.block": supported, - // Unsupported - - "branch.if": unsupported, - "branch.if.iteration": unsupported, - "branch.switchCase": unsupported, - "branch.switchCase.iteration": unsupported, - "branch.ternary": unsupported, - "branch.ternary.iteration": unsupported, - "branch.try": unsupported, - "branch.try.iteration": unsupported, - "condition.for": unsupported, - "condition.if": unsupported, - "condition.ternary": unsupported, - "condition.while": unsupported, - "interior.class": unsupported, - "interior.function": unsupported, - "interior.if": unsupported, - "interior.lambda": unsupported, - "interior.try": unsupported, - "key.attribute": unsupported, - "name.class": unsupported, - "name.field.class": unsupported, - "name.foreach": unsupported, - "name.method": unsupported, - "statement.class": unsupported, - "string.multiLine": unsupported, - "string.singleLine": unsupported, - "value.attribute": unsupported, - "value.foreach": unsupported, - "value.return": unsupported, - "value.switch": unsupported, - attribute: unsupported, - class: unsupported, - environment: unsupported, - fieldAccess: unsupported, - map: unsupported, - regularExpression: unsupported, - - // Not applicable - - // Chained function calls - "functionCall.chain": notApplicable, - "functionCallee.chain": notApplicable, + fieldAccess: supported, + + "interior.function": supported, + "interior.lambda": supported, + "interior.if": supported, + "interior.try": supported, + "interior.switch": supported, + "interior.foreach": supported, + "interior.while": supported, + + /* NOT APPLICABLE */ + + // Assignment + "statement.assignment.compound": notApplicable, + "statement.assignment.destructuring": notApplicable, + "name.assignment.compound": notApplicable, + "name.assignment.destructuring": notApplicable, + "value.assignment.compound": notApplicable, + "value.assignment.destructuring": notApplicable, + "statement.update": notApplicable, - // Uninitialized variables + // Variable "statement.variable.uninitialized": notApplicable, + "statement.variable.destructuring": notApplicable, "name.variable.uninitialized": notApplicable, + "name.variable.destructuring": notApplicable, "type.variable.uninitialized": notApplicable, + "type.variable.initialized": notApplicable, + "value.variable.destructuring": notApplicable, - "interior.cell": notApplicable, - "interior.command": notApplicable, - "interior.element": notApplicable, - "name.assignment.destructuring": notApplicable, - "branch.loop": notApplicable, - "branch.loop.iteration": notApplicable, + // Constant + "statement.constant": notApplicable, + "name.constant": notApplicable, + "value.constant": notApplicable, + "type.constant": notApplicable, - // Not applicable for base language but might be useful for markdown or quarto - "section.iteration.document": notApplicable, - "section.iteration.parent": notApplicable, - "type.alias": notApplicable, - "type.argument.formal": notApplicable, + // Class + class: notApplicable, + "class.iteration.block": notApplicable, + "class.iteration.document": notApplicable, + "name.class": notApplicable, + "name.field.class": notApplicable, + "name.iteration.class": notApplicable, + "statement.class": notApplicable, + "statement.field.class": notApplicable, + "statement.iteration.class": notApplicable, + "value.field.class": notApplicable, + "value.iteration.class": notApplicable, + "type.class": notApplicable, + "type.field.class": notApplicable, + "type.iteration.class": notApplicable, + "interior.class": notApplicable, + + // Constructor + "statement.constructor": notApplicable, + "namedFunction.constructor": notApplicable, + "argument.formal.constructor.singleLine": notApplicable, + "argument.formal.constructor.multiLine": notApplicable, + "argument.formal.constructor.iteration": notApplicable, + "argumentList.formal.constructor.empty": notApplicable, + "argumentList.formal.constructor.singleLine": notApplicable, + "argumentList.formal.constructor.multiLine": notApplicable, + "interior.constructor": notApplicable, + "name.argument.formal.constructor": notApplicable, + "name.argument.formal.constructor.iteration": notApplicable, + "name.constructor": notApplicable, "type.argument.formal.constructor": notApplicable, "type.argument.formal.constructor.iteration": notApplicable, - "type.argument.formal.iteration": notApplicable, + "value.argument.formal.constructor": notApplicable, + "value.argument.formal.constructor.iteration": notApplicable, + "functionCall.constructor": notApplicable, + "functionCallee.constructor": notApplicable, + + // Method + "statement.method": notApplicable, + "namedFunction.method": notApplicable, + "argument.formal.method.singleLine": notApplicable, + "argument.formal.method.multiLine": notApplicable, + "argument.formal.method.iteration": notApplicable, + "argumentList.formal.method.empty": notApplicable, + "argumentList.formal.method.singleLine": notApplicable, + "argumentList.formal.method.multiLine": notApplicable, + "interior.method": notApplicable, + "name.argument.formal.method": notApplicable, + "name.argument.formal.method.iteration": notApplicable, + "name.method": notApplicable, "type.argument.formal.method": notApplicable, "type.argument.formal.method.iteration": notApplicable, - "type.cast": notApplicable, - "type.class": notApplicable, - "type.enum": notApplicable, - "type.field.class": notApplicable, - "type.foreach": notApplicable, - "type.interface": notApplicable, + "type.return.method": notApplicable, + "value.argument.formal.method": notApplicable, + "value.argument.formal.method.iteration": notApplicable, + + // Function (class-contained variants) + "namedFunction.iteration.class": notApplicable, + + // Catch parameter + "argument.catch": notApplicable, + "name.argument.catch": notApplicable, + "type.argument.catch": notApplicable, + + // Type + "type.argument.formal": notApplicable, + "type.argument.formal.iteration": notApplicable, + "type.argument.formal.lambda": notApplicable, + "type.argument.formal.lambda.iteration": notApplicable, "type.return": notApplicable, + "type.foreach": notApplicable, "type.resource": notApplicable, - "type.iteration.class": notApplicable, "type.typeArgument": notApplicable, "type.typeArgument.iteration": notApplicable, - "type.variable.initialized": notApplicable, + "type.cast": notApplicable, + "type.iteration.block": notApplicable, + "type.iteration.document": notApplicable, + + // Interface + "statement.interface": notApplicable, + "statement.field.interface": notApplicable, + "statement.iteration.interface": notApplicable, + "interior.interface": notApplicable, + "name.interface": notApplicable, + "name.field.interface": notApplicable, + "name.iteration.interface": notApplicable, + "type.interface": notApplicable, + "type.field.interface": notApplicable, + "value.field.interface": notApplicable, + "type.iteration.interface": notApplicable, + + // Enum + "statement.enum": notApplicable, + "functionCallee.enum": notApplicable, + "functionCall.enum": notApplicable, + "name.enum": notApplicable, + "name.field.enum": notApplicable, + "name.iteration.enum": notApplicable, + "value.field.enum": notApplicable, + "value.iteration.enum": notApplicable, + "type.enum": notApplicable, + "interior.enum": notApplicable, + + // Function call + "functionCall.chain": notApplicable, + "functionCallee.chain": notApplicable, + "functionCall.generic": notApplicable, + "functionCallee.generic": notApplicable, + + // Return statement + "value.return.lambda": notApplicable, + + // Yield statement + "statement.yield": notApplicable, + "value.yield": notApplicable, + + // Throw statement + "statement.throw": notApplicable, + "value.throw": notApplicable, + + // Loop + "branch.loop": notApplicable, + "branch.loop.iteration": notApplicable, + + // For loop + "statement.for": notApplicable, + "condition.for": notApplicable, + "interior.for": notApplicable, + + // While loop branch not applicable in R + "statement.doWhile": notApplicable, + "condition.doWhile": notApplicable, + "interior.doWhile": notApplicable, + + // Resource statement + "statement.resource": notApplicable, + "interior.resource": notApplicable, + "name.resource": notApplicable, + "value.resource": notApplicable, + + // Static + "statement.static": notApplicable, + "interior.static": notApplicable, + + // Namespace + "statement.namespace": notApplicable, + "interior.namespace": notApplicable, + "name.namespace": notApplicable, + + // Ternary + "branch.ternary": notApplicable, + "branch.ternary.iteration": notApplicable, + "condition.ternary": notApplicable, + + // Type alias + "type.alias": notApplicable, + "statement.typeAlias": notApplicable, + "name.typeAlias": notApplicable, "value.typeAlias": notApplicable, - "value.variable.destructuring": notApplicable, - command: notApplicable, + + // Map + map: notApplicable, + "key.mapPair": notApplicable, + "key.mapPair.iteration": notApplicable, + "value.mapPair": notApplicable, + "value.mapPair.iteration": notApplicable, + + // Section + section: notApplicable, + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + + // Element element: notApplicable, + "interior.element": notApplicable, + "textFragment.element": notApplicable, + tags: notApplicable, + startTag: notApplicable, endTag: notApplicable, + + // Attribute + attribute: notApplicable, + "key.attribute": notApplicable, + "value.attribute": notApplicable, + + // Command + command: notApplicable, + "statement.command": notApplicable, + "name.command": notApplicable, + "value.command": notApplicable, + "interior.command": notApplicable, + + // Notebook cell notebookCell: notApplicable, - section: notApplicable, - startTag: notApplicable, - tags: notApplicable, + "interior.cell": notApplicable, + + // Miscellaneous statements + "statement.package": notApplicable, + "statement.import": notApplicable, + + // Miscellaneous + "comment.block": notApplicable, + "textFragment.comment.block": notApplicable, + environment: notApplicable, + pairDelimiter: notApplicable, + regularExpression: notApplicable, + selector: notApplicable, + unit: notApplicable, }; From 3230362ecb708bb2acc9c6e000a53eeda126ef8b Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 11:59:57 +0100 Subject: [PATCH 02/12] more tests --- data/fixtures/scopes/r/condition.if.scope | 32 ++++ data/fixtures/scopes/r/condition.while.scope | 13 ++ data/fixtures/scopes/r/list.scope | 10 + .../name/name.argument.actual.iteration.scope | 13 ++ .../scopes/r/name/name.argument.actual.scope | 39 ++++ .../name/name.argument.formal.iteration.scope | 13 ++ .../fixtures/scopes/r/name/name.foreach.scope | 20 ++ .../r/name/name.iteration.document.scope | 12 ++ .../r/namedFunction.iteration.document.scope | 12 ++ .../scopes/r/statement/statement.break.scope | 33 ++++ .../r/statement/statement.continue.scope | 33 ++++ .../r/statement/statement.foreach.scope | 10 + .../r/statement/statement.function.scope | 10 + .../r/statement/statement.functionCall.scope | 10 + .../scopes/r/statement/statement.if.scope | 15 ++ .../statement.iteration.document.scope | 12 ++ .../scopes/r/statement/statement.return.scope | 21 +++ .../scopes/r/statement/statement.switch.scope | 10 + .../scopes/r/statement/statement.try.scope | 10 + .../statement.variable.initialized.scope | 10 + .../scopes/r/statement/statement.while.scope | 10 + data/fixtures/scopes/r/string.multiLine.scope | 13 ++ .../fixtures/scopes/r/string.singleLine.scope | 10 + .../scopes/r/textFragment.comment.line.scope | 10 + .../r/textFragment.string.multiLine.scope | 13 ++ .../r/textFragment.string.singleLine.scope | 10 + .../value.argument.actual.iteration.scope | 13 ++ .../r/value/value.argument.actual.scope | 39 ++++ .../scopes/r/value/value.foreach.scope | 20 ++ .../scopes/r/value/value.return.scope | 15 ++ packages/common/src/scopeSupportFacets/r.ts | 2 +- queries/java.scm | 2 +- queries/r.scm | 173 ++++++++++++------ 33 files changed, 608 insertions(+), 60 deletions(-) create mode 100644 data/fixtures/scopes/r/condition.if.scope create mode 100644 data/fixtures/scopes/r/condition.while.scope create mode 100644 data/fixtures/scopes/r/list.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.actual.iteration.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.actual.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/r/name/name.foreach.scope create mode 100644 data/fixtures/scopes/r/name/name.iteration.document.scope create mode 100644 data/fixtures/scopes/r/namedFunction.iteration.document.scope create mode 100644 data/fixtures/scopes/r/statement/statement.break.scope create mode 100644 data/fixtures/scopes/r/statement/statement.continue.scope create mode 100644 data/fixtures/scopes/r/statement/statement.foreach.scope create mode 100644 data/fixtures/scopes/r/statement/statement.function.scope create mode 100644 data/fixtures/scopes/r/statement/statement.functionCall.scope create mode 100644 data/fixtures/scopes/r/statement/statement.if.scope create mode 100644 data/fixtures/scopes/r/statement/statement.iteration.document.scope create mode 100644 data/fixtures/scopes/r/statement/statement.return.scope create mode 100644 data/fixtures/scopes/r/statement/statement.switch.scope create mode 100644 data/fixtures/scopes/r/statement/statement.try.scope create mode 100644 data/fixtures/scopes/r/statement/statement.variable.initialized.scope create mode 100644 data/fixtures/scopes/r/statement/statement.while.scope create mode 100644 data/fixtures/scopes/r/string.multiLine.scope create mode 100644 data/fixtures/scopes/r/string.singleLine.scope create mode 100644 data/fixtures/scopes/r/textFragment.comment.line.scope create mode 100644 data/fixtures/scopes/r/textFragment.string.multiLine.scope create mode 100644 data/fixtures/scopes/r/textFragment.string.singleLine.scope create mode 100644 data/fixtures/scopes/r/value/value.argument.actual.iteration.scope create mode 100644 data/fixtures/scopes/r/value/value.argument.actual.scope create mode 100644 data/fixtures/scopes/r/value/value.foreach.scope create mode 100644 data/fixtures/scopes/r/value/value.return.scope diff --git a/data/fixtures/scopes/r/condition.if.scope b/data/fixtures/scopes/r/condition.if.scope new file mode 100644 index 0000000000..7427e144ae --- /dev/null +++ b/data/fixtures/scopes/r/condition.if.scope @@ -0,0 +1,32 @@ +if (TRUE) { +} else if (FALSE) { +} else {} +--- + +[#1 Content] = +[#1 Removal] = 0:4-0:8 + >----< +0| if (TRUE) { + +[#1 Domain] = 0:0-2:9 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else {} + ---------< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 1:11-1:16 + >-----< +1| } else if (FALSE) { + +[#2 Domain] = 1:2-2:1 + >----------------- +1| } else if (FALSE) { +2| } else {} + -< + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/condition.while.scope b/data/fixtures/scopes/r/condition.while.scope new file mode 100644 index 0000000000..2bea324508 --- /dev/null +++ b/data/fixtures/scopes/r/condition.while.scope @@ -0,0 +1,13 @@ +while (TRUE) {} +--- + +[Content] = +[Removal] = 0:7-0:11 + >----< +0| while (TRUE) {} + +[Domain] = 0:0-0:15 + >---------------< +0| while (TRUE) {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/list.scope b/data/fixtures/scopes/r/list.scope new file mode 100644 index 0000000000..b52f10a913 --- /dev/null +++ b/data/fixtures/scopes/r/list.scope @@ -0,0 +1,10 @@ +list(1, 2, 3) +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| list(1, 2, 3) + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name/name.argument.actual.iteration.scope b/data/fixtures/scopes/r/name/name.argument.actual.iteration.scope new file mode 100644 index 0000000000..546c765209 --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.actual.iteration.scope @@ -0,0 +1,13 @@ +foo(aaa = 0, bbb = 1) +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:21 + >---------------------< +0| foo(aaa = 0, bbb = 1) + + +[#2 Content] = +[#2 Domain] = 0:4-0:20 + >----------------< +0| foo(aaa = 0, bbb = 1) diff --git a/data/fixtures/scopes/r/name/name.argument.actual.scope b/data/fixtures/scopes/r/name/name.argument.actual.scope new file mode 100644 index 0000000000..4f658f672e --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.actual.scope @@ -0,0 +1,39 @@ +foo(aaa = 0, bbb = 1) +--- + +[#1 Content] = 0:4-0:7 + >---< +0| foo(aaa = 0, bbb = 1) + +[#1 Removal] = 0:4-0:10 + >------< +0| foo(aaa = 0, bbb = 1) + +[#1 Trailing delimiter] = 0:7-0:10 + >---< +0| foo(aaa = 0, bbb = 1) + +[#1 Domain] = 0:4-0:11 + >-------< +0| foo(aaa = 0, bbb = 1) + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:13-0:16 + >---< +0| foo(aaa = 0, bbb = 1) + +[#2 Removal] = 0:13-0:19 + >------< +0| foo(aaa = 0, bbb = 1) + +[#2 Trailing delimiter] = 0:16-0:19 + >---< +0| foo(aaa = 0, bbb = 1) + +[#2 Domain] = 0:13-0:20 + >-------< +0| foo(aaa = 0, bbb = 1) + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name/name.argument.formal.iteration.scope b/data/fixtures/scopes/r/name/name.argument.formal.iteration.scope new file mode 100644 index 0000000000..1a73d43ddb --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.formal.iteration.scope @@ -0,0 +1,13 @@ +function(aaa, bbb) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:21 + >---------------------< +0| function(aaa, bbb) {} + + +[#2 Content] = +[#2 Domain] = 0:9-0:17 + >--------< +0| function(aaa, bbb) {} diff --git a/data/fixtures/scopes/r/name/name.foreach.scope b/data/fixtures/scopes/r/name/name.foreach.scope new file mode 100644 index 0000000000..e71717e127 --- /dev/null +++ b/data/fixtures/scopes/r/name/name.foreach.scope @@ -0,0 +1,20 @@ +for (v in values) {} +--- + +[Content] = 0:5-0:6 + >-< +0| for (v in values) {} + +[Removal] = 0:5-0:7 + >--< +0| for (v in values) {} + +[Trailing delimiter] = 0:6-0:7 + >-< +0| for (v in values) {} + +[Domain] = 0:0-0:20 + >--------------------< +0| for (v in values) {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name/name.iteration.document.scope b/data/fixtures/scopes/r/name/name.iteration.document.scope new file mode 100644 index 0000000000..affbd59dcb --- /dev/null +++ b/data/fixtures/scopes/r/name/name.iteration.document.scope @@ -0,0 +1,12 @@ + +foo <- 0 + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| foo <- 0 +2| + < diff --git a/data/fixtures/scopes/r/namedFunction.iteration.document.scope b/data/fixtures/scopes/r/namedFunction.iteration.document.scope new file mode 100644 index 0000000000..1a239c74ff --- /dev/null +++ b/data/fixtures/scopes/r/namedFunction.iteration.document.scope @@ -0,0 +1,12 @@ + +foo <- function() {} + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| foo <- function() {} +2| + < diff --git a/data/fixtures/scopes/r/statement/statement.break.scope b/data/fixtures/scopes/r/statement/statement.break.scope new file mode 100644 index 0000000000..ef8c186345 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.break.scope @@ -0,0 +1,33 @@ +while (TRUE) { + break +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >-------------- +0| while (TRUE) { +1| break +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:9 + >-----< +1| break + +[#2 Removal] = 1:0-2:0 + >--------- +1| break +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| break + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.continue.scope b/data/fixtures/scopes/r/statement/statement.continue.scope new file mode 100644 index 0000000000..cae3260c14 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.continue.scope @@ -0,0 +1,33 @@ +while (TRUE) { + next +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >-------------- +0| while (TRUE) { +1| next +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:8 + >----< +1| next + +[#2 Removal] = 1:0-2:0 + >-------- +1| next +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| next + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.foreach.scope b/data/fixtures/scopes/r/statement/statement.foreach.scope new file mode 100644 index 0000000000..8b146d89ba --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.foreach.scope @@ -0,0 +1,10 @@ +for (v in values) {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:20 + >--------------------< +0| for (v in values) {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.function.scope b/data/fixtures/scopes/r/statement/statement.function.scope new file mode 100644 index 0000000000..950c1f1750 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.function.scope @@ -0,0 +1,10 @@ +foo <- function() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:20 + >--------------------< +0| foo <- function() {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.functionCall.scope b/data/fixtures/scopes/r/statement/statement.functionCall.scope new file mode 100644 index 0000000000..fb55b4580a --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.functionCall.scope @@ -0,0 +1,10 @@ +foo() +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:5 + >-----< +0| foo() + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.if.scope b/data/fixtures/scopes/r/statement/statement.if.scope new file mode 100644 index 0000000000..e4b67572d7 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.if.scope @@ -0,0 +1,15 @@ +if (TRUE) { +} else if (FALSE) { +} else {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-2:9 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else {} + ---------< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.iteration.document.scope b/data/fixtures/scopes/r/statement/statement.iteration.document.scope new file mode 100644 index 0000000000..affbd59dcb --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.iteration.document.scope @@ -0,0 +1,12 @@ + +foo <- 0 + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| foo <- 0 +2| + < diff --git a/data/fixtures/scopes/r/statement/statement.return.scope b/data/fixtures/scopes/r/statement/statement.return.scope new file mode 100644 index 0000000000..92372db28f --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.return.scope @@ -0,0 +1,21 @@ +function() { + return(0) +} +--- + +[Content] = +[Domain] = 1:4-1:13 + >---------< +1| return(0) + +[Removal] = 1:0-2:0 + >------------- +1| return(0) +2| } + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| return(0) + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.switch.scope b/data/fixtures/scopes/r/statement/statement.switch.scope new file mode 100644 index 0000000000..c71831bda3 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.switch.scope @@ -0,0 +1,10 @@ +switch(foo) +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:11 + >-----------< +0| switch(foo) + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.try.scope b/data/fixtures/scopes/r/statement/statement.try.scope new file mode 100644 index 0000000000..496fde28d1 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.try.scope @@ -0,0 +1,10 @@ +tryCatch() +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:10 + >----------< +0| tryCatch() + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.variable.initialized.scope b/data/fixtures/scopes/r/statement/statement.variable.initialized.scope new file mode 100644 index 0000000000..69ff0379f0 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.variable.initialized.scope @@ -0,0 +1,10 @@ +foo <- 0 +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:8 + >--------< +0| foo <- 0 + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.while.scope b/data/fixtures/scopes/r/statement/statement.while.scope new file mode 100644 index 0000000000..3db8a96d84 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.while.scope @@ -0,0 +1,10 @@ +while (TRUE) {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:15 + >---------------< +0| while (TRUE) {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/string.multiLine.scope b/data/fixtures/scopes/r/string.multiLine.scope new file mode 100644 index 0000000000..e8f7baaa0a --- /dev/null +++ b/data/fixtures/scopes/r/string.multiLine.scope @@ -0,0 +1,13 @@ +"Hello +world" +--- + +[Content] = +[Removal] = +[Domain] = 0:0-1:6 + >------ +0| "Hello +1| world" + ------< + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/string.singleLine.scope b/data/fixtures/scopes/r/string.singleLine.scope new file mode 100644 index 0000000000..51f6a58b24 --- /dev/null +++ b/data/fixtures/scopes/r/string.singleLine.scope @@ -0,0 +1,10 @@ +'Hello world' +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| 'Hello world' + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/textFragment.comment.line.scope b/data/fixtures/scopes/r/textFragment.comment.line.scope new file mode 100644 index 0000000000..2c362ef415 --- /dev/null +++ b/data/fixtures/scopes/r/textFragment.comment.line.scope @@ -0,0 +1,10 @@ +# Hello world +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| # Hello world + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/textFragment.string.multiLine.scope b/data/fixtures/scopes/r/textFragment.string.multiLine.scope new file mode 100644 index 0000000000..2780f7ce95 --- /dev/null +++ b/data/fixtures/scopes/r/textFragment.string.multiLine.scope @@ -0,0 +1,13 @@ +"Hello +world" +--- + +[Content] = +[Removal] = +[Domain] = 0:1-1:5 + >----- +0| "Hello +1| world" + -----< + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/textFragment.string.singleLine.scope b/data/fixtures/scopes/r/textFragment.string.singleLine.scope new file mode 100644 index 0000000000..03f85ad58a --- /dev/null +++ b/data/fixtures/scopes/r/textFragment.string.singleLine.scope @@ -0,0 +1,10 @@ +'Hello world' +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:12 + >-----------< +0| 'Hello world' + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value/value.argument.actual.iteration.scope b/data/fixtures/scopes/r/value/value.argument.actual.iteration.scope new file mode 100644 index 0000000000..546c765209 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.argument.actual.iteration.scope @@ -0,0 +1,13 @@ +foo(aaa = 0, bbb = 1) +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:21 + >---------------------< +0| foo(aaa = 0, bbb = 1) + + +[#2 Content] = +[#2 Domain] = 0:4-0:20 + >----------------< +0| foo(aaa = 0, bbb = 1) diff --git a/data/fixtures/scopes/r/value/value.argument.actual.scope b/data/fixtures/scopes/r/value/value.argument.actual.scope new file mode 100644 index 0000000000..b7b94700a4 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.argument.actual.scope @@ -0,0 +1,39 @@ +foo(aaa = 0, bbb = 1) +--- + +[#1 Content] = 0:10-0:11 + >-< +0| foo(aaa = 0, bbb = 1) + +[#1 Removal] = 0:7-0:11 + >----< +0| foo(aaa = 0, bbb = 1) + +[#1 Leading delimiter] = 0:7-0:10 + >---< +0| foo(aaa = 0, bbb = 1) + +[#1 Domain] = 0:4-0:11 + >-------< +0| foo(aaa = 0, bbb = 1) + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:19-0:20 + >-< +0| foo(aaa = 0, bbb = 1) + +[#2 Removal] = 0:16-0:20 + >----< +0| foo(aaa = 0, bbb = 1) + +[#2 Leading delimiter] = 0:16-0:19 + >---< +0| foo(aaa = 0, bbb = 1) + +[#2 Domain] = 0:13-0:20 + >-------< +0| foo(aaa = 0, bbb = 1) + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value/value.foreach.scope b/data/fixtures/scopes/r/value/value.foreach.scope new file mode 100644 index 0000000000..b360506e19 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.foreach.scope @@ -0,0 +1,20 @@ +for (v in values) {} +--- + +[Content] = 0:10-0:16 + >------< +0| for (v in values) {} + +[Removal] = 0:9-0:16 + >-------< +0| for (v in values) {} + +[Leading delimiter] = 0:9-0:10 + >-< +0| for (v in values) {} + +[Domain] = 0:0-0:20 + >--------------------< +0| for (v in values) {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value/value.return.scope b/data/fixtures/scopes/r/value/value.return.scope new file mode 100644 index 0000000000..54ad6ab339 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.return.scope @@ -0,0 +1,15 @@ +function() { + return(0) +} +--- + +[Content] = +[Removal] = 1:11-1:12 + >-< +1| return(0) + +[Domain] = 1:4-1:13 + >---------< +1| return(0) + +[Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 3e7e1e3a24..02f069efbe 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -71,7 +71,6 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "statement.return": supported, "statement.break": supported, "statement.continue": supported, - "statement.misc": supported, "statement.iteration.document": supported, "statement.iteration.block": supported, @@ -343,6 +342,7 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "interior.cell": notApplicable, // Miscellaneous statements + "statement.misc": notApplicable, "statement.package": notApplicable, "statement.import": notApplicable, diff --git a/queries/java.scm b/queries/java.scm index efa3241f2a..d766117d21 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -38,7 +38,7 @@ ;; "block", ;; (declaration) ;; Is a compound of all other declarations - ;; Disabled on purpose. We have a better definition of this below. + ;; Disabled on purpose. We have a better definition of these below. ;; (if_statement) ;; (enum_declaration) ;; (local_variable_declaration) diff --git a/queries/r.scm b/queries/r.scm index b34f60cd6f..6b86f5c592 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -3,42 +3,72 @@ [ (for_statement) - (if_statement) (repeat_statement) - (function_definition) (while_statement) + (binary_operator) + (call) + (next) + (break) + + ;; Disabled on purpose. We have a better definition of these below. + ;; (if_statement) + ;; (function_definition) ] @statement -;;!! # hello -;;! ^^^^^^^ -(comment) @comment +;;!! { } +;;! ^ +(_ + . + "{" @interior.start.endOf + "}" @interior.end.startOf + . +) + +(program) @statement.iteration @namedFunction.iteration +(program) @name.iteration @value.iteration + +;;!! # hello world +;;! ^^^^^^^^^^^^^ +(comment) @comment @textFragment + +;;!! "hello world" +;;! ^^^^^^^^^^^^^ +;;! ^^^^^^^^^^^ +(string + (string_content)? @textFragment +) @string + +;;!! if (TRUE) {} else {} +( + (if_statement + condition: (_) @condition + ) @ifStatement @statement @condition.domain + (#not-parent-type? @ifStatement if_statement) +) -;;!! if (x > 0) { } -;;! ^^^^^^^^^^^^^^ -(if_statement) @ifStatement +;;!! else if (TRUE) {} +(if_statement + "else" @condition.domain.start + alternative: (if_statement + condition: (_) @condition + consequence: (_) @condition.domain.end + ) +) -;; named function -;;!! abc <- function(x){ } -;;! ^^^^^^^^^^^^^^^^^^^^^ +;;!! foo <- function(){} +;;! ^^^^^^^^^^^^^^^^^^^ +;;! ^^^ (binary_operator - ;;!! abc <- function(x){ } - ;;! ^^^ lhs: (identifier) @name - rhs: (function_definition - name: "function" - parameters: (parameters) - body: (braced_expression) - ) @name.trailing.startOf -) @namedFunction @_.domain - -;; anonymous function -;;!! function(x){ } -;;! ^^^^^^^^^^^^^^ + rhs: (function_definition) @name.trailing.startOf +) @namedFunction @statement @_.domain + +;;!! function(){} +;;! ^^^^^^^^^^^^ (function_definition) @anonymousFunction -;; argument.actual -;;!! foo(a, b") -;;! ^ ^ +;;!! foo(aaa, bbb) +;;! ^^^ ^^^ ( (arguments ( @@ -58,9 +88,8 @@ (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) -;; argument.formal -;;!! function(a, b){} -;;! ^ ^ +;;!! function(aaa, bbb){} +;;! ^^^ ^^^ ( (parameters ( @@ -80,9 +109,27 @@ (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) -;; argumentList.actual -;;!! foo(a, b) -;;! ^^^^ +;;!! foo(aaa = 0) +;;! ^^^ +;;! ^ +(argument + name: (_) @name @value.leading.endOf + value: (_) @value @name.trailing.startOf +) @_.domain + +;;!! foo(aaa = 0) +;;! ^^^^^^^ +(arguments + "(" @name.iteration.start.endOf @value.iteration.start.endOf + (argument + name: (_) + value: (_) + ) + ")" @name.iteration.end.startOf @value.iteration.end.startOf +) + +;;!! foo(aaa, bbb) +;;! ^^^^^^^^ (call (arguments "(" @argumentList.removal.start.endOf @argumentOrParameter.iteration.start.endOf @@ -92,9 +139,8 @@ (#child-range! @argumentList 1 -2) ) @argumentList.domain @argumentOrParameter.iteration.domain -;; argumentList.formal -;;!! foo <- function(a, b){ } -;;! ^^^^ +;;!! foo <- function(aaa, bbb){} +;;! ^^^^^^^^ (binary_operator (function_definition (parameters @@ -106,9 +152,8 @@ ) ) @argumentList.domain @argumentOrParameter.iteration.domain -;; argumentList.formal -;;!! function(a, b){} -;;! ^^^^ +;;!! function(aaa, bbb){} +;;! ^^^^^^^^ ( (function_definition (parameters @@ -126,43 +171,55 @@ ")" @name.iteration.end.startOf @value.iteration.end.startOf @type.iteration.end.startOf ) -;; Function calls ;;!! foo() ;;! ^^^^^ ;;! ^^^ -;;! ----- - (call - (identifier) @functionCallee + function: (_) @functionCallee ) @functionCall @functionCallee.domain ;; Technically lists and arrays are just calls to the function `list` or `c` ;;!! list(1, 2, 3) ;;! ^^^^^^^^^^^^^ (call - function: (identifier) @_dummy + function: (_) @_dummy (#match? @_dummy "^(c|list)$") ) @list +;;!! return(0, 1) +;;! ^^^^ +(call + function: (return) + (arguments + "(" + . + (argument) @value.start + (argument)? @value.end + . + ")" + ) +) @value.domain + +;;!! foo <- 0 +;;! ^^^ +;;! ^ (binary_operator - ;;!! hello <- "world" - ;;! ^^^^^ - ;;! ----- - lhs: (identifier) @name @value.leading.endOf - operator: [ - "<-" - "=" - ] - ;;!! hello <- "world" - ;;! ^^^^^^^ - ;;! ----- + lhs: (_) @name @value.leading.endOf rhs: (_) @value @name.trailing.startOf ) @_.domain -;;!! foo(hello) -;;! ^^^^^ -;;! ----- -;; (identifier) @value +;;!! while (TRUE) {} +(while_statement + condition: (_) @condition +) @condition.domain + +;;!! for (v in values) {} +;;! ^ +;;! ^^^^^^ +(for_statement + variable: (_) @name + sequence: (_) @value +) @_.domain ;; ;; from https://github.com/r-lib/tree-sitter-r/blob/main/queries/highlights.scm ;; ;; Plus magrittr operators From fe7f3fd90750bc3d4007166ad6f740615184e86f Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 12:27:27 +0100 Subject: [PATCH 03/12] argument --- .../argument.actual.method.iteration.scope | 10 ++++ .../argument.actual.method.multiLine.scope | 44 +++++++++++++++ .../argument.actual.method.singleLine.scope | 33 ++++++++++++ .../argument/argument.actual.singleLine.scope | 22 ++++---- .../argument.actual.singleLine2.scope | 33 ------------ .../argument.actual.singleLine3.scope | 10 ---- .../argument.actual.singleLine4.scope | 33 ------------ .../argument.actual.singleLine5.scope | 53 ------------------- .../argument.formal.lambda.iteration.scope | 10 ++++ .../argument.formal.lambda.multiLine.scope | 44 +++++++++++++++ .../argument.formal.lambda.singleLine.scope | 33 ++++++++++++ .../argument.formal.singleLine2.scope | 53 ------------------- ...ame.argument.formal.lambda.iteration.scope | 13 +++++ .../r/name/name.argument.formal.lambda.scope | 26 +++++++++ .../scopes/r/name/name.argument.formal.scope | 26 +++++++++ .../scopes/r/name/name.argument.formal2.scope | 39 ++++++++++++++ .../value.argument.formal.iteration.scope | 13 +++++ .../r/value/value.argument.formal.scope | 39 ++++++++++++++ .../r/value/value.iteration.document.scope | 12 +++++ .../scopes/r/value/value.switch.scope | 13 +++++ queries/r.scm | 48 +++++++++++------ 21 files changed, 399 insertions(+), 208 deletions(-) create mode 100644 data/fixtures/scopes/r/argument/argument.actual.method.iteration.scope create mode 100644 data/fixtures/scopes/r/argument/argument.actual.method.multiLine.scope create mode 100644 data/fixtures/scopes/r/argument/argument.actual.method.singleLine.scope delete mode 100644 data/fixtures/scopes/r/argument/argument.actual.singleLine2.scope delete mode 100644 data/fixtures/scopes/r/argument/argument.actual.singleLine3.scope delete mode 100644 data/fixtures/scopes/r/argument/argument.actual.singleLine4.scope delete mode 100644 data/fixtures/scopes/r/argument/argument.actual.singleLine5.scope create mode 100644 data/fixtures/scopes/r/argument/argument.formal.lambda.iteration.scope create mode 100644 data/fixtures/scopes/r/argument/argument.formal.lambda.multiLine.scope create mode 100644 data/fixtures/scopes/r/argument/argument.formal.lambda.singleLine.scope delete mode 100644 data/fixtures/scopes/r/argument/argument.formal.singleLine2.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.formal.lambda.iteration.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.formal.lambda.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.formal.scope create mode 100644 data/fixtures/scopes/r/name/name.argument.formal2.scope create mode 100644 data/fixtures/scopes/r/value/value.argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/r/value/value.argument.formal.scope create mode 100644 data/fixtures/scopes/r/value/value.iteration.document.scope create mode 100644 data/fixtures/scopes/r/value/value.switch.scope diff --git a/data/fixtures/scopes/r/argument/argument.actual.method.iteration.scope b/data/fixtures/scopes/r/argument/argument.actual.method.iteration.scope new file mode 100644 index 0000000000..8b3899b4a1 --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.actual.method.iteration.scope @@ -0,0 +1,10 @@ +foo.bar(aaa, bbb) +--- + +[Content] = 0:8-0:16 + >--------< +0| foo.bar(aaa, bbb) + +[Domain] = 0:0-0:17 + >-----------------< +0| foo.bar(aaa, bbb) diff --git a/data/fixtures/scopes/r/argument/argument.actual.method.multiLine.scope b/data/fixtures/scopes/r/argument/argument.actual.method.multiLine.scope new file mode 100644 index 0000000000..7dace79cea --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.actual.method.multiLine.scope @@ -0,0 +1,44 @@ +foo.bar( + aaa, + bbb +) +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:7 + >---< +1| aaa, + +[#1 Removal] = 1:4-2:4 + >---- +1| aaa, +2| bbb + ----< + +[#1 Trailing delimiter] = 1:7-2:4 + >- +1| aaa, +2| bbb + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:7 + >---< +2| bbb + +[#2 Removal] = 1:7-2:7 + >- +1| aaa, +2| bbb + -------< + +[#2 Leading delimiter] = 1:7-2:4 + >- +1| aaa, +2| bbb + ----< + +[#2 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/r/argument/argument.actual.method.singleLine.scope b/data/fixtures/scopes/r/argument/argument.actual.method.singleLine.scope new file mode 100644 index 0000000000..d22bd33706 --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.actual.method.singleLine.scope @@ -0,0 +1,33 @@ +foo.bar(aaa, bbb) +--- + +[#1 Content] = +[#1 Domain] = 0:8-0:11 + >---< +0| foo.bar(aaa, bbb) + +[#1 Removal] = 0:8-0:13 + >-----< +0| foo.bar(aaa, bbb) + +[#1 Trailing delimiter] = 0:11-0:13 + >--< +0| foo.bar(aaa, bbb) + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:13-0:16 + >---< +0| foo.bar(aaa, bbb) + +[#2 Removal] = 0:11-0:16 + >-----< +0| foo.bar(aaa, bbb) + +[#2 Leading delimiter] = 0:11-0:13 + >--< +0| foo.bar(aaa, bbb) + +[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.actual.singleLine.scope b/data/fixtures/scopes/r/argument/argument.actual.singleLine.scope index 35aa9e2ef8..0844bf6144 100644 --- a/data/fixtures/scopes/r/argument/argument.actual.singleLine.scope +++ b/data/fixtures/scopes/r/argument/argument.actual.singleLine.scope @@ -1,33 +1,33 @@ -func(aaa, bbb) +func(aaa, bbb = 0) --- [#1 Content] = [#1 Domain] = 0:5-0:8 >---< -0| func(aaa, bbb) +0| func(aaa, bbb = 0) [#1 Removal] = 0:5-0:10 >-----< -0| func(aaa, bbb) +0| func(aaa, bbb = 0) [#1 Trailing delimiter] = 0:8-0:10 >--< -0| func(aaa, bbb) +0| func(aaa, bbb = 0) [#1 Insertion delimiter] = ", " [#2 Content] = -[#2 Domain] = 0:10-0:13 - >---< -0| func(aaa, bbb) +[#2 Domain] = 0:10-0:17 + >-------< +0| func(aaa, bbb = 0) -[#2 Removal] = 0:8-0:13 - >-----< -0| func(aaa, bbb) +[#2 Removal] = 0:8-0:17 + >---------< +0| func(aaa, bbb = 0) [#2 Leading delimiter] = 0:8-0:10 >--< -0| func(aaa, bbb) +0| func(aaa, bbb = 0) [#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.actual.singleLine2.scope b/data/fixtures/scopes/r/argument/argument.actual.singleLine2.scope deleted file mode 100644 index 35aa9e2ef8..0000000000 --- a/data/fixtures/scopes/r/argument/argument.actual.singleLine2.scope +++ /dev/null @@ -1,33 +0,0 @@ -func(aaa, bbb) ---- - -[#1 Content] = -[#1 Domain] = 0:5-0:8 - >---< -0| func(aaa, bbb) - -[#1 Removal] = 0:5-0:10 - >-----< -0| func(aaa, bbb) - -[#1 Trailing delimiter] = 0:8-0:10 - >--< -0| func(aaa, bbb) - -[#1 Insertion delimiter] = ", " - - -[#2 Content] = -[#2 Domain] = 0:10-0:13 - >---< -0| func(aaa, bbb) - -[#2 Removal] = 0:8-0:13 - >-----< -0| func(aaa, bbb) - -[#2 Leading delimiter] = 0:8-0:10 - >--< -0| func(aaa, bbb) - -[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.actual.singleLine3.scope b/data/fixtures/scopes/r/argument/argument.actual.singleLine3.scope deleted file mode 100644 index 223eb2f607..0000000000 --- a/data/fixtures/scopes/r/argument/argument.actual.singleLine3.scope +++ /dev/null @@ -1,10 +0,0 @@ -func(...) ---- - -[Content] = -[Removal] = -[Domain] = 0:5-0:8 - >---< -0| func(...) - -[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.actual.singleLine4.scope b/data/fixtures/scopes/r/argument/argument.actual.singleLine4.scope deleted file mode 100644 index 88cadc33be..0000000000 --- a/data/fixtures/scopes/r/argument/argument.actual.singleLine4.scope +++ /dev/null @@ -1,33 +0,0 @@ -func(aaa=0, bbb=1) ---- - -[#1 Content] = -[#1 Domain] = 0:5-0:10 - >-----< -0| func(aaa=0, bbb=1) - -[#1 Removal] = 0:5-0:12 - >-------< -0| func(aaa=0, bbb=1) - -[#1 Trailing delimiter] = 0:10-0:12 - >--< -0| func(aaa=0, bbb=1) - -[#1 Insertion delimiter] = ", " - - -[#2 Content] = -[#2 Domain] = 0:12-0:17 - >-----< -0| func(aaa=0, bbb=1) - -[#2 Removal] = 0:10-0:17 - >-------< -0| func(aaa=0, bbb=1) - -[#2 Leading delimiter] = 0:10-0:12 - >--< -0| func(aaa=0, bbb=1) - -[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.actual.singleLine5.scope b/data/fixtures/scopes/r/argument/argument.actual.singleLine5.scope deleted file mode 100644 index 1a0999b6b5..0000000000 --- a/data/fixtures/scopes/r/argument/argument.actual.singleLine5.scope +++ /dev/null @@ -1,53 +0,0 @@ -func(aaa, bbb, ccc) ---- - -[#1 Content] = -[#1 Domain] = 0:5-0:8 - >---< -0| func(aaa, bbb, ccc) - -[#1 Removal] = 0:5-0:10 - >-----< -0| func(aaa, bbb, ccc) - -[#1 Trailing delimiter] = 0:8-0:10 - >--< -0| func(aaa, bbb, ccc) - -[#1 Insertion delimiter] = ", " - - -[#2 Content] = -[#2 Domain] = 0:10-0:13 - >---< -0| func(aaa, bbb, ccc) - -[#2 Removal] = 0:10-0:15 - >-----< -0| func(aaa, bbb, ccc) - -[#2 Leading delimiter] = 0:8-0:10 - >--< -0| func(aaa, bbb, ccc) - -[#2 Trailing delimiter] = 0:13-0:15 - >--< -0| func(aaa, bbb, ccc) - -[#2 Insertion delimiter] = ", " - - -[#3 Content] = -[#3 Domain] = 0:15-0:18 - >---< -0| func(aaa, bbb, ccc) - -[#3 Removal] = 0:13-0:18 - >-----< -0| func(aaa, bbb, ccc) - -[#3 Leading delimiter] = 0:13-0:15 - >--< -0| func(aaa, bbb, ccc) - -[#3 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.formal.lambda.iteration.scope b/data/fixtures/scopes/r/argument/argument.formal.lambda.iteration.scope new file mode 100644 index 0000000000..c2324ea9c3 --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.formal.lambda.iteration.scope @@ -0,0 +1,10 @@ +function(aaa, bbb) {} +--- + +[Content] = 0:9-0:17 + >--------< +0| function(aaa, bbb) {} + +[Domain] = 0:0-0:21 + >---------------------< +0| function(aaa, bbb) {} diff --git a/data/fixtures/scopes/r/argument/argument.formal.lambda.multiLine.scope b/data/fixtures/scopes/r/argument/argument.formal.lambda.multiLine.scope new file mode 100644 index 0000000000..d63f69132c --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.formal.lambda.multiLine.scope @@ -0,0 +1,44 @@ +function( + aaa, + bbb +) {} +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:7 + >---< +1| aaa, + +[#1 Removal] = 1:4-2:4 + >---- +1| aaa, +2| bbb + ----< + +[#1 Trailing delimiter] = 1:7-2:4 + >- +1| aaa, +2| bbb + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:7 + >---< +2| bbb + +[#2 Removal] = 1:7-2:7 + >- +1| aaa, +2| bbb + -------< + +[#2 Leading delimiter] = 1:7-2:4 + >- +1| aaa, +2| bbb + ----< + +[#2 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/r/argument/argument.formal.lambda.singleLine.scope b/data/fixtures/scopes/r/argument/argument.formal.lambda.singleLine.scope new file mode 100644 index 0000000000..5de4b19967 --- /dev/null +++ b/data/fixtures/scopes/r/argument/argument.formal.lambda.singleLine.scope @@ -0,0 +1,33 @@ +function(aaa, bbb) {} +--- + +[#1 Content] = +[#1 Domain] = 0:9-0:12 + >---< +0| function(aaa, bbb) {} + +[#1 Removal] = 0:9-0:14 + >-----< +0| function(aaa, bbb) {} + +[#1 Trailing delimiter] = 0:12-0:14 + >--< +0| function(aaa, bbb) {} + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:14-0:17 + >---< +0| function(aaa, bbb) {} + +[#2 Removal] = 0:12-0:17 + >-----< +0| function(aaa, bbb) {} + +[#2 Leading delimiter] = 0:12-0:14 + >--< +0| function(aaa, bbb) {} + +[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/argument/argument.formal.singleLine2.scope b/data/fixtures/scopes/r/argument/argument.formal.singleLine2.scope deleted file mode 100644 index 6671acf160..0000000000 --- a/data/fixtures/scopes/r/argument/argument.formal.singleLine2.scope +++ /dev/null @@ -1,53 +0,0 @@ -foo <- function(aaa, bbb, ccc) {} ---- - -[#1 Content] = -[#1 Domain] = 0:16-0:19 - >---< -0| foo <- function(aaa, bbb, ccc) {} - -[#1 Removal] = 0:16-0:21 - >-----< -0| foo <- function(aaa, bbb, ccc) {} - -[#1 Trailing delimiter] = 0:19-0:21 - >--< -0| foo <- function(aaa, bbb, ccc) {} - -[#1 Insertion delimiter] = ", " - - -[#2 Content] = -[#2 Domain] = 0:21-0:24 - >---< -0| foo <- function(aaa, bbb, ccc) {} - -[#2 Removal] = 0:21-0:26 - >-----< -0| foo <- function(aaa, bbb, ccc) {} - -[#2 Leading delimiter] = 0:19-0:21 - >--< -0| foo <- function(aaa, bbb, ccc) {} - -[#2 Trailing delimiter] = 0:24-0:26 - >--< -0| foo <- function(aaa, bbb, ccc) {} - -[#2 Insertion delimiter] = ", " - - -[#3 Content] = -[#3 Domain] = 0:26-0:29 - >---< -0| foo <- function(aaa, bbb, ccc) {} - -[#3 Removal] = 0:24-0:29 - >-----< -0| foo <- function(aaa, bbb, ccc) {} - -[#3 Leading delimiter] = 0:24-0:26 - >--< -0| foo <- function(aaa, bbb, ccc) {} - -[#3 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/name/name.argument.formal.lambda.iteration.scope b/data/fixtures/scopes/r/name/name.argument.formal.lambda.iteration.scope new file mode 100644 index 0000000000..1a73d43ddb --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.formal.lambda.iteration.scope @@ -0,0 +1,13 @@ +function(aaa, bbb) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:21 + >---------------------< +0| function(aaa, bbb) {} + + +[#2 Content] = +[#2 Domain] = 0:9-0:17 + >--------< +0| function(aaa, bbb) {} diff --git a/data/fixtures/scopes/r/name/name.argument.formal.lambda.scope b/data/fixtures/scopes/r/name/name.argument.formal.lambda.scope new file mode 100644 index 0000000000..0e4fa3baae --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.formal.lambda.scope @@ -0,0 +1,26 @@ +function(aaa, bbb) {} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:9-0:12 + >---< +0| function(aaa, bbb) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 0:14-0:17 + >---< +0| function(aaa, bbb) {} + +[#2 Removal] = 0:13-0:17 + >----< +0| function(aaa, bbb) {} + +[#2 Leading delimiter] = 0:13-0:14 + >-< +0| function(aaa, bbb) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name/name.argument.formal.scope b/data/fixtures/scopes/r/name/name.argument.formal.scope new file mode 100644 index 0000000000..0e4fa3baae --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.formal.scope @@ -0,0 +1,26 @@ +function(aaa, bbb) {} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:9-0:12 + >---< +0| function(aaa, bbb) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 0:14-0:17 + >---< +0| function(aaa, bbb) {} + +[#2 Removal] = 0:13-0:17 + >----< +0| function(aaa, bbb) {} + +[#2 Leading delimiter] = 0:13-0:14 + >-< +0| function(aaa, bbb) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name/name.argument.formal2.scope b/data/fixtures/scopes/r/name/name.argument.formal2.scope new file mode 100644 index 0000000000..15911bd390 --- /dev/null +++ b/data/fixtures/scopes/r/name/name.argument.formal2.scope @@ -0,0 +1,39 @@ +function(aaa = 0, bbb = 1) {} +--- + +[#1 Content] = 0:9-0:12 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#1 Removal] = 0:9-0:15 + >------< +0| function(aaa = 0, bbb = 1) {} + +[#1 Trailing delimiter] = 0:12-0:15 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#1 Domain] = 0:9-0:16 + >-------< +0| function(aaa = 0, bbb = 1) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:18-0:21 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#2 Removal] = 0:18-0:24 + >------< +0| function(aaa = 0, bbb = 1) {} + +[#2 Trailing delimiter] = 0:21-0:24 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#2 Domain] = 0:18-0:25 + >-------< +0| function(aaa = 0, bbb = 1) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value/value.argument.formal.iteration.scope b/data/fixtures/scopes/r/value/value.argument.formal.iteration.scope new file mode 100644 index 0000000000..37437323ca --- /dev/null +++ b/data/fixtures/scopes/r/value/value.argument.formal.iteration.scope @@ -0,0 +1,13 @@ +function(aaa = 0, bbb = 1) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:29 + >-----------------------------< +0| function(aaa = 0, bbb = 1) {} + + +[#2 Content] = +[#2 Domain] = 0:9-0:25 + >----------------< +0| function(aaa = 0, bbb = 1) {} diff --git a/data/fixtures/scopes/r/value/value.argument.formal.scope b/data/fixtures/scopes/r/value/value.argument.formal.scope new file mode 100644 index 0000000000..84d8ed99d0 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.argument.formal.scope @@ -0,0 +1,39 @@ +function(aaa = 0, bbb = 1) {} +--- + +[#1 Content] = 0:15-0:16 + >-< +0| function(aaa = 0, bbb = 1) {} + +[#1 Removal] = 0:12-0:16 + >----< +0| function(aaa = 0, bbb = 1) {} + +[#1 Leading delimiter] = 0:12-0:15 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#1 Domain] = 0:9-0:16 + >-------< +0| function(aaa = 0, bbb = 1) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:24-0:25 + >-< +0| function(aaa = 0, bbb = 1) {} + +[#2 Removal] = 0:21-0:25 + >----< +0| function(aaa = 0, bbb = 1) {} + +[#2 Leading delimiter] = 0:21-0:24 + >---< +0| function(aaa = 0, bbb = 1) {} + +[#2 Domain] = 0:18-0:25 + >-------< +0| function(aaa = 0, bbb = 1) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value/value.iteration.document.scope b/data/fixtures/scopes/r/value/value.iteration.document.scope new file mode 100644 index 0000000000..affbd59dcb --- /dev/null +++ b/data/fixtures/scopes/r/value/value.iteration.document.scope @@ -0,0 +1,12 @@ + +foo <- 0 + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| foo <- 0 +2| + < diff --git a/data/fixtures/scopes/r/value/value.switch.scope b/data/fixtures/scopes/r/value/value.switch.scope new file mode 100644 index 0000000000..b728c6e2ec --- /dev/null +++ b/data/fixtures/scopes/r/value/value.switch.scope @@ -0,0 +1,13 @@ +switch(foo) +--- + +[Content] = +[Removal] = 0:7-0:10 + >---< +0| switch(foo) + +[Domain] = 0:0-0:11 + >-----------< +0| switch(foo) + +[Insertion delimiter] = " " diff --git a/queries/r.scm b/queries/r.scm index 6b86f5c592..d928c1f255 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -109,6 +109,20 @@ (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) +;;!! foo(aaa = 0) +;;! ^^^^^^^ +(arguments + "(" @name.iteration.start.endOf @value.iteration.start.endOf + ")" @name.iteration.end.startOf @value.iteration.end.startOf +) + +;;!! function(aaa, bbb){} +;;! ^^^^^^^^ +(parameters + "(" @name.iteration.start.endOf @value.iteration.start.endOf + ")" @name.iteration.end.startOf @value.iteration.end.startOf +) + ;;!! foo(aaa = 0) ;;! ^^^ ;;! ^ @@ -117,16 +131,13 @@ value: (_) @value @name.trailing.startOf ) @_.domain -;;!! foo(aaa = 0) -;;! ^^^^^^^ -(arguments - "(" @name.iteration.start.endOf @value.iteration.start.endOf - (argument - name: (_) - value: (_) - ) - ")" @name.iteration.end.startOf @value.iteration.end.startOf -) +;;!! function(aaa = 0) +;;! ^^^ +;;! ^ +(parameter + name: (_) @name @value.leading.endOf + default: (_)? @value @name.trailing.startOf +) @_.domain ;;!! foo(aaa, bbb) ;;! ^^^^^^^^ @@ -166,11 +177,6 @@ (#not-parent-type? @argumentList.domain binary_operator) ) -(parameters - "(" @name.iteration.start.endOf @value.iteration.start.endOf @type.iteration.start.endOf - ")" @name.iteration.end.startOf @value.iteration.end.startOf @type.iteration.end.startOf -) - ;;!! foo() ;;! ^^^^^ ;;! ^^^ @@ -186,6 +192,18 @@ (#match? @_dummy "^(c|list)$") ) @list +;;!! switch(foo, ...) +;;! ^^^ +(call + function: (_) @_dummy + (arguments + "(" + . + (argument) @value + ) + (#eq? @_dummy switch) +) @value.domain + ;;!! return(0, 1) ;;! ^^^^ (call From ab4deb0df99b5dc27a98e354d857ca34775af51b Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 12:30:31 +0100 Subject: [PATCH 04/12] interior --- .../scopes/r/interior/interior.foreach.scope | 10 ++++++ .../scopes/r/interior/interior.function.scope | 10 ++++++ .../scopes/r/interior/interior.if.scope | 34 +++++++++++++++++++ .../scopes/r/interior/interior.lambda.scope | 10 ++++++ .../scopes/r/interior/interior.while.scope | 10 ++++++ 5 files changed, 74 insertions(+) create mode 100644 data/fixtures/scopes/r/interior/interior.foreach.scope create mode 100644 data/fixtures/scopes/r/interior/interior.function.scope create mode 100644 data/fixtures/scopes/r/interior/interior.if.scope create mode 100644 data/fixtures/scopes/r/interior/interior.lambda.scope create mode 100644 data/fixtures/scopes/r/interior/interior.while.scope diff --git a/data/fixtures/scopes/r/interior/interior.foreach.scope b/data/fixtures/scopes/r/interior/interior.foreach.scope new file mode 100644 index 0000000000..7738d34017 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.foreach.scope @@ -0,0 +1,10 @@ +for (v in values) { } +--- + +[Content] = +[Removal] = +[Domain] = 0:19-0:20 + >-< +0| for (v in values) { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/interior/interior.function.scope b/data/fixtures/scopes/r/interior/interior.function.scope new file mode 100644 index 0000000000..7479f4d8d5 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.function.scope @@ -0,0 +1,10 @@ +foo <- function() { } +--- + +[Content] = +[Removal] = +[Domain] = 0:19-0:20 + >-< +0| foo <- function() { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/interior/interior.if.scope b/data/fixtures/scopes/r/interior/interior.if.scope new file mode 100644 index 0000000000..6efbe863b0 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.if.scope @@ -0,0 +1,34 @@ +if (TRUE) { +} else if (FALSE) { +} else { } +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:11-1:0 + > +0| if (TRUE) { +1| } else if (FALSE) { + < + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 1:19-2:0 + > +1| } else if (FALSE) { +2| } else { } + < + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 2:8-2:9 + >-< +2| } else { } + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/interior/interior.lambda.scope b/data/fixtures/scopes/r/interior/interior.lambda.scope new file mode 100644 index 0000000000..b68bf02746 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.lambda.scope @@ -0,0 +1,10 @@ +function() { } +--- + +[Content] = +[Removal] = +[Domain] = 0:12-0:13 + >-< +0| function() { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/interior/interior.while.scope b/data/fixtures/scopes/r/interior/interior.while.scope new file mode 100644 index 0000000000..b451dddc3a --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.while.scope @@ -0,0 +1,10 @@ +while (TRUE) { } +--- + +[Content] = +[Removal] = +[Domain] = 0:14-0:15 + >-< +0| while (TRUE) { } + +[Insertion delimiter] = " " From fd4fb3647a6c800d90eac79edb86a200c2af374d Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 12:50:16 +0100 Subject: [PATCH 05/12] disqualified delimiter --- .../scopes/r/branch/branch.if.elif.else.scope | 63 +++++++++++++++++++ .../scopes/r/branch/branch.if.else.scope | 38 +++++++++++ .../scopes/r/branch/branch.if.iteration.scope | 12 ++++ data/fixtures/scopes/r/branch/branch.if.scope | 10 +++ .../scopes/r/disqualifyDelimiter.scope | 45 +++++++++++++ packages/common/src/scopeSupportFacets/r.ts | 9 +-- queries/java.scm | 26 ++++---- queries/r.scm | 51 ++++++++++----- 8 files changed, 222 insertions(+), 32 deletions(-) create mode 100644 data/fixtures/scopes/r/branch/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/r/branch/branch.if.else.scope create mode 100644 data/fixtures/scopes/r/branch/branch.if.iteration.scope create mode 100644 data/fixtures/scopes/r/branch/branch.if.scope create mode 100644 data/fixtures/scopes/r/disqualifyDelimiter.scope diff --git a/data/fixtures/scopes/r/branch/branch.if.elif.else.scope b/data/fixtures/scopes/r/branch/branch.if.elif.else.scope new file mode 100644 index 0000000000..5935ebfafb --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.if.elif.else.scope @@ -0,0 +1,63 @@ +if (TRUE) { +} else if (FALSE) { +} else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:1 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { + -< + +[#1 Removal] = 0:0-1:7 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { + -------< + +[#1 Trailing delimiter] = 1:1-1:2 + >-< +1| } else if (FALSE) { + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:2-2:1 + >----------------- +1| } else if (FALSE) { +2| } else {} + -< + +[#2 Removal] = 1:2-2:2 + >----------------- +1| } else if (FALSE) { +2| } else {} + --< + +[#2 Leading delimiter] = 1:1-1:2 + >-< +1| } else if (FALSE) { + +[#2 Trailing delimiter] = 2:1-2:2 + >-< +2| } else {} + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 2:2-2:9 + >-------< +2| } else {} + +[#3 Removal] = 2:1-2:9 + >--------< +2| } else {} + +[#3 Leading delimiter] = 2:1-2:2 + >-< +2| } else {} + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/branch/branch.if.else.scope b/data/fixtures/scopes/r/branch/branch.if.else.scope new file mode 100644 index 0000000000..068136316f --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.if.else.scope @@ -0,0 +1,38 @@ +if (TRUE) { +} else {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-1:1 + >----------- +0| if (TRUE) { +1| } else {} + -< + +[#1 Removal] = 0:0-1:2 + >----------- +0| if (TRUE) { +1| } else {} + --< + +[#1 Trailing delimiter] = 1:1-1:2 + >-< +1| } else {} + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:2-1:9 + >-------< +1| } else {} + +[#2 Removal] = 1:1-1:9 + >--------< +1| } else {} + +[#2 Leading delimiter] = 1:1-1:2 + >-< +1| } else {} + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/branch/branch.if.iteration.scope b/data/fixtures/scopes/r/branch/branch.if.iteration.scope new file mode 100644 index 0000000000..690f881ce5 --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.if.iteration.scope @@ -0,0 +1,12 @@ +if (TRUE) { +} else if (FALSE) { +} else {} +--- + +[Content] = +[Domain] = 0:0-2:9 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else {} + ---------< diff --git a/data/fixtures/scopes/r/branch/branch.if.scope b/data/fixtures/scopes/r/branch/branch.if.scope new file mode 100644 index 0000000000..6894c02809 --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.if.scope @@ -0,0 +1,10 @@ +if (TRUE) {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:12 + >------------< +0| if (TRUE) {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/disqualifyDelimiter.scope b/data/fixtures/scopes/r/disqualifyDelimiter.scope new file mode 100644 index 0000000000..2bb0d8cc5c --- /dev/null +++ b/data/fixtures/scopes/r/disqualifyDelimiter.scope @@ -0,0 +1,45 @@ +foo < 0 +foo > 0 +foo <- 0 +foo -> 0 +foo <= 0 +foo >= 0 +foo <<- 0 +foo ->> 0 +foo |> 0 +--- +[#1 Content] = 0:4-0:5 + >-< +0| foo < 0 + +[#2 Content] = 1:4-1:5 + >-< +1| foo > 0 + +[#3 Content] = 2:4-2:6 + >--< +2| foo <- 0 + +[#4 Content] = 3:4-3:6 + >--< +3| foo -> 0 + +[#5 Content] = 4:4-4:6 + >--< +4| foo <= 0 + +[#6 Content] = 5:4-5:6 + >--< +5| foo >= 0 + +[#7 Content] = 6:4-6:7 + >---< +6| foo <<- 0 + +[#8 Content] = 7:4-7:7 + >---< +7| foo ->> 0 + +[#9 Content] = 8:4-8:6 + >--< +8| foo |> 0 diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 02f069efbe..5d418e894c 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -34,10 +34,6 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "argumentList.formal.lambda.singleLine": supported, "argumentList.formal.lambda.multiLine": supported, - "collectionItem.unenclosed.singleLine": supported, - "collectionItem.unenclosed.multiLine": supported, - "collectionItem.unenclosed.iteration": supported, - "branch.if": supported, "branch.if.elif.else": supported, "branch.if.else": supported, @@ -341,6 +337,11 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { notebookCell: notApplicable, "interior.cell": notApplicable, + // Unenclosed collection items + "collectionItem.unenclosed.singleLine": notApplicable, + "collectionItem.unenclosed.multiLine": notApplicable, + "collectionItem.unenclosed.iteration": notApplicable, + // Miscellaneous statements "statement.misc": notApplicable, "statement.package": notApplicable, diff --git a/queries/java.scm b/queries/java.scm index d766117d21..5eacffd201 100644 --- a/queries/java.scm +++ b/queries/java.scm @@ -651,18 +651,20 @@ ) ) @_.domain -operator: [ - "<" - ">" - "<=" - ">=" - "<<" - ">>" - "<<=" - ">>=" - ">>>" - ">>>=" -] @disqualifyDelimiter +(_ + operator: [ + "<" + ">" + "<=" + ">=" + "<<" + ">>" + "<<=" + ">>=" + ">>>" + ">>>=" + ] @disqualifyDelimiter +) (lambda_expression "->" @disqualifyDelimiter ) diff --git a/queries/r.scm b/queries/r.scm index d928c1f255..4e3742a808 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -38,23 +38,39 @@ (string_content)? @textFragment ) @string -;;!! if (TRUE) {} else {} +;;!! if () {} else {} +( + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement if_statement) +) + +;;!! if () {} ( (if_statement + "if" @branch.start @branch.removal.start condition: (_) @condition - ) @ifStatement @statement @condition.domain - (#not-parent-type? @ifStatement if_statement) + consequence: (_) @branch.end @branch.removal.end + "else"? @branch.removal.end.startOf + alternative: (if_statement)? @branch.removal.end.startOf + ) @condition.domain + (#not-parent-type? @condition.domain if_statement) ) -;;!! else if (TRUE) {} +;;!! else if () {} (if_statement - "else" @condition.domain.start + "else" @branch.start @condition.domain.start alternative: (if_statement condition: (_) @condition - consequence: (_) @condition.domain.end + consequence: (_) @branch.end @condition.domain.end ) ) +;;!! else {} +(if_statement + "else" @branch.start + alternative: (braced_expression) @branch.end +) + ;;!! foo <- function(){} ;;! ^^^^^^^^^^^^^^^^^^^ ;;! ^^^ @@ -239,13 +255,16 @@ sequence: (_) @value ) @_.domain -;; ;; from https://github.com/r-lib/tree-sitter-r/blob/main/queries/highlights.scm -;; ;; Plus magrittr operators -;; operator: [ "?" ":=" "=" "<-" "<<-" "->" "->>" -;; "~" "|>" "||" "|" "&&" "&" -;; "<" "<=" ">" ">=" "==" "!=" -;; "+" "-" "*" "/" "::" ":::" -;; "**" "^" "$" "@" ":" "%in%" -;; "%>%" "%<>%" "%T>%" "%$%" -;; "special" -;; ] @disqualifyDelimiter +(_ + operator: [ + "<" + ">" + "<-" + "->" + "<=" + ">=" + "<<-" + "->>" + "|>" + ] @disqualifyDelimiter +) From 61192acaaf9c8059c6536b2221ec65d6bf28fe50 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 12:57:14 +0100 Subject: [PATCH 06/12] statement assignment --- .../scopes/r/statement/statement.assignment.scope | 10 ++++++++++ .../scopes/r/statement/statement.assignment2.scope | 10 ++++++++++ packages/common/src/scopeSupportFacets/r.ts | 8 +++++--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 data/fixtures/scopes/r/statement/statement.assignment.scope create mode 100644 data/fixtures/scopes/r/statement/statement.assignment2.scope diff --git a/data/fixtures/scopes/r/statement/statement.assignment.scope b/data/fixtures/scopes/r/statement/statement.assignment.scope new file mode 100644 index 0000000000..69ff0379f0 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.assignment.scope @@ -0,0 +1,10 @@ +foo <- 0 +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:8 + >--------< +0| foo <- 0 + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/statement/statement.assignment2.scope b/data/fixtures/scopes/r/statement/statement.assignment2.scope new file mode 100644 index 0000000000..acdb2b1498 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.assignment2.scope @@ -0,0 +1,10 @@ +foo = 0 +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:7 + >-------< +0| foo = 0 + +[Insertion delimiter] = "\n" diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 5d418e894c..5577ccd478 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -1,7 +1,7 @@ import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -const { supported, notApplicable } = ScopeSupportFacetLevel; +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const rScopeSupport: LanguageScopeSupportFacetMap = { disqualifyDelimiter: supported, @@ -105,8 +105,6 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "value.iteration.document": supported, "value.iteration.block": supported, - fieldAccess: supported, - "interior.function": supported, "interior.lambda": supported, "interior.if": supported, @@ -115,6 +113,10 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "interior.foreach": supported, "interior.while": supported, + /* UNSUPPORTED */ + + fieldAccess: unsupported, + /* NOT APPLICABLE */ // Assignment From bb673841663a2fe5b19898a41236c1e07bcbd384 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 13:07:08 +0100 Subject: [PATCH 07/12] try --- .../r/branch/branch.try.iteration.scope | 7 ++ .../fixtures/scopes/r/branch/branch.try.scope | 72 +++++++++++++++++++ .../scopes/r/interior/interior.try.scope | 42 +++++++++++ queries/r.scm | 19 +++++ 4 files changed, 140 insertions(+) create mode 100644 data/fixtures/scopes/r/branch/branch.try.iteration.scope create mode 100644 data/fixtures/scopes/r/branch/branch.try.scope create mode 100644 data/fixtures/scopes/r/interior/interior.try.scope diff --git a/data/fixtures/scopes/r/branch/branch.try.iteration.scope b/data/fixtures/scopes/r/branch/branch.try.iteration.scope new file mode 100644 index 0000000000..c3bbb1b4cd --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.try.iteration.scope @@ -0,0 +1,7 @@ +tryCatch( ) +--- + +[Content] = +[Domain] = 0:9-0:10 + >-< +0| tryCatch( ) diff --git a/data/fixtures/scopes/r/branch/branch.try.scope b/data/fixtures/scopes/r/branch/branch.try.scope new file mode 100644 index 0000000000..3af46e4910 --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.try.scope @@ -0,0 +1,72 @@ +tryCatch( + expr = {}, + error = function() {}, + warning = function() {}, + finally = {} +) +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:13 + >---------< +1| expr = {}, + +[#1 Removal] = 1:0-1:13 + >-------------< +1| expr = {}, + +[#1 Leading delimiter] = 1:0-1:4 + >----< +1| expr = {}, + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:25 + >---------------------< +2| error = function() {}, + +[#2 Removal] = 2:0-2:25 + >-------------------------< +2| error = function() {}, + +[#2 Leading delimiter] = 2:0-2:4 + >----< +2| error = function() {}, + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 3:4-3:27 + >-----------------------< +3| warning = function() {}, + +[#3 Removal] = 3:0-3:27 + >---------------------------< +3| warning = function() {}, + +[#3 Leading delimiter] = 3:0-3:4 + >----< +3| warning = function() {}, + +[#3 Insertion delimiter] = "\n" + + +[#4 Content] = +[#4 Domain] = 4:4-4:16 + >------------< +4| finally = {} + +[#4 Removal] = 4:0-5:0 + >---------------- +4| finally = {} +5| ) + < + +[#4 Leading delimiter] = 4:0-4:4 + >----< +4| finally = {} + +[#4 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/interior/interior.try.scope b/data/fixtures/scopes/r/interior/interior.try.scope new file mode 100644 index 0000000000..dd251f0dd2 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.try.scope @@ -0,0 +1,42 @@ +tryCatch( + expr = { }, + error = function() { }, + warning = function() { }, + finally = { } +) +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 1:12-1:13 + >-< +1| expr = { }, + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 2:24-2:25 + >-< +2| error = function() { }, + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 3:26-3:27 + >-< +3| warning = function() { }, + +[#3 Insertion delimiter] = " " + + +[#4 Content] = +[#4 Removal] = +[#4 Domain] = 4:15-4:16 + >-< +4| finally = { } + +[#4 Insertion delimiter] = " " diff --git a/queries/r.scm b/queries/r.scm index 4e3742a808..c6fae34f63 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -220,6 +220,25 @@ (#eq? @_dummy switch) ) @value.domain +;;!! tryCatch() +(call + function: (_) @_dummy + (arguments + (argument) @branch + ) + (#eq? @_dummy tryCatch) +) + +;;!! tryCatch() +(call + function: (_) @_dummy + (arguments + "(" @branch.iteration.start.endOf + ")" @branch.iteration.end.startOf + ) + (#eq? @_dummy tryCatch) +) + ;;!! return(0, 1) ;;! ^^^^ (call From 532a81f3dd2be410314c6e25b5f4791905bb0c2c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 13:31:51 +0100 Subject: [PATCH 08/12] switch case --- .../branch/branch.switchCase.iteration.scope | 7 +++ .../scopes/r/branch/branch.switchCase.scope | 55 +++++++++++++++++++ .../r/interior/interior.switchCase.scope | 34 ++++++++++++ packages/common/src/scopeSupportFacets/r.ts | 3 +- queries/r.scm | 42 ++++++++++++-- 5 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 data/fixtures/scopes/r/branch/branch.switchCase.iteration.scope create mode 100644 data/fixtures/scopes/r/branch/branch.switchCase.scope create mode 100644 data/fixtures/scopes/r/interior/interior.switchCase.scope diff --git a/data/fixtures/scopes/r/branch/branch.switchCase.iteration.scope b/data/fixtures/scopes/r/branch/branch.switchCase.iteration.scope new file mode 100644 index 0000000000..aebe9ab01f --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.switchCase.iteration.scope @@ -0,0 +1,7 @@ +switch( ) +--- + +[Content] = +[Domain] = 0:7-0:8 + >-< +0| switch( ) diff --git a/data/fixtures/scopes/r/branch/branch.switchCase.scope b/data/fixtures/scopes/r/branch/branch.switchCase.scope new file mode 100644 index 0000000000..d8e59b2fee --- /dev/null +++ b/data/fixtures/scopes/r/branch/branch.switchCase.scope @@ -0,0 +1,55 @@ +switch(foo, + a = 0, + b = {}, + "_" +) +--- + +[#1 Content] = +[#1 Domain] = 1:2-1:7 + >-----< +1| a = 0, + +[#1 Removal] = 1:0-1:7 + >-------< +1| a = 0, + +[#1 Leading delimiter] = 1:0-1:2 + >--< +1| a = 0, + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:2-2:8 + >------< +2| b = {}, + +[#2 Removal] = 2:0-2:8 + >--------< +2| b = {}, + +[#2 Leading delimiter] = 2:0-2:2 + >--< +2| b = {}, + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 3:2-3:5 + >---< +3| "_" + +[#3 Removal] = 3:0-4:0 + >----- +3| "_" +4| ) + < + +[#3 Leading delimiter] = 3:0-3:2 + >--< +3| "_" + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/interior/interior.switchCase.scope b/data/fixtures/scopes/r/interior/interior.switchCase.scope new file mode 100644 index 0000000000..4190f2b715 --- /dev/null +++ b/data/fixtures/scopes/r/interior/interior.switchCase.scope @@ -0,0 +1,34 @@ +switch(foo, + a = bar, + b = { + baz + }, + "_" +) +--- + +[#1 Content] = 1:6-1:9 + >---< +1| a = bar, + +[#1 Removal] = +[#1 Domain] = 1:5-1:9 + >----< +1| a = bar, + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 3:4-3:7 + >---< +3| baz + +[#2 Removal] = +[#2 Domain] = 2:7-4:2 + > +2| b = { +3| baz +4| }, + --< + +[#2 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 5577ccd478..cd1b5d70a5 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -109,7 +109,7 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "interior.lambda": supported, "interior.if": supported, "interior.try": supported, - "interior.switch": supported, + "interior.switchCase": supported, "interior.foreach": supported, "interior.while": supported, @@ -352,6 +352,7 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { // Miscellaneous "comment.block": notApplicable, "textFragment.comment.block": notApplicable, + "interior.switch": notApplicable, environment: notApplicable, pairDelimiter: notApplicable, regularExpression: notApplicable, diff --git a/queries/r.scm b/queries/r.scm index c6fae34f63..9fe3d5475a 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -208,19 +208,50 @@ (#match? @_dummy "^(c|list)$") ) @list -;;!! switch(foo, ...) +;;!! switch(foo, ) ;;! ^^^ +;;! ^^^^^ (call function: (_) @_dummy (arguments - "(" + "(" @branch.iteration.start.endOf . - (argument) @value + (argument)? @value + ")" @branch.iteration.end.startOf ) (#eq? @_dummy switch) ) @value.domain -;;!! tryCatch() +;;!! switch(foo, aaa=0) +;;! ^^^^^ +(call + function: (_) @_dummy + (arguments + . + (argument) + (argument) @branch + ) + (#eq? @_dummy switch) +) + +;;!! switch(foo, aaa=0) +;;! ^ +(call + function: (_) @_dummy + (arguments + . + (argument) + (argument + "=" @interior.start.endOf + value: (_) @interior.end.endOf + ) + ) + (#eq? @_dummy switch) + (#not-type? @interior.end.endOf braced_expression) +) + +;;!! tryCatch({}) +;;! ^^ (call function: (_) @_dummy (arguments @@ -229,7 +260,8 @@ (#eq? @_dummy tryCatch) ) -;;!! tryCatch() +;;!! tryCatch( ) +;;! ^ (call function: (_) @_dummy (arguments From 269a83a78f65a593db00da42efe05875b42cffd5 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 13:41:13 +0100 Subject: [PATCH 09/12] block iteration --- .../scopes/r/name/name.iteration.block.scope | 13 +++++++ .../scopes/r/name/name.iteration.block2.scope | 34 +++++++++++++++++++ .../scopes/r/name/name.iteration.block3.scope | 13 +++++++ .../statement/statement.iteration.block.scope | 13 +++++++ .../statement.iteration.block2.scope | 34 +++++++++++++++++++ .../statement.iteration.block3.scope | 13 +++++++ .../r/value/value.iteration.block.scope | 13 +++++++ .../r/value/value.iteration.block2.scope | 34 +++++++++++++++++++ .../r/value/value.iteration.block3.scope | 13 +++++++ queries/r.scm | 12 +++++-- 10 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 data/fixtures/scopes/r/name/name.iteration.block.scope create mode 100644 data/fixtures/scopes/r/name/name.iteration.block2.scope create mode 100644 data/fixtures/scopes/r/name/name.iteration.block3.scope create mode 100644 data/fixtures/scopes/r/statement/statement.iteration.block.scope create mode 100644 data/fixtures/scopes/r/statement/statement.iteration.block2.scope create mode 100644 data/fixtures/scopes/r/statement/statement.iteration.block3.scope create mode 100644 data/fixtures/scopes/r/value/value.iteration.block.scope create mode 100644 data/fixtures/scopes/r/value/value.iteration.block2.scope create mode 100644 data/fixtures/scopes/r/value/value.iteration.block3.scope diff --git a/data/fixtures/scopes/r/name/name.iteration.block.scope b/data/fixtures/scopes/r/name/name.iteration.block.scope new file mode 100644 index 0000000000..0ed0365560 --- /dev/null +++ b/data/fixtures/scopes/r/name/name.iteration.block.scope @@ -0,0 +1,13 @@ +function() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| function() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| function() { } diff --git a/data/fixtures/scopes/r/name/name.iteration.block2.scope b/data/fixtures/scopes/r/name/name.iteration.block2.scope new file mode 100644 index 0000000000..54cf3712d4 --- /dev/null +++ b/data/fixtures/scopes/r/name/name.iteration.block2.scope @@ -0,0 +1,34 @@ +if (TRUE) { +} else if (FALSE) { +} else { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-2:10 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else { } + ----------< + + +[#2 Content] = +[#2 Domain] = 0:11-1:0 + > +0| if (TRUE) { +1| } else if (FALSE) { + < + + +[#3 Content] = +[#3 Domain] = 1:19-2:0 + > +1| } else if (FALSE) { +2| } else { } + < + + +[#4 Content] = +[#4 Domain] = 2:8-2:9 + >-< +2| } else { } diff --git a/data/fixtures/scopes/r/name/name.iteration.block3.scope b/data/fixtures/scopes/r/name/name.iteration.block3.scope new file mode 100644 index 0000000000..f13372d5da --- /dev/null +++ b/data/fixtures/scopes/r/name/name.iteration.block3.scope @@ -0,0 +1,13 @@ +while (TRUE) { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:16 + >----------------< +0| while (TRUE) { } + + +[#2 Content] = +[#2 Domain] = 0:14-0:15 + >-< +0| while (TRUE) { } diff --git a/data/fixtures/scopes/r/statement/statement.iteration.block.scope b/data/fixtures/scopes/r/statement/statement.iteration.block.scope new file mode 100644 index 0000000000..0ed0365560 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.iteration.block.scope @@ -0,0 +1,13 @@ +function() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| function() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| function() { } diff --git a/data/fixtures/scopes/r/statement/statement.iteration.block2.scope b/data/fixtures/scopes/r/statement/statement.iteration.block2.scope new file mode 100644 index 0000000000..54cf3712d4 --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.iteration.block2.scope @@ -0,0 +1,34 @@ +if (TRUE) { +} else if (FALSE) { +} else { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-2:10 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else { } + ----------< + + +[#2 Content] = +[#2 Domain] = 0:11-1:0 + > +0| if (TRUE) { +1| } else if (FALSE) { + < + + +[#3 Content] = +[#3 Domain] = 1:19-2:0 + > +1| } else if (FALSE) { +2| } else { } + < + + +[#4 Content] = +[#4 Domain] = 2:8-2:9 + >-< +2| } else { } diff --git a/data/fixtures/scopes/r/statement/statement.iteration.block3.scope b/data/fixtures/scopes/r/statement/statement.iteration.block3.scope new file mode 100644 index 0000000000..f13372d5da --- /dev/null +++ b/data/fixtures/scopes/r/statement/statement.iteration.block3.scope @@ -0,0 +1,13 @@ +while (TRUE) { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:16 + >----------------< +0| while (TRUE) { } + + +[#2 Content] = +[#2 Domain] = 0:14-0:15 + >-< +0| while (TRUE) { } diff --git a/data/fixtures/scopes/r/value/value.iteration.block.scope b/data/fixtures/scopes/r/value/value.iteration.block.scope new file mode 100644 index 0000000000..0ed0365560 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.iteration.block.scope @@ -0,0 +1,13 @@ +function() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| function() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| function() { } diff --git a/data/fixtures/scopes/r/value/value.iteration.block2.scope b/data/fixtures/scopes/r/value/value.iteration.block2.scope new file mode 100644 index 0000000000..54cf3712d4 --- /dev/null +++ b/data/fixtures/scopes/r/value/value.iteration.block2.scope @@ -0,0 +1,34 @@ +if (TRUE) { +} else if (FALSE) { +} else { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-2:10 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else { } + ----------< + + +[#2 Content] = +[#2 Domain] = 0:11-1:0 + > +0| if (TRUE) { +1| } else if (FALSE) { + < + + +[#3 Content] = +[#3 Domain] = 1:19-2:0 + > +1| } else if (FALSE) { +2| } else { } + < + + +[#4 Content] = +[#4 Domain] = 2:8-2:9 + >-< +2| } else { } diff --git a/data/fixtures/scopes/r/value/value.iteration.block3.scope b/data/fixtures/scopes/r/value/value.iteration.block3.scope new file mode 100644 index 0000000000..f13372d5da --- /dev/null +++ b/data/fixtures/scopes/r/value/value.iteration.block3.scope @@ -0,0 +1,13 @@ +while (TRUE) { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:16 + >----------------< +0| while (TRUE) { } + + +[#2 Content] = +[#2 Domain] = 0:14-0:15 + >-< +0| while (TRUE) { } diff --git a/queries/r.scm b/queries/r.scm index 9fe3d5475a..464d238db4 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -15,6 +15,9 @@ ;; (function_definition) ] @statement +(program) @statement.iteration @namedFunction.iteration +(program) @name.iteration @value.iteration + ;;!! { } ;;! ^ (_ @@ -23,9 +26,12 @@ "}" @interior.end.startOf . ) - -(program) @statement.iteration @namedFunction.iteration -(program) @name.iteration @value.iteration +(_ + . + "{" @statement.iteration.start.endOf @name.iteration.start.endOf @value.iteration.start.endOf + "}" @statement.iteration.end.startOf @name.iteration.end.startOf @value.iteration.end.startOf + . +) ;;!! # hello world ;;! ^^^^^^^^^^^^^ From 34836e02aee303db198a1d0d289f85125fa9fe21 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 13:55:03 +0100 Subject: [PATCH 10/12] switch condition --- .../scopes/r/branch/branch.switchCase.scope | 58 +++++++++---------- .../r/condition.switchCase.iteration.scope | 7 +++ .../scopes/r/condition.switchCase.scope | 26 +++++++++ .../scopes/r/condition.switchCase2.scope | 21 +++++++ .../r/interior/interior.switchCase.scope | 40 ++++++------- packages/common/src/scopeSupportFacets/r.ts | 8 +++ queries/r.scm | 15 ++++- 7 files changed, 123 insertions(+), 52 deletions(-) create mode 100644 data/fixtures/scopes/r/condition.switchCase.iteration.scope create mode 100644 data/fixtures/scopes/r/condition.switchCase.scope create mode 100644 data/fixtures/scopes/r/condition.switchCase2.scope diff --git a/data/fixtures/scopes/r/branch/branch.switchCase.scope b/data/fixtures/scopes/r/branch/branch.switchCase.scope index d8e59b2fee..2b5fe6f85a 100644 --- a/data/fixtures/scopes/r/branch/branch.switchCase.scope +++ b/data/fixtures/scopes/r/branch/branch.switchCase.scope @@ -1,55 +1,55 @@ switch(foo, - a = 0, - b = {}, - "_" + a = 0, + b = {}, + "_" ) --- [#1 Content] = -[#1 Domain] = 1:2-1:7 - >-----< -1| a = 0, +[#1 Domain] = 1:4-1:9 + >-----< +1| a = 0, -[#1 Removal] = 1:0-1:7 - >-------< -1| a = 0, +[#1 Removal] = 1:0-1:9 + >---------< +1| a = 0, -[#1 Leading delimiter] = 1:0-1:2 - >--< -1| a = 0, +[#1 Leading delimiter] = 1:0-1:4 + >----< +1| a = 0, [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Domain] = 2:2-2:8 - >------< -2| b = {}, +[#2 Domain] = 2:4-2:10 + >------< +2| b = {}, -[#2 Removal] = 2:0-2:8 - >--------< -2| b = {}, +[#2 Removal] = 2:0-2:10 + >----------< +2| b = {}, -[#2 Leading delimiter] = 2:0-2:2 - >--< -2| b = {}, +[#2 Leading delimiter] = 2:0-2:4 + >----< +2| b = {}, [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Domain] = 3:2-3:5 - >---< -3| "_" +[#3 Domain] = 3:4-3:7 + >---< +3| "_" [#3 Removal] = 3:0-4:0 - >----- -3| "_" + >------- +3| "_" 4| ) < -[#3 Leading delimiter] = 3:0-3:2 - >--< -3| "_" +[#3 Leading delimiter] = 3:0-3:4 + >----< +3| "_" [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/condition.switchCase.iteration.scope b/data/fixtures/scopes/r/condition.switchCase.iteration.scope new file mode 100644 index 0000000000..aebe9ab01f --- /dev/null +++ b/data/fixtures/scopes/r/condition.switchCase.iteration.scope @@ -0,0 +1,7 @@ +switch( ) +--- + +[Content] = +[Domain] = 0:7-0:8 + >-< +0| switch( ) diff --git a/data/fixtures/scopes/r/condition.switchCase.scope b/data/fixtures/scopes/r/condition.switchCase.scope new file mode 100644 index 0000000000..760f7980b5 --- /dev/null +++ b/data/fixtures/scopes/r/condition.switchCase.scope @@ -0,0 +1,26 @@ +switch(foo, + a = 0 +) +--- + +[Content] = 1:4-1:5 + >-< +1| a = 0 + +[Removal] = 1:4-1:6 + >--< +1| a = 0 + +[Leading delimiter] = 1:0-1:4 + >----< +1| a = 0 + +[Trailing delimiter] = 1:5-1:6 + >-< +1| a = 0 + +[Domain] = 1:4-1:9 + >-----< +1| a = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/condition.switchCase2.scope b/data/fixtures/scopes/r/condition.switchCase2.scope new file mode 100644 index 0000000000..a465b4a1a3 --- /dev/null +++ b/data/fixtures/scopes/r/condition.switchCase2.scope @@ -0,0 +1,21 @@ +switch(foo, + "_" +) +--- + +[Content] = +[Domain] = 1:4-1:7 + >---< +1| "_" + +[Removal] = 1:0-2:0 + >------- +1| "_" +2| ) + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| "_" + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/interior/interior.switchCase.scope b/data/fixtures/scopes/r/interior/interior.switchCase.scope index 4190f2b715..8ed16096cd 100644 --- a/data/fixtures/scopes/r/interior/interior.switchCase.scope +++ b/data/fixtures/scopes/r/interior/interior.switchCase.scope @@ -1,34 +1,34 @@ switch(foo, - a = bar, - b = { - baz - }, - "_" + a = bar, + b = { + baz + }, + "_" ) --- -[#1 Content] = 1:6-1:9 - >---< -1| a = bar, +[#1 Content] = 1:8-1:11 + >---< +1| a = bar, [#1 Removal] = -[#1 Domain] = 1:5-1:9 - >----< -1| a = bar, +[#1 Domain] = 1:7-1:11 + >----< +1| a = bar, [#1 Insertion delimiter] = " " -[#2 Content] = 3:4-3:7 - >---< -3| baz +[#2 Content] = 3:8-3:11 + >---< +3| baz [#2 Removal] = -[#2 Domain] = 2:7-4:2 - > -2| b = { -3| baz -4| }, - --< +[#2 Domain] = 2:9-4:4 + > +2| b = { +3| baz +4| }, + ----< [#2 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index cd1b5d70a5..0480735e58 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -47,6 +47,8 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { "condition.if": supported, "condition.while": supported, + "condition.switchCase": supported, + "condition.switchCase.iteration": supported, functionCall: supported, "functionCall.method": supported, @@ -163,9 +165,15 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = { // Constructor "statement.constructor": notApplicable, "namedFunction.constructor": notApplicable, + "argument.actual.constructor.singleLine": notApplicable, + "argument.actual.constructor.multiLine": notApplicable, + "argument.actual.constructor.iteration": notApplicable, "argument.formal.constructor.singleLine": notApplicable, "argument.formal.constructor.multiLine": notApplicable, "argument.formal.constructor.iteration": notApplicable, + "argumentList.actual.constructor.empty": notApplicable, + "argumentList.actual.constructor.singleLine": notApplicable, + "argumentList.actual.constructor.multiLine": notApplicable, "argumentList.formal.constructor.empty": notApplicable, "argumentList.formal.constructor.singleLine": notApplicable, "argumentList.formal.constructor.multiLine": notApplicable, diff --git a/queries/r.scm b/queries/r.scm index 464d238db4..752bab2813 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -220,22 +220,31 @@ (call function: (_) @_dummy (arguments - "(" @branch.iteration.start.endOf + "(" @branch.iteration.start.endOf @condition.iteration.start.endOf . (argument)? @value - ")" @branch.iteration.end.startOf + ")" @branch.iteration.end.startOf @condition.iteration.end.startOf ) (#eq? @_dummy switch) ) @value.domain ;;!! switch(foo, aaa=0) +;;! ^^^ ;;! ^^^^^ (call function: (_) @_dummy (arguments . (argument) - (argument) @branch + [ + (argument + name: (_) @condition + ) + (argument + !name + value: (_) @condition + ) + ] @branch @condition.domain ) (#eq? @_dummy switch) ) From 17f2d668331bcb6a0059616f64d01a58f1e2c6bc Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 14:22:30 +0100 Subject: [PATCH 11/12] Update if statement --- .../scopes/r/branch/branch.if.elif.else.scope | 33 +++++++++++-------- .../scopes/r/branch/branch.if.else.scope | 31 +++++++++-------- .../scopes/r/branch/branch.if.iteration.scope | 10 +++--- data/fixtures/scopes/r/branch/branch.if.scope | 13 +++++--- data/fixtures/scopes/r/ifStatement.scope | 15 ++++++--- .../scopes/r/interior/interior.if.scope | 13 +++++--- .../scopes/r/statement/statement.if.scope | 10 +++--- queries/r.scm | 3 ++ 8 files changed, 79 insertions(+), 49 deletions(-) diff --git a/data/fixtures/scopes/r/branch/branch.if.elif.else.scope b/data/fixtures/scopes/r/branch/branch.if.elif.else.scope index 5935ebfafb..354581a605 100644 --- a/data/fixtures/scopes/r/branch/branch.if.elif.else.scope +++ b/data/fixtures/scopes/r/branch/branch.if.elif.else.scope @@ -1,6 +1,7 @@ if (TRUE) { } else if (FALSE) { -} else {} +} else { +} --- [#1 Content] = @@ -20,20 +21,20 @@ if (TRUE) { >-< 1| } else if (FALSE) { -[#1 Insertion delimiter] = "\n" +[#1 Insertion delimiter] = " " [#2 Content] = [#2 Domain] = 1:2-2:1 >----------------- 1| } else if (FALSE) { -2| } else {} +2| } else { -< [#2 Removal] = 1:2-2:2 >----------------- 1| } else if (FALSE) { -2| } else {} +2| } else { --< [#2 Leading delimiter] = 1:1-1:2 @@ -42,22 +43,26 @@ if (TRUE) { [#2 Trailing delimiter] = 2:1-2:2 >-< -2| } else {} +2| } else { -[#2 Insertion delimiter] = "\n" +[#2 Insertion delimiter] = " " [#3 Content] = -[#3 Domain] = 2:2-2:9 - >-------< -2| } else {} +[#3 Domain] = 2:2-3:1 + >------ +2| } else { +3| } + -< -[#3 Removal] = 2:1-2:9 - >--------< -2| } else {} +[#3 Removal] = 2:1-3:1 + >------- +2| } else { +3| } + -< [#3 Leading delimiter] = 2:1-2:2 >-< -2| } else {} +2| } else { -[#3 Insertion delimiter] = "\n" +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/branch/branch.if.else.scope b/data/fixtures/scopes/r/branch/branch.if.else.scope index 068136316f..64c3b49ca7 100644 --- a/data/fixtures/scopes/r/branch/branch.if.else.scope +++ b/data/fixtures/scopes/r/branch/branch.if.else.scope @@ -1,38 +1,43 @@ if (TRUE) { -} else {} +} else { +} --- [#1 Content] = [#1 Domain] = 0:0-1:1 >----------- 0| if (TRUE) { -1| } else {} +1| } else { -< [#1 Removal] = 0:0-1:2 >----------- 0| if (TRUE) { -1| } else {} +1| } else { --< [#1 Trailing delimiter] = 1:1-1:2 >-< -1| } else {} +1| } else { -[#1 Insertion delimiter] = "\n" +[#1 Insertion delimiter] = " " [#2 Content] = -[#2 Domain] = 1:2-1:9 - >-------< -1| } else {} +[#2 Domain] = 1:2-2:1 + >------ +1| } else { +2| } + -< -[#2 Removal] = 1:1-1:9 - >--------< -1| } else {} +[#2 Removal] = 1:1-2:1 + >------- +1| } else { +2| } + -< [#2 Leading delimiter] = 1:1-1:2 >-< -1| } else {} +1| } else { -[#2 Insertion delimiter] = "\n" +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/branch/branch.if.iteration.scope b/data/fixtures/scopes/r/branch/branch.if.iteration.scope index 690f881ce5..3caeb0ea69 100644 --- a/data/fixtures/scopes/r/branch/branch.if.iteration.scope +++ b/data/fixtures/scopes/r/branch/branch.if.iteration.scope @@ -1,12 +1,14 @@ if (TRUE) { } else if (FALSE) { -} else {} +} else { +} --- [Content] = -[Domain] = 0:0-2:9 +[Domain] = 0:0-3:1 >----------- 0| if (TRUE) { 1| } else if (FALSE) { -2| } else {} - ---------< +2| } else { +3| } + -< diff --git a/data/fixtures/scopes/r/branch/branch.if.scope b/data/fixtures/scopes/r/branch/branch.if.scope index 6894c02809..42ec6d3390 100644 --- a/data/fixtures/scopes/r/branch/branch.if.scope +++ b/data/fixtures/scopes/r/branch/branch.if.scope @@ -1,10 +1,13 @@ -if (TRUE) {} +if (TRUE) { +} --- [Content] = [Removal] = -[Domain] = 0:0-0:12 - >------------< -0| if (TRUE) {} +[Domain] = 0:0-1:1 + >----------- +0| if (TRUE) { +1| } + -< -[Insertion delimiter] = "\n" +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/ifStatement.scope b/data/fixtures/scopes/r/ifStatement.scope index dff608890b..83edea49b5 100644 --- a/data/fixtures/scopes/r/ifStatement.scope +++ b/data/fixtures/scopes/r/ifStatement.scope @@ -1,10 +1,17 @@ -if(TRUE) {} +if (TRUE) { +} else if (FALSE) { +} else { +} --- [Content] = [Removal] = -[Domain] = 0:0-0:11 - >-----------< -0| if(TRUE) {} +[Domain] = 0:0-3:1 + >----------- +0| if (TRUE) { +1| } else if (FALSE) { +2| } else { +3| } + -< [Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/interior/interior.if.scope b/data/fixtures/scopes/r/interior/interior.if.scope index 6efbe863b0..f1328fccfc 100644 --- a/data/fixtures/scopes/r/interior/interior.if.scope +++ b/data/fixtures/scopes/r/interior/interior.if.scope @@ -1,6 +1,7 @@ if (TRUE) { } else if (FALSE) { -} else { } +} else { +} --- [#1 Content] = @@ -19,7 +20,7 @@ if (TRUE) { [#2 Domain] = 1:19-2:0 > 1| } else if (FALSE) { -2| } else { } +2| } else { < [#2 Insertion delimiter] = " " @@ -27,8 +28,10 @@ if (TRUE) { [#3 Content] = [#3 Removal] = -[#3 Domain] = 2:8-2:9 - >-< -2| } else { } +[#3 Domain] = 2:8-3:0 + > +2| } else { +3| } + < [#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/statement/statement.if.scope b/data/fixtures/scopes/r/statement/statement.if.scope index e4b67572d7..83edea49b5 100644 --- a/data/fixtures/scopes/r/statement/statement.if.scope +++ b/data/fixtures/scopes/r/statement/statement.if.scope @@ -1,15 +1,17 @@ if (TRUE) { } else if (FALSE) { -} else {} +} else { +} --- [Content] = [Removal] = -[Domain] = 0:0-2:9 +[Domain] = 0:0-3:1 >----------- 0| if (TRUE) { 1| } else if (FALSE) { -2| } else {} - ---------< +2| } else { +3| } + -< [Insertion delimiter] = "\n" diff --git a/queries/r.scm b/queries/r.scm index 752bab2813..0e934ad21a 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -60,6 +60,7 @@ alternative: (if_statement)? @branch.removal.end.startOf ) @condition.domain (#not-parent-type? @condition.domain if_statement) + (#insertion-delimiter! @branch.start " ") ) ;;!! else if () {} @@ -69,12 +70,14 @@ condition: (_) @condition consequence: (_) @branch.end @condition.domain.end ) + (#insertion-delimiter! @branch.start " ") ) ;;!! else {} (if_statement "else" @branch.start alternative: (braced_expression) @branch.end + (#insertion-delimiter! @branch.start " ") ) ;;!! foo <- function(){} From 5b61c7769df3e85900df96adb6d990bfbd555d75 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 14 Feb 2026 14:28:28 +0100 Subject: [PATCH 12/12] Added conditions --- queries/r.scm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/queries/r.scm b/queries/r.scm index 0e934ad21a..29df41d408 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -5,16 +5,30 @@ (for_statement) (repeat_statement) (while_statement) - (binary_operator) - (call) (next) (break) ;; Disabled on purpose. We have a better definition of these below. ;; (if_statement) ;; (function_definition) + ;; (binary_operator) + ;; (call) ] @statement +(program + [ + (binary_operator) + (call) + ] @statement +) + +(braced_expression + [ + (binary_operator) + (call) + ] @statement +) + (program) @statement.iteration @namedFunction.iteration (program) @name.iteration @value.iteration @@ -308,6 +322,10 @@ ;;! ^ (binary_operator lhs: (_) @name @value.leading.endOf + operator: [ + "<-" + "=" + ] rhs: (_) @value @name.trailing.startOf ) @_.domain