From 955dcdc132e728a62ce6e96c2d4bb94c5770fbb0 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 12:08:25 +0100 Subject: [PATCH 01/17] Update go scope facets support --- packages/common/src/scopeSupportFacets/go.ts | 305 ++++++++++++++++++- 1 file changed, 303 insertions(+), 2 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/go.ts b/packages/common/src/scopeSupportFacets/go.ts index 835ea8a95e..a1df12a6f4 100644 --- a/packages/common/src/scopeSupportFacets/go.ts +++ b/packages/common/src/scopeSupportFacets/go.ts @@ -1,18 +1,319 @@ import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -// eslint-disable-next-line @typescript-eslint/no-unused-vars const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const goScopeSupport: LanguageScopeSupportFacetMap = { disqualifyDelimiter: supported, + list: supported, + map: supported, + + ifStatement: supported, + + "statement.interface": supported, + "statement.function": supported, + "statement.method": supported, + "statement.if": supported, + "statement.switch": supported, + "statement.for": supported, + "statement.foreach": supported, + "statement.variable": supported, + "statement.assignment": supported, + "statement.return": supported, + "statement.break": supported, + "statement.continue": supported, + "statement.iteration.document": supported, + "statement.iteration.interface": supported, + "statement.iteration.block": supported, + + namedFunction: supported, + "namedFunction.method": supported, + "namedFunction.iteration.document": supported, + anonymousFunction: supported, + + functionCall: supported, + "functionCall.method": supported, + "functionCall.chain": supported, + functionCallee: supported, + "functionCallee.method": supported, + "functionCallee.chain": 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.method.singleLine": supported, + "argument.formal.method.multiLine": supported, + "argument.formal.method.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, + "argumentList.actual.multiLine": supported, + "argumentList.actual.method.empty": supported, + "argumentList.actual.method.singleLine": supported, + "argumentList.actual.method.multiLine": supported, + "argumentList.formal.empty": supported, + "argumentList.formal.singleLine": supported, + "argumentList.formal.multiLine": supported, + "argumentList.formal.lambda.empty": supported, + "argumentList.formal.lambda.singleLine": supported, + "argumentList.formal.lambda.multiLine": supported, + "argumentList.formal.method.empty": supported, + "argumentList.formal.method.singleLine": supported, + "argumentList.formal.method.multiLine": supported, + "comment.line": supported, + "comment.block": supported, "string.singleLine": supported, "string.multiLine": supported, + "textFragment.comment.line": supported, + "textFragment.comment.block": supported, "textFragment.string.singleLine": supported, "textFragment.string.multiLine": supported, - "textFragment.comment.line": supported, + + "branch.if": supported, + "branch.if.elif.else": supported, + "branch.if.else": supported, + "branch.if.iteration": supported, + "branch.switchCase": supported, + "branch.switchCase.iteration": supported, + + "collectionItem.unenclosed.singleLine": supported, + "collectionItem.unenclosed.multiLine": supported, + "collectionItem.unenclosed.iteration": supported, + + "condition.if": supported, + "condition.for": supported, + "condition.switchCase": supported, + "condition.switchCase.iteration": supported, + + "name.assignment": supported, + "name.variable": supported, + "name.foreach": supported, + "name.function": supported, + "name.method": supported, + "name.interface": supported, + "name.argument.formal": supported, + "name.argument.formal.iteration": supported, + "name.argument.formal.method": supported, + "name.argument.formal.method.iteration": supported, + "name.iteration.block": supported, + "name.iteration.document": supported, + "name.iteration.interface": supported, + + "key.mapPair": supported, + "key.mapPair.iteration": supported, + + "value.assignment": supported, + "value.variable": supported, + "value.mapPair": supported, + "value.mapPair.iteration": supported, + "value.foreach": supported, + "value.return": supported, + "value.switch": supported, + "value.typeAlias": supported, + "value.iteration.block": supported, + "value.iteration.document": supported, + + "type.variable": supported, + "type.argument.formal": supported, + "type.argument.formal.iteration": supported, + "type.argument.formal.method": supported, + "type.argument.formal.method.iteration": supported, + "type.return": supported, + "type.interface": supported, + "type.alias": supported, + "type.cast": supported, + "type.typeArgument": supported, + "type.typeArgument.iteration": supported, + "type.iteration.block": supported, + "type.iteration.document": supported, + "type.iteration.interface": supported, + + "interior.interface": supported, + "interior.function": supported, + "interior.method": supported, + "interior.lambda": supported, + "interior.if": supported, + "interior.switch": supported, + "interior.switchCase": supported, + "interior.for": supported, + "interior.foreach": supported, + + /* UNSUPPORTED */ + + fieldAccess: unsupported, + + /* NOT APPLICABLE */ + + // Element and tags + element: notApplicable, + tags: notApplicable, + startTag: notApplicable, + endTag: notApplicable, + "interior.element": notApplicable, + "textFragment.element": notApplicable, + + // Attributes + attribute: notApplicable, + "key.attribute": notApplicable, + "value.attribute": notApplicable, + + // Section + section: notApplicable, + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + + // Command + command: notApplicable, + "statement.command": notApplicable, + "name.command": notApplicable, + "value.command": notApplicable, + "interior.command": notApplicable, + + // Class + class: notApplicable, + "class.iteration.document": notApplicable, + "class.iteration.block": notApplicable, + "statement.class": notApplicable, + "statement.field.class": notApplicable, + "statement.iteration.class": notApplicable, + "namedFunction.iteration.class": notApplicable, + "name.class": notApplicable, + "name.field.class": notApplicable, + "name.iteration.class": notApplicable, + "type.class": notApplicable, + "type.field.class": notApplicable, + "type.iteration.class": notApplicable, + "interior.class": notApplicable, + "value.field.class": notApplicable, + "value.iteration.class": notApplicable, + + // Enum + "statement.enum": notApplicable, + "name.enum": notApplicable, + "name.field.enum": notApplicable, + "name.iteration.enum": notApplicable, + "type.enum": notApplicable, + "interior.enum": notApplicable, + "value.field.enum": notApplicable, + "value.iteration.enum": notApplicable, + + // Interface field declarations + "statement.field.interface": notApplicable, + "name.field.interface": notApplicable, + "type.field.interface": notApplicable, + + // Constructors + "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, + "functionCall.constructor": notApplicable, + "functionCallee.constructor": notApplicable, + "name.constructor": notApplicable, + "name.argument.formal.constructor": notApplicable, + "name.argument.formal.constructor.iteration": notApplicable, + "type.argument.formal.constructor": notApplicable, + "type.argument.formal.constructor.iteration": notApplicable, + "value.argument.formal.constructor": notApplicable, + "value.argument.formal.constructor.iteration": notApplicable, + "interior.constructor": notApplicable, + + // Namespace + "statement.namespace": notApplicable, + "name.namespace": notApplicable, + "interior.namespace": notApplicable, + + // Try / catch + "statement.try": notApplicable, + "branch.try": notApplicable, + "branch.try.iteration": notApplicable, + "interior.try": notApplicable, + "argument.catch": notApplicable, + "name.argument.catch": notApplicable, + "type.argument.catch": notApplicable, + + // Loop types + "statement.while": notApplicable, + "condition.while": notApplicable, + "interior.while": notApplicable, + "statement.doWhile": notApplicable, + "condition.doWhile": notApplicable, + "interior.doWhile": notApplicable, + "branch.loop": notApplicable, + "branch.loop.iteration": notApplicable, + + // Ternary + "branch.ternary": notApplicable, + "branch.ternary.iteration": notApplicable, + "condition.ternary": notApplicable, + + // Resource syntax + "statement.resource": notApplicable, + "name.resource": notApplicable, + "name.resource.iteration": notApplicable, + "value.resource": notApplicable, + "value.resource.iteration": notApplicable, + "type.resource": notApplicable, + "type.resource.iteration": notApplicable, + "interior.resource": notApplicable, + + // Static + "statement.static": notApplicable, + "interior.static": notApplicable, + + // Keyword arguments + "name.argument.actual": notApplicable, + "name.argument.actual.iteration": notApplicable, + "value.argument.actual": notApplicable, + "value.argument.actual.iteration": notApplicable, + + // Default parameter values + "value.argument.formal": notApplicable, + "value.argument.formal.iteration": notApplicable, + "value.argument.formal.method": notApplicable, + "value.argument.formal.method.iteration": notApplicable, + + // Yield + "statement.yield": notApplicable, + "value.yield": notApplicable, + + // Notebook cell + notebookCell: notApplicable, + "interior.cell": notApplicable, + + // Miscellaneous + "statement.misc": notApplicable, + "name.assignment.pattern": notApplicable, + "name.variable.pattern": notApplicable, + "value.variable.pattern": notApplicable, + "value.return.lambda": notApplicable, + "type.foreach": notApplicable, + regularExpression: notApplicable, + selector: notApplicable, + unit: notApplicable, + pairDelimiter: notApplicable, + environment: notApplicable, }; From d25727c3e293e09225914b1983d99b6ef8735182 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 13:24:30 +0100 Subject: [PATCH 02/17] Started adding scope fixtures --- .../scopes/go/anonymousFunction.scope | 17 ++++++ .../scopes/go/class.iteration.document.scope | 12 ++++ data/fixtures/scopes/go/class.scope | 10 ++++ data/fixtures/scopes/go/comment.block.scope | 10 ++++ data/fixtures/scopes/go/condition.for.scope | 20 +++++++ data/fixtures/scopes/go/condition.if.scope | 57 +++++++++++++++++++ .../scopes/go/functionCall.chain.scope | 19 +++++++ .../scopes/go/functionCall.method.scope | 10 ++++ data/fixtures/scopes/go/functionCall.scope | 10 ++++ .../scopes/go/functionCallee.chain.scope | 25 ++++++++ .../scopes/go/functionCallee.method.scope | 13 +++++ data/fixtures/scopes/go/functionCallee.scope | 13 +++++ data/fixtures/scopes/go/ifStatement.scope | 17 ++++++ .../go/name/name.iteration.document.scope | 12 ++++ .../go/namedFunction.iteration.document.scope | 12 ++++ .../scopes/go/namedFunction.method.scope | 10 ++++ data/fixtures/scopes/go/namedFunction.scope | 10 ++++ .../go/textFragment.comment.block.scope | 10 ++++ .../go/type/type.iteration.document.scope | 12 ++++ .../go/value/value.iteration.document.scope | 12 ++++ packages/common/src/scopeSupportFacets/go.ts | 31 +++++----- queries/go.scm | 45 +++++++++++---- 22 files changed, 362 insertions(+), 25 deletions(-) create mode 100644 data/fixtures/scopes/go/anonymousFunction.scope create mode 100644 data/fixtures/scopes/go/class.iteration.document.scope create mode 100644 data/fixtures/scopes/go/class.scope create mode 100644 data/fixtures/scopes/go/comment.block.scope create mode 100644 data/fixtures/scopes/go/condition.for.scope create mode 100644 data/fixtures/scopes/go/condition.if.scope create mode 100644 data/fixtures/scopes/go/functionCall.chain.scope create mode 100644 data/fixtures/scopes/go/functionCall.method.scope create mode 100644 data/fixtures/scopes/go/functionCall.scope create mode 100644 data/fixtures/scopes/go/functionCallee.chain.scope create mode 100644 data/fixtures/scopes/go/functionCallee.method.scope create mode 100644 data/fixtures/scopes/go/functionCallee.scope create mode 100644 data/fixtures/scopes/go/ifStatement.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.document.scope create mode 100644 data/fixtures/scopes/go/namedFunction.iteration.document.scope create mode 100644 data/fixtures/scopes/go/namedFunction.method.scope create mode 100644 data/fixtures/scopes/go/namedFunction.scope create mode 100644 data/fixtures/scopes/go/textFragment.comment.block.scope create mode 100644 data/fixtures/scopes/go/type/type.iteration.document.scope create mode 100644 data/fixtures/scopes/go/value/value.iteration.document.scope diff --git a/data/fixtures/scopes/go/anonymousFunction.scope b/data/fixtures/scopes/go/anonymousFunction.scope new file mode 100644 index 0000000000..4df5d7defd --- /dev/null +++ b/data/fixtures/scopes/go/anonymousFunction.scope @@ -0,0 +1,17 @@ +foo := func() {} +--- + +[Content] = +[Domain] = 0:7-0:16 + >---------< +0| foo := func() {} + +[Removal] = 0:6-0:16 + >----------< +0| foo := func() {} + +[Leading delimiter] = 0:6-0:7 + >-< +0| foo := func() {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/class.iteration.document.scope b/data/fixtures/scopes/go/class.iteration.document.scope new file mode 100644 index 0000000000..1036138cb1 --- /dev/null +++ b/data/fixtures/scopes/go/class.iteration.document.scope @@ -0,0 +1,12 @@ + +type Foo struct {} + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| type Foo struct {} +2| + < diff --git a/data/fixtures/scopes/go/class.scope b/data/fixtures/scopes/go/class.scope new file mode 100644 index 0000000000..9a7bd2a866 --- /dev/null +++ b/data/fixtures/scopes/go/class.scope @@ -0,0 +1,10 @@ +type Foo struct {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:18 + >------------------< +0| type Foo struct {} + +[Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/go/comment.block.scope b/data/fixtures/scopes/go/comment.block.scope new file mode 100644 index 0000000000..5e8b51111c --- /dev/null +++ b/data/fixtures/scopes/go/comment.block.scope @@ -0,0 +1,10 @@ +/* Hello world */ +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:17 + >-----------------< +0| /* Hello world */ + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/condition.for.scope b/data/fixtures/scopes/go/condition.for.scope new file mode 100644 index 0000000000..e453771326 --- /dev/null +++ b/data/fixtures/scopes/go/condition.for.scope @@ -0,0 +1,20 @@ +for i := 0; i < size; i++ {} +--- + +[Content] = 0:12-0:20 + >--------< +0| for i := 0; i < size; i++ {} + +[Removal] = 0:11-0:20 + >---------< +0| for i := 0; i < size; i++ {} + +[Leading delimiter] = 0:11-0:12 + >-< +0| for i := 0; i < size; i++ {} + +[Domain] = 0:0-0:28 + >----------------------------< +0| for i := 0; i < size; i++ {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/condition.if.scope b/data/fixtures/scopes/go/condition.if.scope new file mode 100644 index 0000000000..0b2a84f7bc --- /dev/null +++ b/data/fixtures/scopes/go/condition.if.scope @@ -0,0 +1,57 @@ +if true { +} else if false { +} else { +} +--- + +[#1 Content] = 0:3-0:7 + >----< +0| if true { + +[#1 Removal] = 0:3-0:8 + >-----< +0| if true { + +[#1 Leading delimiter] = 0:2-0:3 + >-< +0| if true { + +[#1 Trailing delimiter] = 0:7-0:8 + >-< +0| if true { + +[#1 Domain] = 0:0-3:1 + >--------- +0| if true { +1| } else if false { +2| } else { +3| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 1:10-1:15 + >-----< +1| } else if false { + +[#2 Removal] = 1:10-1:16 + >------< +1| } else if false { + +[#2 Leading delimiter] = 1:9-1:10 + >-< +1| } else if false { + +[#2 Trailing delimiter] = 1:15-1:16 + >-< +1| } else if false { + +[#2 Domain] = 1:7-3:1 + >---------- +1| } else if false { +2| } else { +3| } + -< + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCall.chain.scope b/data/fixtures/scopes/go/functionCall.chain.scope new file mode 100644 index 0000000000..c73434c70d --- /dev/null +++ b/data/fixtures/scopes/go/functionCall.chain.scope @@ -0,0 +1,19 @@ +foo().bar() +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:5 + >-----< +0| foo().bar() + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 0:0-0:11 + >-----------< +0| foo().bar() + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCall.method.scope b/data/fixtures/scopes/go/functionCall.method.scope new file mode 100644 index 0000000000..6ab0ba4c3a --- /dev/null +++ b/data/fixtures/scopes/go/functionCall.method.scope @@ -0,0 +1,10 @@ +foo.bar() +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:9 + >---------< +0| foo.bar() + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCall.scope b/data/fixtures/scopes/go/functionCall.scope new file mode 100644 index 0000000000..00162e317c --- /dev/null +++ b/data/fixtures/scopes/go/functionCall.scope @@ -0,0 +1,10 @@ +foo() +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:5 + >-----< +0| foo() + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCallee.chain.scope b/data/fixtures/scopes/go/functionCallee.chain.scope new file mode 100644 index 0000000000..b0b9872650 --- /dev/null +++ b/data/fixtures/scopes/go/functionCallee.chain.scope @@ -0,0 +1,25 @@ +foo().bar() +--- + +[#1 Content] = +[#1 Removal] = 0:0-0:3 + >---< +0| foo().bar() + +[#1 Domain] = 0:0-0:5 + >-----< +0| foo().bar() + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 0:0-0:9 + >---------< +0| foo().bar() + +[#2 Domain] = 0:0-0:11 + >-----------< +0| foo().bar() + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCallee.method.scope b/data/fixtures/scopes/go/functionCallee.method.scope new file mode 100644 index 0000000000..e77bc361ec --- /dev/null +++ b/data/fixtures/scopes/go/functionCallee.method.scope @@ -0,0 +1,13 @@ +foo.bar() +--- + +[Content] = +[Removal] = 0:0-0:7 + >-------< +0| foo.bar() + +[Domain] = 0:0-0:9 + >---------< +0| foo.bar() + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/functionCallee.scope b/data/fixtures/scopes/go/functionCallee.scope new file mode 100644 index 0000000000..2b075b5c33 --- /dev/null +++ b/data/fixtures/scopes/go/functionCallee.scope @@ -0,0 +1,13 @@ +foo() +--- + +[Content] = +[Removal] = 0:0-0:3 + >---< +0| foo() + +[Domain] = 0:0-0:5 + >-----< +0| foo() + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/ifStatement.scope b/data/fixtures/scopes/go/ifStatement.scope new file mode 100644 index 0000000000..8f864e71e7 --- /dev/null +++ b/data/fixtures/scopes/go/ifStatement.scope @@ -0,0 +1,17 @@ +if true { +} else if false { +} else { +} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-3:1 + >--------- +0| if true { +1| } else if false { +2| } else { +3| } + -< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/name/name.iteration.document.scope b/data/fixtures/scopes/go/name/name.iteration.document.scope new file mode 100644 index 0000000000..f70d9ac2c1 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.document.scope @@ -0,0 +1,12 @@ + +var foo int + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| var foo int +2| + < diff --git a/data/fixtures/scopes/go/namedFunction.iteration.document.scope b/data/fixtures/scopes/go/namedFunction.iteration.document.scope new file mode 100644 index 0000000000..46eb837954 --- /dev/null +++ b/data/fixtures/scopes/go/namedFunction.iteration.document.scope @@ -0,0 +1,12 @@ + +func foo() {} + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| func foo() {} +2| + < diff --git a/data/fixtures/scopes/go/namedFunction.method.scope b/data/fixtures/scopes/go/namedFunction.method.scope new file mode 100644 index 0000000000..73fd0487bb --- /dev/null +++ b/data/fixtures/scopes/go/namedFunction.method.scope @@ -0,0 +1,10 @@ +func (f Foo) bar() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| func (f Foo) bar() {} + +[Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/go/namedFunction.scope b/data/fixtures/scopes/go/namedFunction.scope new file mode 100644 index 0000000000..73d215f7eb --- /dev/null +++ b/data/fixtures/scopes/go/namedFunction.scope @@ -0,0 +1,10 @@ +func foo() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| func foo() {} + +[Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/go/textFragment.comment.block.scope b/data/fixtures/scopes/go/textFragment.comment.block.scope new file mode 100644 index 0000000000..af33f95d00 --- /dev/null +++ b/data/fixtures/scopes/go/textFragment.comment.block.scope @@ -0,0 +1,10 @@ +/* Hello world */ +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:17 + >-----------------< +0| /* Hello world */ + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.iteration.document.scope b/data/fixtures/scopes/go/type/type.iteration.document.scope new file mode 100644 index 0000000000..f70d9ac2c1 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.iteration.document.scope @@ -0,0 +1,12 @@ + +var foo int + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| var foo int +2| + < diff --git a/data/fixtures/scopes/go/value/value.iteration.document.scope b/data/fixtures/scopes/go/value/value.iteration.document.scope new file mode 100644 index 0000000000..e51a745f22 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.iteration.document.scope @@ -0,0 +1,12 @@ + +foo := 1 + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| foo := 1 +2| + < diff --git a/packages/common/src/scopeSupportFacets/go.ts b/packages/common/src/scopeSupportFacets/go.ts index a1df12a6f4..3b3df4610c 100644 --- a/packages/common/src/scopeSupportFacets/go.ts +++ b/packages/common/src/scopeSupportFacets/go.ts @@ -11,7 +11,13 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { ifStatement: supported, + class: supported, + "class.iteration.block": supported, + "class.iteration.document": supported, + + "statement.class": supported, "statement.interface": supported, + "statement.field.class": supported, "statement.function": supported, "statement.method": supported, "statement.if": supported, @@ -24,11 +30,13 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "statement.break": supported, "statement.continue": supported, "statement.iteration.document": supported, + "statement.iteration.class": supported, "statement.iteration.interface": supported, "statement.iteration.block": supported, namedFunction: supported, "namedFunction.method": supported, + "namedFunction.iteration.class": supported, "namedFunction.iteration.document": supported, anonymousFunction: supported, @@ -103,12 +111,15 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "name.foreach": supported, "name.function": supported, "name.method": supported, + "name.class": supported, "name.interface": supported, + "name.field.class": supported, "name.argument.formal": supported, "name.argument.formal.iteration": supported, "name.argument.formal.method": supported, "name.argument.formal.method.iteration": supported, "name.iteration.block": supported, + "name.iteration.class": supported, "name.iteration.document": supported, "name.iteration.interface": supported, @@ -132,15 +143,19 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "type.argument.formal.method": supported, "type.argument.formal.method.iteration": supported, "type.return": supported, + "type.class": supported, "type.interface": supported, + "type.field.class": supported, "type.alias": supported, "type.cast": supported, "type.typeArgument": supported, "type.typeArgument.iteration": supported, "type.iteration.block": supported, + "type.iteration.class": supported, "type.iteration.document": supported, "type.iteration.interface": supported, + "interior.class": supported, "interior.interface": supported, "interior.function": supported, "interior.method": supported, @@ -182,21 +197,7 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "value.command": notApplicable, "interior.command": notApplicable, - // Class - class: notApplicable, - "class.iteration.document": notApplicable, - "class.iteration.block": notApplicable, - "statement.class": notApplicable, - "statement.field.class": notApplicable, - "statement.iteration.class": notApplicable, - "namedFunction.iteration.class": notApplicable, - "name.class": notApplicable, - "name.field.class": notApplicable, - "name.iteration.class": notApplicable, - "type.class": notApplicable, - "type.field.class": notApplicable, - "type.iteration.class": notApplicable, - "interior.class": notApplicable, + // Class field values "value.field.class": notApplicable, "value.iteration.class": notApplicable, diff --git a/queries/go.scm b/queries/go.scm index 1a57ed82a8..26913342d8 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -19,7 +19,6 @@ (for_statement) (go_statement) (goto_statement) - (if_statement) (inc_statement) (labeled_statement) (return_statement) @@ -29,8 +28,21 @@ (type_declaration) (type_switch_statement) (var_declaration) + + ;; Disabled on purpose. We have a better definition of this below. + ;; (if_statement) ] @statement +( + (source_file) @class.iteration @statement.iteration @namedFunction.iteration + (#document-range! @class.iteration @statement.iteration @namedFunction.iteration) +) + +( + (source_file) @name.iteration @value.iteration @type.iteration + (#document-range! @name.iteration @value.iteration @type.iteration) +) + ;;!! { } ;;! ^ (_ @@ -52,6 +64,13 @@ (comment) @comment @textFragment +;;!! type Foo struct {} +(type_declaration + (type_spec + type: (struct_type) + ) +) @class @type + ;; What should map and list refer to in Go programs? ;; ;; The obvious answer is that map should refer to map and struct composite literals, @@ -239,6 +258,12 @@ ;; if-else-based branch +;; The outermost if statement +( + (if_statement) @ifStatement @statement @branch.iteration + (#not-parent-type? @ifStatement if_statement) +) + ;; first if in an if-else chain ( (if_statement @@ -266,14 +291,6 @@ (#insertion-delimiter! @branch.start.startOf " ") ) -;; iteration scope is always the outermost if statement -( - (if_statement) @branch.iteration - (#not-parent-type? @branch.iteration if_statement) -) - -(if_statement) @ifStatement - [ (call_expression) (composite_literal) @@ -302,12 +319,12 @@ [ (pointer_type) (qualified_type) - (type_identifier) ] @type (function_declaration result: (_) @type ) @_.domain + (method_declaration result: (_) @type ) @_.domain @@ -318,6 +335,7 @@ condition: (_) @condition ) @_.domain (#not-type? @condition parenthesized_expression) + (#not-type? @_.domain for_clause) ) ;;!! if (true) {} @@ -328,6 +346,13 @@ (#child-range! @condition 0 -1 true true) ) +;;!! for i := 0; i < size; i++ {} +(for_statement + (for_clause + condition: (_) @condition + ) +) @condition.domain + ;;!! func add(x int, y int) int {} ( (parameter_list From 3d24f494c82e4c6569f30c74287990c5acdff756 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 13:47:50 +0100 Subject: [PATCH 03/17] variables --- .../scopes/go/key.mapPair.iteration.scope | 7 +++ data/fixtures/scopes/go/key.mapPair.scope | 32 ++++++++++ data/fixtures/scopes/go/list.scope | 10 +++ data/fixtures/scopes/go/map.scope | 10 +++ .../scopes/go/name/name.assignment.scope | 20 ++++++ .../scopes/go/name/name.variable.scope | 24 +++++++ .../scopes/go/name/name.variable2.scope | 24 +++++++ .../scopes/go/name/name.variable3.scope | 20 ++++++ .../scopes/go/type/type.variable.scope | 20 ++++++ .../scopes/go/type/type.variable2.scope | 24 +++++++ .../scopes/go/value/value.assignment.scope | 20 ++++++ .../go/value/value.mapPair.iteration.scope | 13 ++++ .../scopes/go/value/value.mapPair.scope | 39 ++++++++++++ .../scopes/go/value/value.variable.scope | 20 ++++++ .../scopes/go/value/value.variable2.scope | 20 ++++++ .../scopes/go/value/value.variable3.scope | 20 ++++++ queries/go.scm | 62 ++++++++++++++++--- 17 files changed, 378 insertions(+), 7 deletions(-) create mode 100644 data/fixtures/scopes/go/key.mapPair.iteration.scope create mode 100644 data/fixtures/scopes/go/key.mapPair.scope create mode 100644 data/fixtures/scopes/go/list.scope create mode 100644 data/fixtures/scopes/go/map.scope create mode 100644 data/fixtures/scopes/go/name/name.assignment.scope create mode 100644 data/fixtures/scopes/go/name/name.variable.scope create mode 100644 data/fixtures/scopes/go/name/name.variable2.scope create mode 100644 data/fixtures/scopes/go/name/name.variable3.scope create mode 100644 data/fixtures/scopes/go/type/type.variable.scope create mode 100644 data/fixtures/scopes/go/type/type.variable2.scope create mode 100644 data/fixtures/scopes/go/value/value.assignment.scope create mode 100644 data/fixtures/scopes/go/value/value.mapPair.iteration.scope create mode 100644 data/fixtures/scopes/go/value/value.mapPair.scope create mode 100644 data/fixtures/scopes/go/value/value.variable.scope create mode 100644 data/fixtures/scopes/go/value/value.variable2.scope create mode 100644 data/fixtures/scopes/go/value/value.variable3.scope diff --git a/data/fixtures/scopes/go/key.mapPair.iteration.scope b/data/fixtures/scopes/go/key.mapPair.iteration.scope new file mode 100644 index 0000000000..82c069999d --- /dev/null +++ b/data/fixtures/scopes/go/key.mapPair.iteration.scope @@ -0,0 +1,7 @@ +map[string]int{"aaa": 1, "bbb": 2} +--- + +[Content] = +[Domain] = 0:15-0:33 + >------------------< +0| map[string]int{"aaa": 1, "bbb": 2} diff --git a/data/fixtures/scopes/go/key.mapPair.scope b/data/fixtures/scopes/go/key.mapPair.scope new file mode 100644 index 0000000000..c94b925827 --- /dev/null +++ b/data/fixtures/scopes/go/key.mapPair.scope @@ -0,0 +1,32 @@ +map[string]int{"aaa": 1, "bbb": 2} +--- + +[#1 Content] = +[#1 Removal] = 0:15-0:20 + >-----< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Domain] = 0:15-0:23 + >--------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:25-0:30 + >-----< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Removal] = 0:24-0:30 + >------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Leading delimiter] = 0:24-0:25 + >-< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Domain] = 0:25-0:33 + >--------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/list.scope b/data/fixtures/scopes/go/list.scope new file mode 100644 index 0000000000..3106e513ff --- /dev/null +++ b/data/fixtures/scopes/go/list.scope @@ -0,0 +1,10 @@ +[]int{aaa, bbb} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:15 + >---------------< +0| []int{aaa, bbb} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/map.scope b/data/fixtures/scopes/go/map.scope new file mode 100644 index 0000000000..488d5fbb5b --- /dev/null +++ b/data/fixtures/scopes/go/map.scope @@ -0,0 +1,10 @@ +map[string]int{"aaa": 1, "bbb": 2} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:34 + >----------------------------------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.assignment.scope b/data/fixtures/scopes/go/name/name.assignment.scope new file mode 100644 index 0000000000..829dd52b1c --- /dev/null +++ b/data/fixtures/scopes/go/name/name.assignment.scope @@ -0,0 +1,20 @@ +foo = 1 +--- + +[Content] = 0:0-0:3 + >---< +0| foo = 1 + +[Removal] = 0:0-0:4 + >----< +0| foo = 1 + +[Trailing delimiter] = 0:3-0:4 + >-< +0| foo = 1 + +[Domain] = 0:0-0:7 + >-------< +0| foo = 1 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.variable.scope b/data/fixtures/scopes/go/name/name.variable.scope new file mode 100644 index 0000000000..78abad522f --- /dev/null +++ b/data/fixtures/scopes/go/name/name.variable.scope @@ -0,0 +1,24 @@ +var foo int +--- + +[Content] = 0:4-0:7 + >---< +0| var foo int + +[Removal] = 0:4-0:8 + >----< +0| var foo int + +[Leading delimiter] = 0:3-0:4 + >-< +0| var foo int + +[Trailing delimiter] = 0:7-0:8 + >-< +0| var foo int + +[Domain] = 0:0-0:11 + >-----------< +0| var foo int + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.variable2.scope b/data/fixtures/scopes/go/name/name.variable2.scope new file mode 100644 index 0000000000..11adc00523 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.variable2.scope @@ -0,0 +1,24 @@ +var foo int = 0 +--- + +[Content] = 0:4-0:7 + >---< +0| var foo int = 0 + +[Removal] = 0:4-0:8 + >----< +0| var foo int = 0 + +[Leading delimiter] = 0:3-0:4 + >-< +0| var foo int = 0 + +[Trailing delimiter] = 0:7-0:8 + >-< +0| var foo int = 0 + +[Domain] = 0:0-0:15 + >---------------< +0| var foo int = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.variable3.scope b/data/fixtures/scopes/go/name/name.variable3.scope new file mode 100644 index 0000000000..cda5dd235d --- /dev/null +++ b/data/fixtures/scopes/go/name/name.variable3.scope @@ -0,0 +1,20 @@ +foo := 0 +--- + +[Content] = 0:0-0:3 + >---< +0| foo := 0 + +[Removal] = 0:0-0:4 + >----< +0| foo := 0 + +[Trailing delimiter] = 0:3-0:4 + >-< +0| foo := 0 + +[Domain] = 0:0-0:8 + >--------< +0| foo := 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.variable.scope b/data/fixtures/scopes/go/type/type.variable.scope new file mode 100644 index 0000000000..44a666889c --- /dev/null +++ b/data/fixtures/scopes/go/type/type.variable.scope @@ -0,0 +1,20 @@ +var foo int +--- + +[Content] = 0:8-0:11 + >---< +0| var foo int + +[Removal] = 0:7-0:11 + >----< +0| var foo int + +[Leading delimiter] = 0:7-0:8 + >-< +0| var foo int + +[Domain] = 0:0-0:11 + >-----------< +0| var foo int + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.variable2.scope b/data/fixtures/scopes/go/type/type.variable2.scope new file mode 100644 index 0000000000..7913b77ea5 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.variable2.scope @@ -0,0 +1,24 @@ +var foo int = 0 +--- + +[Content] = 0:8-0:11 + >---< +0| var foo int = 0 + +[Removal] = 0:8-0:12 + >----< +0| var foo int = 0 + +[Leading delimiter] = 0:7-0:8 + >-< +0| var foo int = 0 + +[Trailing delimiter] = 0:11-0:12 + >-< +0| var foo int = 0 + +[Domain] = 0:0-0:15 + >---------------< +0| var foo int = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.assignment.scope b/data/fixtures/scopes/go/value/value.assignment.scope new file mode 100644 index 0000000000..6e89de0927 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.assignment.scope @@ -0,0 +1,20 @@ +foo = 0 +--- + +[Content] = 0:6-0:7 + >-< +0| foo = 0 + +[Removal] = 0:3-0:7 + >----< +0| foo = 0 + +[Leading delimiter] = 0:3-0:6 + >---< +0| foo = 0 + +[Domain] = 0:0-0:7 + >-------< +0| foo = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.mapPair.iteration.scope b/data/fixtures/scopes/go/value/value.mapPair.iteration.scope new file mode 100644 index 0000000000..75828c2c40 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.mapPair.iteration.scope @@ -0,0 +1,13 @@ +map[string]int{"aaa": 1, "bbb": 2} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:34 + >----------------------------------< +0| map[string]int{"aaa": 1, "bbb": 2} + + +[#2 Content] = +[#2 Domain] = 0:15-0:33 + >------------------< +0| map[string]int{"aaa": 1, "bbb": 2} diff --git a/data/fixtures/scopes/go/value/value.mapPair.scope b/data/fixtures/scopes/go/value/value.mapPair.scope new file mode 100644 index 0000000000..70069978be --- /dev/null +++ b/data/fixtures/scopes/go/value/value.mapPair.scope @@ -0,0 +1,39 @@ +map[string]int{"aaa": 1, "bbb": 2} +--- + +[#1 Content] = 0:22-0:23 + >-< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Removal] = 0:21-0:23 + >--< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Leading delimiter] = 0:21-0:22 + >-< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Domain] = 0:15-0:23 + >--------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:32-0:33 + >-< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Removal] = 0:31-0:33 + >--< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Leading delimiter] = 0:31-0:32 + >-< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Domain] = 0:25-0:33 + >--------< +0| map[string]int{"aaa": 1, "bbb": 2} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.variable.scope b/data/fixtures/scopes/go/value/value.variable.scope new file mode 100644 index 0000000000..fb52bff040 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.variable.scope @@ -0,0 +1,20 @@ +var foo int = 0 +--- + +[Content] = 0:14-0:15 + >-< +0| var foo int = 0 + +[Removal] = 0:11-0:15 + >----< +0| var foo int = 0 + +[Leading delimiter] = 0:11-0:14 + >---< +0| var foo int = 0 + +[Domain] = 0:0-0:15 + >---------------< +0| var foo int = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.variable2.scope b/data/fixtures/scopes/go/value/value.variable2.scope new file mode 100644 index 0000000000..1fa20fec11 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.variable2.scope @@ -0,0 +1,20 @@ +var foo = 0 +--- + +[Content] = 0:14-0:15 + >-< +0| var foo int = 0 + +[Removal] = 0:11-0:15 + >----< +0| var foo int = 0 + +[Leading delimiter] = 0:11-0:14 + >---< +0| var foo int = 0 + +[Domain] = 0:0-0:15 + >---------------< +0| var foo int = 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.variable3.scope b/data/fixtures/scopes/go/value/value.variable3.scope new file mode 100644 index 0000000000..048f1900d1 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.variable3.scope @@ -0,0 +1,20 @@ +foo := 0 +--- + +[Content] = 0:7-0:8 + >-< +0| foo := 0 + +[Removal] = 0:3-0:8 + >-----< +0| foo := 0 + +[Leading delimiter] = 0:3-0:7 + >----< +0| foo := 0 + +[Domain] = 0:0-0:8 + >--------< +0| foo := 0 + +[Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 26913342d8..91a5f88712 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -5,8 +5,6 @@ ;; and then cleaned up. [ (assignment_statement) - ;; omit block for now, as it is not clear that it matches Cursorless user expectations - ;; (block) (break_statement) (const_declaration) (continue_statement) @@ -31,6 +29,8 @@ ;; Disabled on purpose. We have a better definition of this below. ;; (if_statement) + ;; omit block for now, as it is not clear that it matches Cursorless user expectations + ;; (block) ] @statement ( @@ -299,10 +299,18 @@ (call_expression function: (_) @functionCallee ) @_.domain + (composite_literal type: (_) @functionCallee ) @_.domain +(return_statement + (expression_list) @value +) @_.domain + +;;!! map[string]int{"aaa": 1, "bbb": 2} +;;! ^^^^^ ^^^^^ +;;! ^ ^ (keyed_element . (_) @collectionKey @@ -310,11 +318,12 @@ (_) @value ) @_.domain -(return_statement - (expression_list) @value -) @_.domain - -(literal_value) @collectionKey.iteration @value.iteration +;;!! map[string]int{"aaa": 1, "bbb": 2} +;;! ^^^^^^^^^^^^^^^^^^ +(literal_value + "{" @collectionKey.iteration.start.endOf @value.iteration.start.endOf + "}" @collectionKey.iteration.end.startOf @value.iteration.end.startOf +) [ (pointer_type) @@ -393,6 +402,45 @@ ) ) @argumentOrParameter.iteration.domain +;;!! var foo int = 0 +;;! ^^^ +;;! ^^^ +;;! ^ +(var_declaration + (var_spec + name: (_) @name + type: (_) @type @value.leading.endOf + value: (_)? @value + ) +) @_.domain + +;;!! var foo = 0 +;;! ^^^ +;;! ^ +(var_declaration + (var_spec + name: (_) @name @value.leading.endOf + !type + value: (_) @value + ) +) @_.domain + +;;!! foo := 0 +;;! ^^^ +;;! ^ +(short_var_declaration + left: (_) @name @value.leading.endOf + right: (_) @value +) @_.domain + +;;!! foo = 0 +;;! ^^^ +;;! ^ +(assignment_statement + left: (_) @name @value.leading.endOf + right: (_) @value +) @_.domain + operator: [ "<-" "<" From f43d081522fead21b40cff89538c486ef15e6c99 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 14:20:54 +0100 Subject: [PATCH 04/17] More tests --- .../scopes/go/interior/interior.class.scope | 10 +++++ .../scopes/go/interior/interior.for.scope | 10 +++++ .../scopes/go/interior/interior.foreach.scope | 10 +++++ .../go/interior/interior.function.scope | 10 +++++ .../scopes/go/interior/interior.if.scope | 37 +++++++++++++++ .../go/interior/interior.interface.scope | 10 +++++ .../scopes/go/interior/interior.lambda.scope | 10 +++++ .../scopes/go/interior/interior.method.scope | 10 +++++ data/fixtures/scopes/go/name/name.class.scope | 24 ++++++++++ .../scopes/go/name/name.foreach.scope | 24 ++++++++++ .../scopes/go/name/name.function.scope | 17 +++++++ .../scopes/go/name/name.interface.scope | 24 ++++++++++ .../fixtures/scopes/go/name/name.method.scope | 17 +++++++ .../go/statement/statement.assignment.scope | 10 +++++ .../scopes/go/statement/statement.class.scope | 10 +++++ .../scopes/go/statement/statement.for.scope | 10 +++++ .../go/statement/statement.foreach.scope | 10 +++++ .../go/statement/statement.function.scope | 10 +++++ .../scopes/go/statement/statement.if.scope | 17 +++++++ .../go/statement/statement.interface.scope | 10 +++++ .../statement.iteration.document.scope | 12 +++++ .../go/statement/statement.method.scope | 10 +++++ .../go/statement/statement.variable.scope | 10 +++++ .../go/statement/statement.variable2.scope | 10 +++++ .../go/statement/statement.variable3.scope | 10 +++++ data/fixtures/scopes/go/type/type.class.scope | 10 +++++ .../scopes/go/type/type.interface.scope | 10 +++++ .../fixtures/scopes/go/type/type.return.scope | 24 ++++++++++ .../scopes/go/value/value.foreach.scope | 24 ++++++++++ .../scopes/go/value/value.return.scope | 22 +++++++++ .../scopes/go/value/value.variable2.scope | 24 +++++----- queries/go.scm | 45 +++++++++++++++---- 32 files changed, 480 insertions(+), 21 deletions(-) create mode 100644 data/fixtures/scopes/go/interior/interior.class.scope create mode 100644 data/fixtures/scopes/go/interior/interior.for.scope create mode 100644 data/fixtures/scopes/go/interior/interior.foreach.scope create mode 100644 data/fixtures/scopes/go/interior/interior.function.scope create mode 100644 data/fixtures/scopes/go/interior/interior.if.scope create mode 100644 data/fixtures/scopes/go/interior/interior.interface.scope create mode 100644 data/fixtures/scopes/go/interior/interior.lambda.scope create mode 100644 data/fixtures/scopes/go/interior/interior.method.scope create mode 100644 data/fixtures/scopes/go/name/name.class.scope create mode 100644 data/fixtures/scopes/go/name/name.foreach.scope create mode 100644 data/fixtures/scopes/go/name/name.function.scope create mode 100644 data/fixtures/scopes/go/name/name.interface.scope create mode 100644 data/fixtures/scopes/go/name/name.method.scope create mode 100644 data/fixtures/scopes/go/statement/statement.assignment.scope create mode 100644 data/fixtures/scopes/go/statement/statement.class.scope create mode 100644 data/fixtures/scopes/go/statement/statement.for.scope create mode 100644 data/fixtures/scopes/go/statement/statement.foreach.scope create mode 100644 data/fixtures/scopes/go/statement/statement.function.scope create mode 100644 data/fixtures/scopes/go/statement/statement.if.scope create mode 100644 data/fixtures/scopes/go/statement/statement.interface.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.document.scope create mode 100644 data/fixtures/scopes/go/statement/statement.method.scope create mode 100644 data/fixtures/scopes/go/statement/statement.variable.scope create mode 100644 data/fixtures/scopes/go/statement/statement.variable2.scope create mode 100644 data/fixtures/scopes/go/statement/statement.variable3.scope create mode 100644 data/fixtures/scopes/go/type/type.class.scope create mode 100644 data/fixtures/scopes/go/type/type.interface.scope create mode 100644 data/fixtures/scopes/go/type/type.return.scope create mode 100644 data/fixtures/scopes/go/value/value.foreach.scope create mode 100644 data/fixtures/scopes/go/value/value.return.scope diff --git a/data/fixtures/scopes/go/interior/interior.class.scope b/data/fixtures/scopes/go/interior/interior.class.scope new file mode 100644 index 0000000000..41759cfbc9 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.class.scope @@ -0,0 +1,10 @@ +type Foo struct { } +--- + +[Content] = +[Removal] = +[Domain] = 0:17-0:18 + >-< +0| type Foo struct { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.for.scope b/data/fixtures/scopes/go/interior/interior.for.scope new file mode 100644 index 0000000000..0532404a58 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.for.scope @@ -0,0 +1,10 @@ +for i := 0; i < size; i++ { } +--- + +[Content] = +[Removal] = +[Domain] = 0:27-0:28 + >-< +0| for i := 0; i < size; i++ { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.foreach.scope b/data/fixtures/scopes/go/interior/interior.foreach.scope new file mode 100644 index 0000000000..9e3ecabac0 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.foreach.scope @@ -0,0 +1,10 @@ +for _, v := range values { } +--- + +[Content] = +[Removal] = +[Domain] = 0:26-0:27 + >-< +0| for _, v := range values { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.function.scope b/data/fixtures/scopes/go/interior/interior.function.scope new file mode 100644 index 0000000000..7c395916ef --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.function.scope @@ -0,0 +1,10 @@ +func foo() { } +--- + +[Content] = +[Removal] = +[Domain] = 0:12-0:13 + >-< +0| func foo() { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.if.scope b/data/fixtures/scopes/go/interior/interior.if.scope new file mode 100644 index 0000000000..97a15114cc --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.if.scope @@ -0,0 +1,37 @@ +if true { +} else if false { +} else { +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:9-1:0 + > +0| if true { +1| } else if false { + < + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 1:17-2:0 + > +1| } else if false { +2| } else { + < + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 2:8-3:0 + > +2| } else { +3| } + < + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.interface.scope b/data/fixtures/scopes/go/interior/interior.interface.scope new file mode 100644 index 0000000000..2520c3d660 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.interface.scope @@ -0,0 +1,10 @@ +type Foo interface { } +--- + +[Content] = +[Removal] = +[Domain] = 0:20-0:21 + >-< +0| type Foo interface { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.lambda.scope b/data/fixtures/scopes/go/interior/interior.lambda.scope new file mode 100644 index 0000000000..f5bdd78a11 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.lambda.scope @@ -0,0 +1,10 @@ +foo := func() { } +--- + +[Content] = +[Removal] = +[Domain] = 0:15-0:16 + >-< +0| foo := func() { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.method.scope b/data/fixtures/scopes/go/interior/interior.method.scope new file mode 100644 index 0000000000..08626611e1 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.method.scope @@ -0,0 +1,10 @@ +func (f Foo) bar() { } +--- + +[Content] = +[Removal] = +[Domain] = 0:20-0:21 + >-< +0| func (f Foo) bar() { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.class.scope b/data/fixtures/scopes/go/name/name.class.scope new file mode 100644 index 0000000000..1e7219ffe4 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.class.scope @@ -0,0 +1,24 @@ +type Foo struct {} +--- + +[Content] = 0:5-0:8 + >---< +0| type Foo struct {} + +[Removal] = 0:5-0:9 + >----< +0| type Foo struct {} + +[Leading delimiter] = 0:4-0:5 + >-< +0| type Foo struct {} + +[Trailing delimiter] = 0:8-0:9 + >-< +0| type Foo struct {} + +[Domain] = 0:0-0:18 + >------------------< +0| type Foo struct {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.foreach.scope b/data/fixtures/scopes/go/name/name.foreach.scope new file mode 100644 index 0000000000..9fa9ed0460 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.foreach.scope @@ -0,0 +1,24 @@ +for i, v := range values {} +--- + +[Content] = 0:4-0:8 + >----< +0| for i, v := range values {} + +[Removal] = 0:4-0:9 + >-----< +0| for i, v := range values {} + +[Leading delimiter] = 0:3-0:4 + >-< +0| for i, v := range values {} + +[Trailing delimiter] = 0:8-0:9 + >-< +0| for i, v := range values {} + +[Domain] = 0:0-0:27 + >---------------------------< +0| for i, v := range values {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.function.scope b/data/fixtures/scopes/go/name/name.function.scope new file mode 100644 index 0000000000..d9a1dd759b --- /dev/null +++ b/data/fixtures/scopes/go/name/name.function.scope @@ -0,0 +1,17 @@ +func foo() {} +--- + +[Content] = +[Removal] = 0:5-0:8 + >---< +0| func foo() {} + +[Leading delimiter] = 0:4-0:5 + >-< +0| func foo() {} + +[Domain] = 0:0-0:13 + >-------------< +0| func foo() {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.interface.scope b/data/fixtures/scopes/go/name/name.interface.scope new file mode 100644 index 0000000000..68a624009b --- /dev/null +++ b/data/fixtures/scopes/go/name/name.interface.scope @@ -0,0 +1,24 @@ +type Foo interface {} +--- + +[Content] = 0:5-0:8 + >---< +0| type Foo interface {} + +[Removal] = 0:5-0:9 + >----< +0| type Foo interface {} + +[Leading delimiter] = 0:4-0:5 + >-< +0| type Foo interface {} + +[Trailing delimiter] = 0:8-0:9 + >-< +0| type Foo interface {} + +[Domain] = 0:0-0:21 + >---------------------< +0| type Foo interface {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.method.scope b/data/fixtures/scopes/go/name/name.method.scope new file mode 100644 index 0000000000..647cb8304f --- /dev/null +++ b/data/fixtures/scopes/go/name/name.method.scope @@ -0,0 +1,17 @@ +func (f Foo) bar() {} +--- + +[Content] = +[Removal] = 0:13-0:16 + >---< +0| func (f Foo) bar() {} + +[Leading delimiter] = 0:12-0:13 + >-< +0| func (f Foo) bar() {} + +[Domain] = 0:0-0:21 + >---------------------< +0| func (f Foo) bar() {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/statement/statement.assignment.scope b/data/fixtures/scopes/go/statement/statement.assignment.scope new file mode 100644 index 0000000000..acdb2b1498 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.assignment.scope @@ -0,0 +1,10 @@ +foo = 0 +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:7 + >-------< +0| foo = 0 + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.class.scope b/data/fixtures/scopes/go/statement/statement.class.scope new file mode 100644 index 0000000000..1523b81a2d --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.class.scope @@ -0,0 +1,10 @@ +type Foo struct {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:18 + >------------------< +0| type Foo struct {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.for.scope b/data/fixtures/scopes/go/statement/statement.for.scope new file mode 100644 index 0000000000..32136c937a --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.for.scope @@ -0,0 +1,10 @@ +for i := 0; i < size; i++ {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:28 + >----------------------------< +0| for i := 0; i < size; i++ {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.foreach.scope b/data/fixtures/scopes/go/statement/statement.foreach.scope new file mode 100644 index 0000000000..00f8d55fd2 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.foreach.scope @@ -0,0 +1,10 @@ +for _, v := range values {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:27 + >---------------------------< +0| for _, v := range values {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.function.scope b/data/fixtures/scopes/go/statement/statement.function.scope new file mode 100644 index 0000000000..118724d315 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.function.scope @@ -0,0 +1,10 @@ +func foo() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| func foo() {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.if.scope b/data/fixtures/scopes/go/statement/statement.if.scope new file mode 100644 index 0000000000..8f864e71e7 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.if.scope @@ -0,0 +1,17 @@ +if true { +} else if false { +} else { +} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-3:1 + >--------- +0| if true { +1| } else if false { +2| } else { +3| } + -< + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.interface.scope b/data/fixtures/scopes/go/statement/statement.interface.scope new file mode 100644 index 0000000000..0f4fc4f519 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.interface.scope @@ -0,0 +1,10 @@ +type Foo interface {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| type Foo interface {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.iteration.document.scope b/data/fixtures/scopes/go/statement/statement.iteration.document.scope new file mode 100644 index 0000000000..f70d9ac2c1 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.document.scope @@ -0,0 +1,12 @@ + +var foo int + +--- + +[Content] = +[Domain] = 0:0-2:0 + > +0| +1| var foo int +2| + < diff --git a/data/fixtures/scopes/go/statement/statement.method.scope b/data/fixtures/scopes/go/statement/statement.method.scope new file mode 100644 index 0000000000..535aba2bc3 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.method.scope @@ -0,0 +1,10 @@ +func (f Foo) bar() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| func (f Foo) bar() {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.variable.scope b/data/fixtures/scopes/go/statement/statement.variable.scope new file mode 100644 index 0000000000..d557d3cb76 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.variable.scope @@ -0,0 +1,10 @@ +var foo int +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:11 + >-----------< +0| var foo int + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.variable2.scope b/data/fixtures/scopes/go/statement/statement.variable2.scope new file mode 100644 index 0000000000..1bf83fb616 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.variable2.scope @@ -0,0 +1,10 @@ +var foo int = 0 +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:15 + >---------------< +0| var foo int = 0 + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.variable3.scope b/data/fixtures/scopes/go/statement/statement.variable3.scope new file mode 100644 index 0000000000..b3f49c96dd --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.variable3.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/go/type/type.class.scope b/data/fixtures/scopes/go/type/type.class.scope new file mode 100644 index 0000000000..9b7da6b68b --- /dev/null +++ b/data/fixtures/scopes/go/type/type.class.scope @@ -0,0 +1,10 @@ +type Foo struct {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:18 + >------------------< +0| type Foo struct {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.interface.scope b/data/fixtures/scopes/go/type/type.interface.scope new file mode 100644 index 0000000000..095a526dd9 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.interface.scope @@ -0,0 +1,10 @@ +type Foo interface {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| type Foo interface {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.return.scope b/data/fixtures/scopes/go/type/type.return.scope new file mode 100644 index 0000000000..beacc79b8d --- /dev/null +++ b/data/fixtures/scopes/go/type/type.return.scope @@ -0,0 +1,24 @@ +func foo() int {} +--- + +[Content] = 0:11-0:14 + >---< +0| func foo() int {} + +[Removal] = 0:11-0:15 + >----< +0| func foo() int {} + +[Leading delimiter] = 0:10-0:11 + >-< +0| func foo() int {} + +[Trailing delimiter] = 0:14-0:15 + >-< +0| func foo() int {} + +[Domain] = 0:0-0:17 + >-----------------< +0| func foo() int {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.foreach.scope b/data/fixtures/scopes/go/value/value.foreach.scope new file mode 100644 index 0000000000..bba422d7d5 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.foreach.scope @@ -0,0 +1,24 @@ +for i, v := range values {} +--- + +[Content] = 0:18-0:24 + >------< +0| for i, v := range values {} + +[Removal] = 0:18-0:25 + >-------< +0| for i, v := range values {} + +[Leading delimiter] = 0:17-0:18 + >-< +0| for i, v := range values {} + +[Trailing delimiter] = 0:24-0:25 + >-< +0| for i, v := range values {} + +[Domain] = 0:0-0:27 + >---------------------------< +0| for i, v := range values {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.return.scope b/data/fixtures/scopes/go/value/value.return.scope new file mode 100644 index 0000000000..701e78f3df --- /dev/null +++ b/data/fixtures/scopes/go/value/value.return.scope @@ -0,0 +1,22 @@ +func foo() int { + return 0 +} +--- + +[Content] = 1:11-1:12 + >-< +1| return 0 + +[Removal] = 1:10-1:12 + >--< +1| return 0 + +[Leading delimiter] = 1:10-1:11 + >-< +1| return 0 + +[Domain] = 1:4-1:12 + >--------< +1| return 0 + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.variable2.scope b/data/fixtures/scopes/go/value/value.variable2.scope index 1fa20fec11..06dc0be9f8 100644 --- a/data/fixtures/scopes/go/value/value.variable2.scope +++ b/data/fixtures/scopes/go/value/value.variable2.scope @@ -1,20 +1,20 @@ var foo = 0 --- -[Content] = 0:14-0:15 - >-< -0| var foo int = 0 +[Content] = 0:10-0:11 + >-< +0| var foo = 0 -[Removal] = 0:11-0:15 - >----< -0| var foo int = 0 +[Removal] = 0:7-0:11 + >----< +0| var foo = 0 -[Leading delimiter] = 0:11-0:14 - >---< -0| var foo int = 0 +[Leading delimiter] = 0:7-0:10 + >---< +0| var foo = 0 -[Domain] = 0:0-0:15 - >---------------< -0| var foo int = 0 +[Domain] = 0:0-0:11 + >-----------< +0| var foo = 0 [Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 91a5f88712..82eb3723bf 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -4,11 +4,9 @@ ;; curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-go/master/src/node-types.json | jq '[.[] | select(.type == "_statement" or .type == "_simple_statement") | .subtypes[].type]' | grep -v '\"_' | sed -n '1d;p' | sed '$d' | sort ;; and then cleaned up. [ - (assignment_statement) (break_statement) (const_declaration) (continue_statement) - (dec_statement) (defer_statement) (empty_statement) (expression_statement) @@ -17,15 +15,12 @@ (for_statement) (go_statement) (goto_statement) - (inc_statement) (labeled_statement) (return_statement) (select_statement) (send_statement) - (short_var_declaration) (type_declaration) (type_switch_statement) - (var_declaration) ;; Disabled on purpose. We have a better definition of this below. ;; (if_statement) @@ -33,6 +28,18 @@ ;; (block) ] @statement +;; Exclude statements that are part of for clauses +( + [ + (assignment_statement) + (short_var_declaration) + (var_declaration) + (inc_statement) + (dec_statement) + ] @statement + (#not-parent-type? @statement for_clause) +) + ( (source_file) @class.iteration @statement.iteration @namedFunction.iteration (#document-range! @class.iteration @statement.iteration @namedFunction.iteration) @@ -67,9 +74,18 @@ ;;!! type Foo struct {} (type_declaration (type_spec + name: (_) @name type: (struct_type) ) -) @class @type +) @class @type @name.domain + +;;!! type Foo interface {} +(type_declaration + (type_spec + name: (_) @name + type: (interface_type) + ) +) @type @name.domain ;; What should map and list refer to in Go programs? ;; @@ -228,16 +244,16 @@ ;; func foo() (function_declaration name: (_) @name -) @namedFunction @name.domain +) @namedFunction @statement @name.domain ;; method declaration ;; func (X) foo() {} (method_declaration name: (_) @name -) @namedFunction @name.domain +) @namedFunction @statement @name.domain ;; func literal -(func_literal) @anonymousFunction @namedFunction +(func_literal) @anonymousFunction ;; switch-based branch @@ -356,12 +372,23 @@ ) ;;!! for i := 0; i < size; i++ {} +;;! ^^^^^^^^ (for_statement (for_clause condition: (_) @condition ) ) @condition.domain +;;!! for i, v := range values {} +;;! ^^^^ +;;! ^^^^^^ +(for_statement + (range_clause + left: (_) @name + right: (_) @value + ) +) @_.domain + ;;!! func add(x int, y int) int {} ( (parameter_list From 9a322fc520b2c4be1fa4b0738867cee2a67c7e1e Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 14:47:37 +0100 Subject: [PATCH 05/17] More work --- .../go/branch/branch.if.elif.else.scope | 68 +++++++++++++++++++ .../scopes/go/branch/branch.if.else.scope | 43 ++++++++++++ .../go/branch/branch.if.iteration.scope | 14 ++++ .../fixtures/scopes/go/branch/branch.if.scope | 13 ++++ .../scopes/go/name/name.field.class.scope | 52 ++++++++++++++ .../scopes/go/name/name.field.interface.scope | 45 ++++++++++++ .../scopes/go/name/name.iteration.class.scope | 13 ++++ .../go/name/name.iteration.interface.scope | 13 ++++ .../scopes/go/statement/statement.break.scope | 33 +++++++++ .../go/statement/statement.continue.scope | 33 +++++++++ .../go/statement/statement.field.class.scope | 33 +++++++++ .../statement/statement.field.interface.scope | 33 +++++++++ .../statement/statement.iteration.class.scope | 13 ++++ .../statement.iteration.interface.scope | 13 ++++ .../go/statement/statement.return.scope | 33 +++++++++ .../scopes/go/type/type.field.class.scope | 34 ++++++++++ .../scopes/go/type/type.iteration.class.scope | 13 ++++ packages/common/src/scopeSupportFacets/go.ts | 12 ++-- queries/go.scm | 24 ++++++- 19 files changed, 527 insertions(+), 8 deletions(-) create mode 100644 data/fixtures/scopes/go/branch/branch.if.elif.else.scope create mode 100644 data/fixtures/scopes/go/branch/branch.if.else.scope create mode 100644 data/fixtures/scopes/go/branch/branch.if.iteration.scope create mode 100644 data/fixtures/scopes/go/branch/branch.if.scope create mode 100644 data/fixtures/scopes/go/name/name.field.class.scope create mode 100644 data/fixtures/scopes/go/name/name.field.interface.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.class.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.interface.scope create mode 100644 data/fixtures/scopes/go/statement/statement.break.scope create mode 100644 data/fixtures/scopes/go/statement/statement.continue.scope create mode 100644 data/fixtures/scopes/go/statement/statement.field.class.scope create mode 100644 data/fixtures/scopes/go/statement/statement.field.interface.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.class.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.interface.scope create mode 100644 data/fixtures/scopes/go/statement/statement.return.scope create mode 100644 data/fixtures/scopes/go/type/type.field.class.scope create mode 100644 data/fixtures/scopes/go/type/type.iteration.class.scope diff --git a/data/fixtures/scopes/go/branch/branch.if.elif.else.scope b/data/fixtures/scopes/go/branch/branch.if.elif.else.scope new file mode 100644 index 0000000000..1f5f5582b6 --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.if.elif.else.scope @@ -0,0 +1,68 @@ +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:2 + >--------- +0| if true { +1| } else if false { + --< + +[#1 Trailing delimiter] = 1:1-1:2 + >-< +1| } else if false { + +[#1 Insertion delimiter] = " " + + +[#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] = " " + + +[#3 Content] = +[#3 Domain] = 2:2-3:1 + >------ +2| } else { +3| } + -< + +[#3 Removal] = 2:1-3:1 + >------- +2| } else { +3| } + -< + +[#3 Leading delimiter] = 2:1-2:2 + >-< +2| } else { + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/branch/branch.if.else.scope b/data/fixtures/scopes/go/branch/branch.if.else.scope new file mode 100644 index 0000000000..eb3cfcfe18 --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.if.else.scope @@ -0,0 +1,43 @@ +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] = " " + + +[#2 Content] = +[#2 Domain] = 1:2-2:1 + >------ +1| } else { +2| } + -< + +[#2 Removal] = 1:1-2:1 + >------- +1| } else { +2| } + -< + +[#2 Leading delimiter] = 1:1-1:2 + >-< +1| } else { + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/branch/branch.if.iteration.scope b/data/fixtures/scopes/go/branch/branch.if.iteration.scope new file mode 100644 index 0000000000..701bb81573 --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.if.iteration.scope @@ -0,0 +1,14 @@ +if true { +} else if false { +} else { +} +--- + +[Content] = +[Domain] = 0:0-3:1 + >--------- +0| if true { +1| } else if false { +2| } else { +3| } + -< diff --git a/data/fixtures/scopes/go/branch/branch.if.scope b/data/fixtures/scopes/go/branch/branch.if.scope new file mode 100644 index 0000000000..48d491ae4f --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.if.scope @@ -0,0 +1,13 @@ +if true { +} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-1:1 + >--------- +0| if true { +1| } + -< + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.field.class.scope b/data/fixtures/scopes/go/name/name.field.class.scope new file mode 100644 index 0000000000..64ad3cdcd6 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.field.class.scope @@ -0,0 +1,52 @@ +type Foo struct { + bar int +} +--- + +[#1 Content] = 0:5-0:8 + >---< +0| type Foo struct { + +[#1 Removal] = 0:5-0:9 + >----< +0| type Foo struct { + +[#1 Leading delimiter] = 0:4-0:5 + >-< +0| type Foo struct { + +[#1 Trailing delimiter] = 0:8-0:9 + >-< +0| type Foo struct { + +[#1 Domain] = 0:0-2:1 + >----------------- +0| type Foo struct { +1| bar int +2| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 1:4-1:7 + >---< +1| bar int + +[#2 Removal] = 1:4-1:8 + >----< +1| bar int + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| bar int + +[#2 Trailing delimiter] = 1:7-1:8 + >-< +1| bar int + +[#2 Domain] = 1:4-1:11 + >-------< +1| bar int + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.field.interface.scope b/data/fixtures/scopes/go/name/name.field.interface.scope new file mode 100644 index 0000000000..9b88b65615 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.field.interface.scope @@ -0,0 +1,45 @@ +type Foo interface { + bar() +} +--- + +[#1 Content] = 0:5-0:8 + >---< +0| type Foo interface { + +[#1 Removal] = 0:5-0:9 + >----< +0| type Foo interface { + +[#1 Leading delimiter] = 0:4-0:5 + >-< +0| type Foo interface { + +[#1 Trailing delimiter] = 0:8-0:9 + >-< +0| type Foo interface { + +[#1 Domain] = 0:0-2:1 + >-------------------- +0| type Foo interface { +1| bar() +2| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = 1:4-1:7 + >---< +1| bar() + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| bar() + +[#2 Domain] = 1:4-1:9 + >-----< +1| bar() + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.iteration.class.scope b/data/fixtures/scopes/go/name/name.iteration.class.scope new file mode 100644 index 0000000000..90d5342216 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.class.scope @@ -0,0 +1,13 @@ +type Foo struct { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:19 + >-------------------< +0| type Foo struct { } + + +[#2 Content] = +[#2 Domain] = 0:17-0:18 + >-< +0| type Foo struct { } diff --git a/data/fixtures/scopes/go/name/name.iteration.interface.scope b/data/fixtures/scopes/go/name/name.iteration.interface.scope new file mode 100644 index 0000000000..6e6f9959f7 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.interface.scope @@ -0,0 +1,13 @@ +type Foo interface { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:22 + >----------------------< +0| type Foo interface { } + + +[#2 Content] = +[#2 Domain] = 0:20-0:21 + >-< +0| type Foo interface { } diff --git a/data/fixtures/scopes/go/statement/statement.break.scope b/data/fixtures/scopes/go/statement/statement.break.scope new file mode 100644 index 0000000000..c21b362a89 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.break.scope @@ -0,0 +1,33 @@ +for { + break +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >----- +0| for { +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/go/statement/statement.continue.scope b/data/fixtures/scopes/go/statement/statement.continue.scope new file mode 100644 index 0000000000..2f62d1e9b8 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.continue.scope @@ -0,0 +1,33 @@ +for { + continue +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >----- +0| for { +1| continue +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:12 + >--------< +1| continue + +[#2 Removal] = 1:0-2:0 + >------------ +1| continue +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| continue + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.field.class.scope b/data/fixtures/scopes/go/statement/statement.field.class.scope new file mode 100644 index 0000000000..c0765a0205 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.field.class.scope @@ -0,0 +1,33 @@ +type Foo struct { + bar int +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >----------------- +0| type Foo struct { +1| bar int +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:11 + >-------< +1| bar int + +[#2 Removal] = 1:0-2:0 + >----------- +1| bar int +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| bar int + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.field.interface.scope b/data/fixtures/scopes/go/statement/statement.field.interface.scope new file mode 100644 index 0000000000..51ef08b513 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.field.interface.scope @@ -0,0 +1,33 @@ +type Foo interface { + bar() +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >-------------------- +0| type Foo interface { +1| bar() +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:9 + >-----< +1| bar() + +[#2 Removal] = 1:0-2:0 + >--------- +1| bar() +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| bar() + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/statement/statement.iteration.class.scope b/data/fixtures/scopes/go/statement/statement.iteration.class.scope new file mode 100644 index 0000000000..90d5342216 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.class.scope @@ -0,0 +1,13 @@ +type Foo struct { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:19 + >-------------------< +0| type Foo struct { } + + +[#2 Content] = +[#2 Domain] = 0:17-0:18 + >-< +0| type Foo struct { } diff --git a/data/fixtures/scopes/go/statement/statement.iteration.interface.scope b/data/fixtures/scopes/go/statement/statement.iteration.interface.scope new file mode 100644 index 0000000000..6e6f9959f7 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.interface.scope @@ -0,0 +1,13 @@ +type Foo interface { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:22 + >----------------------< +0| type Foo interface { } + + +[#2 Content] = +[#2 Domain] = 0:20-0:21 + >-< +0| type Foo interface { } diff --git a/data/fixtures/scopes/go/statement/statement.return.scope b/data/fixtures/scopes/go/statement/statement.return.scope new file mode 100644 index 0000000000..3129c896a0 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.return.scope @@ -0,0 +1,33 @@ +func foo() int { + return 0 +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >---------------- +0| func foo() int { +1| return 0 +2| } + -< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:12 + >--------< +1| return 0 + +[#2 Removal] = 1:0-2:0 + >------------ +1| return 0 +2| } + < + +[#2 Leading delimiter] = 1:0-1:4 + >----< +1| return 0 + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/type/type.field.class.scope b/data/fixtures/scopes/go/type/type.field.class.scope new file mode 100644 index 0000000000..9b82fdda48 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.field.class.scope @@ -0,0 +1,34 @@ +type Foo struct { + bar int +} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-2:1 + >----------------- +0| type Foo struct { +1| bar int +2| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 1:8-1:11 + >---< +1| bar int + +[#2 Removal] = 1:7-1:11 + >----< +1| bar int + +[#2 Leading delimiter] = 1:7-1:8 + >-< +1| bar int + +[#2 Domain] = 1:4-1:11 + >-------< +1| bar int + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.iteration.class.scope b/data/fixtures/scopes/go/type/type.iteration.class.scope new file mode 100644 index 0000000000..90d5342216 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.iteration.class.scope @@ -0,0 +1,13 @@ +type Foo struct { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:19 + >-------------------< +0| type Foo struct { } + + +[#2 Content] = +[#2 Domain] = 0:17-0:18 + >-< +0| type Foo struct { } diff --git a/packages/common/src/scopeSupportFacets/go.ts b/packages/common/src/scopeSupportFacets/go.ts index 3b3df4610c..741c6c9f8a 100644 --- a/packages/common/src/scopeSupportFacets/go.ts +++ b/packages/common/src/scopeSupportFacets/go.ts @@ -18,6 +18,7 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "statement.class": supported, "statement.interface": supported, "statement.field.class": supported, + "statement.field.interface": supported, "statement.function": supported, "statement.method": supported, "statement.if": supported, @@ -114,6 +115,7 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "name.class": supported, "name.interface": supported, "name.field.class": supported, + "name.field.interface": supported, "name.argument.formal": supported, "name.argument.formal.iteration": supported, "name.argument.formal.method": supported, @@ -153,7 +155,6 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "type.iteration.block": supported, "type.iteration.class": supported, "type.iteration.document": supported, - "type.iteration.interface": supported, "interior.class": supported, "interior.interface": supported, @@ -211,11 +212,6 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "value.field.enum": notApplicable, "value.iteration.enum": notApplicable, - // Interface field declarations - "statement.field.interface": notApplicable, - "name.field.interface": notApplicable, - "type.field.interface": notApplicable, - // Constructors "statement.constructor": notApplicable, "namedFunction.constructor": notApplicable, @@ -305,6 +301,10 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { notebookCell: notApplicable, "interior.cell": notApplicable, + // Interface field types + "type.field.interface": notApplicable, + "type.iteration.interface": notApplicable, + // Miscellaneous "statement.misc": notApplicable, "name.assignment.pattern": notApplicable, diff --git a/queries/go.scm b/queries/go.scm index 82eb3723bf..01ce70e110 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -75,7 +75,12 @@ (type_declaration (type_spec name: (_) @name - type: (struct_type) + type: (struct_type + (field_declaration_list + "{" @statement.iteration.start.endOf @name.iteration.start.endOf @type.iteration.start.endOf + "}" @statement.iteration.end.startOf @name.iteration.end.startOf @type.iteration.end.startOf + ) + ) ) ) @class @type @name.domain @@ -83,10 +88,25 @@ (type_declaration (type_spec name: (_) @name - type: (interface_type) + type: (interface_type + "{" @statement.iteration.start.endOf @name.iteration.start.endOf + "}" @statement.iteration.end.startOf @name.iteration.end.startOf + ) ) ) @type @name.domain +;;!! type Foo interface { bar() } +(method_spec + name: (_) @name +) @statement @name.domain + +;;!! type Foo struct { bar int } +;;!! type Foo interface { bar() } +(field_declaration + name: (_) @name + type: (_) @type +) @statement @_.domain + ;; What should map and list refer to in Go programs? ;; ;; The obvious answer is that map should refer to map and struct composite literals, From 4c74b889e244080e8449f258dbc1a58f1e32d07c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 14:50:56 +0100 Subject: [PATCH 06/17] Update facet description --- data/scopeSupportFacetInfos.md | 6 +++--- .../common/src/scopeSupportFacets/scopeSupportFacetInfos.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/scopeSupportFacetInfos.md b/data/scopeSupportFacetInfos.md index 7418dff4b3..199fc5284b 100644 --- a/data/scopeSupportFacetInfos.md +++ b/data/scopeSupportFacetInfos.md @@ -86,7 +86,7 @@ ### class -- `class` A class in an object-oriented language +- `class` A class/struct in an object-oriented language - `class.iteration.block` Iteration scope for classes: statement blocks (body of functions/if-statements/for-loops/etc). - `class.iteration.document` Iteration scope for classes: the entire document including leading and trailing empty lines. @@ -301,13 +301,13 @@ - `statement.assignment` An assignment statement - `statement.break` A break statement -- `statement.class` A class declaration +- `statement.class` A class/struct declaration - `statement.command` A command statement, eg Talon spoken command or bash - `statement.constructor` A constructor declaration - `statement.continue` A continue statement - `statement.doWhile` A do-while loop statement - `statement.enum` An enum declaration -- `statement.field.class` A field declaration in a class +- `statement.field.class` A field declaration in a class/struct - `statement.field.interface` A field declaration in a interface - `statement.for` A for loop statement - `statement.foreach` A for-each loop statement diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 224ff19eb9..05ef8f340b 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -71,7 +71,7 @@ export const scopeSupportFacetInfos: Record< }, "statement.class": { - description: "A class declaration", + description: "A class/struct declaration", scopeType: "statement", }, "statement.interface": { @@ -83,7 +83,7 @@ export const scopeSupportFacetInfos: Record< scopeType: "statement", }, "statement.field.class": { - description: "A field declaration in a class", + description: "A field declaration in a class/struct", scopeType: "statement", }, "statement.field.interface": { @@ -181,7 +181,7 @@ export const scopeSupportFacetInfos: Record< "statement.iteration.block": blockIter("statement", "statements"), class: { - description: "A class in an object-oriented language", + description: "A class/struct in an object-oriented language", scopeType: "class", }, "class.iteration.document": documentIter("class", "classes"), From c5de8a08ff5ba4d9e3441fa8e071cbf756b39649 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 15:25:00 +0100 Subject: [PATCH 07/17] tests --- .../branch/branch.switchCase.iteration.scope | 7 +++ .../branch/branch.switchCase.iteration2.scope | 7 +++ data/fixtures/scopes/go/condition.for.scope | 20 ------- data/fixtures/scopes/go/condition.if.scope | 57 ------------------- .../scopes/go/interior/interior.switch.scope | 10 ++++ .../scopes/go/interior/interior.switch2.scope | 10 ++++ .../scopes/go/name/name.iteration.block.scope | 13 +++++ .../go/name/name.iteration.block2.scope | 13 +++++ .../go/name/name.iteration.block3.scope | 13 +++++ .../statement/statement.iteration.block.scope | 13 +++++ .../statement.iteration.block2.scope | 13 +++++ .../statement.iteration.block3.scope | 13 +++++ .../go/statement/statement.switch.scope | 10 ++++ .../scopes/go/type/type.iteration.block.scope | 13 +++++ .../go/type/type.iteration.block2.scope | 13 +++++ .../go/type/type.iteration.block3.scope | 13 +++++ .../go/value/value.iteration.block.scope | 13 +++++ .../go/value/value.iteration.block2.scope | 13 +++++ .../go/value/value.iteration.block3.scope | 13 +++++ .../scopes/go/value/value.switch.scope | 24 ++++++++ .../scopes/go/value/value.switch2.scope | 24 ++++++++ queries/go.scm | 34 ++++++++--- 22 files changed, 274 insertions(+), 85 deletions(-) create mode 100644 data/fixtures/scopes/go/branch/branch.switchCase.iteration.scope create mode 100644 data/fixtures/scopes/go/branch/branch.switchCase.iteration2.scope delete mode 100644 data/fixtures/scopes/go/condition.for.scope delete mode 100644 data/fixtures/scopes/go/condition.if.scope create mode 100644 data/fixtures/scopes/go/interior/interior.switch.scope create mode 100644 data/fixtures/scopes/go/interior/interior.switch2.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.block.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.block2.scope create mode 100644 data/fixtures/scopes/go/name/name.iteration.block3.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.block.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.block2.scope create mode 100644 data/fixtures/scopes/go/statement/statement.iteration.block3.scope create mode 100644 data/fixtures/scopes/go/statement/statement.switch.scope create mode 100644 data/fixtures/scopes/go/type/type.iteration.block.scope create mode 100644 data/fixtures/scopes/go/type/type.iteration.block2.scope create mode 100644 data/fixtures/scopes/go/type/type.iteration.block3.scope create mode 100644 data/fixtures/scopes/go/value/value.iteration.block.scope create mode 100644 data/fixtures/scopes/go/value/value.iteration.block2.scope create mode 100644 data/fixtures/scopes/go/value/value.iteration.block3.scope create mode 100644 data/fixtures/scopes/go/value/value.switch.scope create mode 100644 data/fixtures/scopes/go/value/value.switch2.scope diff --git a/data/fixtures/scopes/go/branch/branch.switchCase.iteration.scope b/data/fixtures/scopes/go/branch/branch.switchCase.iteration.scope new file mode 100644 index 0000000000..82cc8a4e12 --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.switchCase.iteration.scope @@ -0,0 +1,7 @@ +switch foo { } +--- + +[Content] = +[Domain] = 0:12-0:13 + >-< +0| switch foo { } diff --git a/data/fixtures/scopes/go/branch/branch.switchCase.iteration2.scope b/data/fixtures/scopes/go/branch/branch.switchCase.iteration2.scope new file mode 100644 index 0000000000..80f83532f7 --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.switchCase.iteration2.scope @@ -0,0 +1,7 @@ +switch v := x.(type) { } +--- + +[Content] = +[Domain] = 0:22-0:23 + >-< +0| switch v := x.(type) { } diff --git a/data/fixtures/scopes/go/condition.for.scope b/data/fixtures/scopes/go/condition.for.scope deleted file mode 100644 index e453771326..0000000000 --- a/data/fixtures/scopes/go/condition.for.scope +++ /dev/null @@ -1,20 +0,0 @@ -for i := 0; i < size; i++ {} ---- - -[Content] = 0:12-0:20 - >--------< -0| for i := 0; i < size; i++ {} - -[Removal] = 0:11-0:20 - >---------< -0| for i := 0; i < size; i++ {} - -[Leading delimiter] = 0:11-0:12 - >-< -0| for i := 0; i < size; i++ {} - -[Domain] = 0:0-0:28 - >----------------------------< -0| for i := 0; i < size; i++ {} - -[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/condition.if.scope b/data/fixtures/scopes/go/condition.if.scope deleted file mode 100644 index 0b2a84f7bc..0000000000 --- a/data/fixtures/scopes/go/condition.if.scope +++ /dev/null @@ -1,57 +0,0 @@ -if true { -} else if false { -} else { -} ---- - -[#1 Content] = 0:3-0:7 - >----< -0| if true { - -[#1 Removal] = 0:3-0:8 - >-----< -0| if true { - -[#1 Leading delimiter] = 0:2-0:3 - >-< -0| if true { - -[#1 Trailing delimiter] = 0:7-0:8 - >-< -0| if true { - -[#1 Domain] = 0:0-3:1 - >--------- -0| if true { -1| } else if false { -2| } else { -3| } - -< - -[#1 Insertion delimiter] = " " - - -[#2 Content] = 1:10-1:15 - >-----< -1| } else if false { - -[#2 Removal] = 1:10-1:16 - >------< -1| } else if false { - -[#2 Leading delimiter] = 1:9-1:10 - >-< -1| } else if false { - -[#2 Trailing delimiter] = 1:15-1:16 - >-< -1| } else if false { - -[#2 Domain] = 1:7-3:1 - >---------- -1| } else if false { -2| } else { -3| } - -< - -[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.switch.scope b/data/fixtures/scopes/go/interior/interior.switch.scope new file mode 100644 index 0000000000..5e37bb02c8 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.switch.scope @@ -0,0 +1,10 @@ +switch foo { } +--- + +[Content] = +[Removal] = +[Domain] = 0:12-0:13 + >-< +0| switch foo { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/interior/interior.switch2.scope b/data/fixtures/scopes/go/interior/interior.switch2.scope new file mode 100644 index 0000000000..02f00f2b00 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.switch2.scope @@ -0,0 +1,10 @@ +switch v := x.(type) { } +--- + +[Content] = +[Removal] = +[Domain] = 0:22-0:23 + >-< +0| switch v := x.(type) { } + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.iteration.block.scope b/data/fixtures/scopes/go/name/name.iteration.block.scope new file mode 100644 index 0000000000..eb1487158f --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.block.scope @@ -0,0 +1,13 @@ +func foo() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| func foo() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| func foo() { } diff --git a/data/fixtures/scopes/go/name/name.iteration.block2.scope b/data/fixtures/scopes/go/name/name.iteration.block2.scope new file mode 100644 index 0000000000..dfc0523a61 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.block2.scope @@ -0,0 +1,13 @@ +if true { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| if true { } + + +[#2 Content] = +[#2 Domain] = 0:9-0:10 + >-< +0| if true { } diff --git a/data/fixtures/scopes/go/name/name.iteration.block3.scope b/data/fixtures/scopes/go/name/name.iteration.block3.scope new file mode 100644 index 0000000000..ff81219a4b --- /dev/null +++ b/data/fixtures/scopes/go/name/name.iteration.block3.scope @@ -0,0 +1,13 @@ +for { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:7 + >-------< +0| for { } + + +[#2 Content] = +[#2 Domain] = 0:5-0:6 + >-< +0| for { } diff --git a/data/fixtures/scopes/go/statement/statement.iteration.block.scope b/data/fixtures/scopes/go/statement/statement.iteration.block.scope new file mode 100644 index 0000000000..eb1487158f --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.block.scope @@ -0,0 +1,13 @@ +func foo() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| func foo() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| func foo() { } diff --git a/data/fixtures/scopes/go/statement/statement.iteration.block2.scope b/data/fixtures/scopes/go/statement/statement.iteration.block2.scope new file mode 100644 index 0000000000..dfc0523a61 --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.block2.scope @@ -0,0 +1,13 @@ +if true { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| if true { } + + +[#2 Content] = +[#2 Domain] = 0:9-0:10 + >-< +0| if true { } diff --git a/data/fixtures/scopes/go/statement/statement.iteration.block3.scope b/data/fixtures/scopes/go/statement/statement.iteration.block3.scope new file mode 100644 index 0000000000..ff81219a4b --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.iteration.block3.scope @@ -0,0 +1,13 @@ +for { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:7 + >-------< +0| for { } + + +[#2 Content] = +[#2 Domain] = 0:5-0:6 + >-< +0| for { } diff --git a/data/fixtures/scopes/go/statement/statement.switch.scope b/data/fixtures/scopes/go/statement/statement.switch.scope new file mode 100644 index 0000000000..6a32cbcf3f --- /dev/null +++ b/data/fixtures/scopes/go/statement/statement.switch.scope @@ -0,0 +1,10 @@ +switch foo {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| switch foo {} + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/type/type.iteration.block.scope b/data/fixtures/scopes/go/type/type.iteration.block.scope new file mode 100644 index 0000000000..eb1487158f --- /dev/null +++ b/data/fixtures/scopes/go/type/type.iteration.block.scope @@ -0,0 +1,13 @@ +func foo() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| func foo() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| func foo() { } diff --git a/data/fixtures/scopes/go/type/type.iteration.block2.scope b/data/fixtures/scopes/go/type/type.iteration.block2.scope new file mode 100644 index 0000000000..dfc0523a61 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.iteration.block2.scope @@ -0,0 +1,13 @@ +if true { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| if true { } + + +[#2 Content] = +[#2 Domain] = 0:9-0:10 + >-< +0| if true { } diff --git a/data/fixtures/scopes/go/type/type.iteration.block3.scope b/data/fixtures/scopes/go/type/type.iteration.block3.scope new file mode 100644 index 0000000000..ff81219a4b --- /dev/null +++ b/data/fixtures/scopes/go/type/type.iteration.block3.scope @@ -0,0 +1,13 @@ +for { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:7 + >-------< +0| for { } + + +[#2 Content] = +[#2 Domain] = 0:5-0:6 + >-< +0| for { } diff --git a/data/fixtures/scopes/go/value/value.iteration.block.scope b/data/fixtures/scopes/go/value/value.iteration.block.scope new file mode 100644 index 0000000000..eb1487158f --- /dev/null +++ b/data/fixtures/scopes/go/value/value.iteration.block.scope @@ -0,0 +1,13 @@ +func foo() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| func foo() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| func foo() { } diff --git a/data/fixtures/scopes/go/value/value.iteration.block2.scope b/data/fixtures/scopes/go/value/value.iteration.block2.scope new file mode 100644 index 0000000000..dfc0523a61 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.iteration.block2.scope @@ -0,0 +1,13 @@ +if true { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| if true { } + + +[#2 Content] = +[#2 Domain] = 0:9-0:10 + >-< +0| if true { } diff --git a/data/fixtures/scopes/go/value/value.iteration.block3.scope b/data/fixtures/scopes/go/value/value.iteration.block3.scope new file mode 100644 index 0000000000..ff81219a4b --- /dev/null +++ b/data/fixtures/scopes/go/value/value.iteration.block3.scope @@ -0,0 +1,13 @@ +for { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:7 + >-------< +0| for { } + + +[#2 Content] = +[#2 Domain] = 0:5-0:6 + >-< +0| for { } diff --git a/data/fixtures/scopes/go/value/value.switch.scope b/data/fixtures/scopes/go/value/value.switch.scope new file mode 100644 index 0000000000..b27bac7781 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.switch.scope @@ -0,0 +1,24 @@ +switch foo {} +--- + +[Content] = 0:7-0:10 + >---< +0| switch foo {} + +[Removal] = 0:7-0:11 + >----< +0| switch foo {} + +[Leading delimiter] = 0:6-0:7 + >-< +0| switch foo {} + +[Trailing delimiter] = 0:10-0:11 + >-< +0| switch foo {} + +[Domain] = 0:0-0:13 + >-------------< +0| switch foo {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.switch2.scope b/data/fixtures/scopes/go/value/value.switch2.scope new file mode 100644 index 0000000000..484e73f3db --- /dev/null +++ b/data/fixtures/scopes/go/value/value.switch2.scope @@ -0,0 +1,24 @@ +switch v := x.(type) {} +--- + +[Content] = 0:7-0:20 + >-------------< +0| switch v := x.(type) {} + +[Removal] = 0:7-0:21 + >--------------< +0| switch v := x.(type) {} + +[Leading delimiter] = 0:6-0:7 + >-< +0| switch v := x.(type) {} + +[Trailing delimiter] = 0:20-0:21 + >-< +0| switch v := x.(type) {} + +[Domain] = 0:0-0:23 + >-----------------------< +0| switch v := x.(type) {} + +[Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 01ce70e110..51c5e4a9b7 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -44,12 +44,20 @@ (source_file) @class.iteration @statement.iteration @namedFunction.iteration (#document-range! @class.iteration @statement.iteration @namedFunction.iteration) ) - ( (source_file) @name.iteration @value.iteration @type.iteration (#document-range! @name.iteration @value.iteration @type.iteration) ) +(block + "{" @statement.iteration.start.endOf + "}" @statement.iteration.end.startOf +) +(block + "{" @name.iteration.start.endOf @value.iteration.start.endOf @type.iteration.start.endOf + "}" @name.iteration.end.startOf @value.iteration.end.startOf @type.iteration.end.startOf +) + ;;!! { } ;;! ^ (_ @@ -69,6 +77,7 @@ (#character-range! @textFragment 1 -1) ) +;; // Hello world (comment) @comment @textFragment ;;!! type Foo struct {} @@ -275,8 +284,6 @@ ;; func literal (func_literal) @anonymousFunction -;; switch-based branch - ( [ (default_case) @@ -287,12 +294,23 @@ (#insertion-delimiter! @branch "\n") ) -[ - (type_switch_statement) - (expression_switch_statement) -] @branch.iteration +;;!! switch foo {} +(expression_switch_statement + value: (_) @value + "{" @interior.start.endOf @branch.iteration.start.endOf @condition.iteration.start.endOf + "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf +) @value.domain -;; if-else-based branch +;;!! switch v := x.(type) {} +(type_switch_statement + "switch" + . + _ @value.start + _ @value.end + . + "{" @interior.start.endOf @branch.iteration.start.endOf @condition.iteration.start.endOf + "}" @interior.end.startOf @branch.iteration.end.startOf @condition.iteration.end.startOf +) @value.domain ;; The outermost if statement ( From 4d26c3bc4f2d656e25744e16f130e07be21c0f05 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 15:26:06 +0100 Subject: [PATCH 08/17] test --- .../scopes/go/condition/condition.for.scope | 20 +++++++ .../scopes/go/condition/condition.if.scope | 57 +++++++++++++++++++ .../condition.switchCase.iteration.scope | 7 +++ .../condition.switchCase.iteration2.scope | 7 +++ 4 files changed, 91 insertions(+) create mode 100644 data/fixtures/scopes/go/condition/condition.for.scope create mode 100644 data/fixtures/scopes/go/condition/condition.if.scope create mode 100644 data/fixtures/scopes/go/condition/condition.switchCase.iteration.scope create mode 100644 data/fixtures/scopes/go/condition/condition.switchCase.iteration2.scope diff --git a/data/fixtures/scopes/go/condition/condition.for.scope b/data/fixtures/scopes/go/condition/condition.for.scope new file mode 100644 index 0000000000..e453771326 --- /dev/null +++ b/data/fixtures/scopes/go/condition/condition.for.scope @@ -0,0 +1,20 @@ +for i := 0; i < size; i++ {} +--- + +[Content] = 0:12-0:20 + >--------< +0| for i := 0; i < size; i++ {} + +[Removal] = 0:11-0:20 + >---------< +0| for i := 0; i < size; i++ {} + +[Leading delimiter] = 0:11-0:12 + >-< +0| for i := 0; i < size; i++ {} + +[Domain] = 0:0-0:28 + >----------------------------< +0| for i := 0; i < size; i++ {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/condition/condition.if.scope b/data/fixtures/scopes/go/condition/condition.if.scope new file mode 100644 index 0000000000..0b2a84f7bc --- /dev/null +++ b/data/fixtures/scopes/go/condition/condition.if.scope @@ -0,0 +1,57 @@ +if true { +} else if false { +} else { +} +--- + +[#1 Content] = 0:3-0:7 + >----< +0| if true { + +[#1 Removal] = 0:3-0:8 + >-----< +0| if true { + +[#1 Leading delimiter] = 0:2-0:3 + >-< +0| if true { + +[#1 Trailing delimiter] = 0:7-0:8 + >-< +0| if true { + +[#1 Domain] = 0:0-3:1 + >--------- +0| if true { +1| } else if false { +2| } else { +3| } + -< + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 1:10-1:15 + >-----< +1| } else if false { + +[#2 Removal] = 1:10-1:16 + >------< +1| } else if false { + +[#2 Leading delimiter] = 1:9-1:10 + >-< +1| } else if false { + +[#2 Trailing delimiter] = 1:15-1:16 + >-< +1| } else if false { + +[#2 Domain] = 1:7-3:1 + >---------- +1| } else if false { +2| } else { +3| } + -< + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/condition/condition.switchCase.iteration.scope b/data/fixtures/scopes/go/condition/condition.switchCase.iteration.scope new file mode 100644 index 0000000000..82cc8a4e12 --- /dev/null +++ b/data/fixtures/scopes/go/condition/condition.switchCase.iteration.scope @@ -0,0 +1,7 @@ +switch foo { } +--- + +[Content] = +[Domain] = 0:12-0:13 + >-< +0| switch foo { } diff --git a/data/fixtures/scopes/go/condition/condition.switchCase.iteration2.scope b/data/fixtures/scopes/go/condition/condition.switchCase.iteration2.scope new file mode 100644 index 0000000000..80f83532f7 --- /dev/null +++ b/data/fixtures/scopes/go/condition/condition.switchCase.iteration2.scope @@ -0,0 +1,7 @@ +switch v := x.(type) { } +--- + +[Content] = +[Domain] = 0:22-0:23 + >-< +0| switch v := x.(type) { } From 51fe1b6a95afb0d6d774dc2ece095afe442ba448 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 15:30:34 +0100 Subject: [PATCH 09/17] argument --- .../argument/argument.actual.iteration.scope | 10 ++++ .../argument.actual.method.iteration.scope | 10 ++++ .../argument.actual.method.multiLine.scope | 44 +++++++++++++++ .../argument.actual.method.singleLine.scope | 33 ++++++++++++ .../argument/argument.actual.multiLine.scope | 44 +++++++++++++++ .../argument/argument.actual.singleLine.scope | 33 ++++++++++++ .../argument/argument.formal.iteration.scope | 10 ++++ .../argument.formal.lambda.iteration.scope | 10 ++++ .../argument.formal.lambda.multiLine.scope | 44 +++++++++++++++ .../argument.formal.lambda.singleLine.scope | 33 ++++++++++++ .../argument.formal.method.iteration.scope | 10 ++++ .../argument.formal.method.multiLine.scope | 53 +++++++++++++++++++ .../argument.formal.method.singleLine.scope | 42 +++++++++++++++ .../argument/argument.formal.multiLine.scope | 44 +++++++++++++++ .../argument/argument.formal.singleLine.scope | 33 ++++++++++++ queries/go.scm | 4 +- 16 files changed, 456 insertions(+), 1 deletion(-) create mode 100644 data/fixtures/scopes/go/argument/argument.actual.iteration.scope create mode 100644 data/fixtures/scopes/go/argument/argument.actual.method.iteration.scope create mode 100644 data/fixtures/scopes/go/argument/argument.actual.method.multiLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.actual.method.singleLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.actual.multiLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.actual.singleLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.lambda.iteration.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.lambda.multiLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.lambda.singleLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.method.iteration.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.method.multiLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.method.singleLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.multiLine.scope create mode 100644 data/fixtures/scopes/go/argument/argument.formal.singleLine.scope diff --git a/data/fixtures/scopes/go/argument/argument.actual.iteration.scope b/data/fixtures/scopes/go/argument/argument.actual.iteration.scope new file mode 100644 index 0000000000..0ea7673e0e --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.actual.iteration.scope @@ -0,0 +1,10 @@ +foo(aaa, bbb, ccc) +--- + +[Content] = 0:4-0:17 + >-------------< +0| foo(aaa, bbb, ccc) + +[Domain] = 0:0-0:18 + >------------------< +0| foo(aaa, bbb, ccc) diff --git a/data/fixtures/scopes/go/argument/argument.actual.method.iteration.scope b/data/fixtures/scopes/go/argument/argument.actual.method.iteration.scope new file mode 100644 index 0000000000..3afa7f9d34 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.actual.method.iteration.scope @@ -0,0 +1,10 @@ +foo.bar(aaa, bbb, ccc) +--- + +[Content] = 0:8-0:21 + >-------------< +0| foo.bar(aaa, bbb, ccc) + +[Domain] = 0:0-0:22 + >----------------------< +0| foo.bar(aaa, bbb, ccc) diff --git a/data/fixtures/scopes/go/argument/argument.actual.method.multiLine.scope b/data/fixtures/scopes/go/argument/argument.actual.method.multiLine.scope new file mode 100644 index 0000000000..d77be8ad8e --- /dev/null +++ b/data/fixtures/scopes/go/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/go/argument/argument.actual.method.singleLine.scope b/data/fixtures/scopes/go/argument/argument.actual.method.singleLine.scope new file mode 100644 index 0000000000..d22bd33706 --- /dev/null +++ b/data/fixtures/scopes/go/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/go/argument/argument.actual.multiLine.scope b/data/fixtures/scopes/go/argument/argument.actual.multiLine.scope new file mode 100644 index 0000000000..796855df6e --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.actual.multiLine.scope @@ -0,0 +1,44 @@ +foo( + 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/go/argument/argument.actual.singleLine.scope b/data/fixtures/scopes/go/argument/argument.actual.singleLine.scope new file mode 100644 index 0000000000..b1a9403ff3 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.actual.singleLine.scope @@ -0,0 +1,33 @@ +foo(aaa, bbb) +--- + +[#1 Content] = +[#1 Domain] = 0:4-0:7 + >---< +0| foo(aaa, bbb) + +[#1 Removal] = 0:4-0:9 + >-----< +0| foo(aaa, bbb) + +[#1 Trailing delimiter] = 0:7-0:9 + >--< +0| foo(aaa, bbb) + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:9-0:12 + >---< +0| foo(aaa, bbb) + +[#2 Removal] = 0:7-0:12 + >-----< +0| foo(aaa, bbb) + +[#2 Leading delimiter] = 0:7-0:9 + >--< +0| foo(aaa, bbb) + +[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argument/argument.formal.iteration.scope b/data/fixtures/scopes/go/argument/argument.formal.iteration.scope new file mode 100644 index 0000000000..4ae5d8a591 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.iteration.scope @@ -0,0 +1,10 @@ +func foo(aaa int, bbb string, ccc int) {} +--- + +[Content] = 0:9-0:37 + >----------------------------< +0| func foo(aaa int, bbb string, ccc int) {} + +[Domain] = 0:0-0:41 + >-----------------------------------------< +0| func foo(aaa int, bbb string, ccc int) {} diff --git a/data/fixtures/scopes/go/argument/argument.formal.lambda.iteration.scope b/data/fixtures/scopes/go/argument/argument.formal.lambda.iteration.scope new file mode 100644 index 0000000000..c70dfa181e --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.lambda.iteration.scope @@ -0,0 +1,10 @@ +func(aaa int, bbb string, ccc int) {} +--- + +[Content] = 0:5-0:33 + >----------------------------< +0| func(aaa int, bbb string, ccc int) {} + +[Domain] = 0:0-0:37 + >-------------------------------------< +0| func(aaa int, bbb string, ccc int) {} diff --git a/data/fixtures/scopes/go/argument/argument.formal.lambda.multiLine.scope b/data/fixtures/scopes/go/argument/argument.formal.lambda.multiLine.scope new file mode 100644 index 0000000000..e70c7ccd1d --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.lambda.multiLine.scope @@ -0,0 +1,44 @@ +func( + aaa int, + bbb string, +) {} +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:11 + >-------< +1| aaa int, + +[#1 Removal] = 1:4-2:4 + >-------- +1| aaa int, +2| bbb string, + ----< + +[#1 Trailing delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:14 + >----------< +2| bbb string, + +[#2 Removal] = 1:11-2:14 + >- +1| aaa int, +2| bbb string, + --------------< + +[#2 Leading delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#2 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argument/argument.formal.lambda.singleLine.scope b/data/fixtures/scopes/go/argument/argument.formal.lambda.singleLine.scope new file mode 100644 index 0000000000..e788b37431 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.lambda.singleLine.scope @@ -0,0 +1,33 @@ +func(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:5-0:12 + >-------< +0| func(aaa int, bbb string) {} + +[#1 Removal] = 0:5-0:14 + >---------< +0| func(aaa int, bbb string) {} + +[#1 Trailing delimiter] = 0:12-0:14 + >--< +0| func(aaa int, bbb string) {} + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:14-0:24 + >----------< +0| func(aaa int, bbb string) {} + +[#2 Removal] = 0:12-0:24 + >------------< +0| func(aaa int, bbb string) {} + +[#2 Leading delimiter] = 0:12-0:14 + >--< +0| func(aaa int, bbb string) {} + +[#2 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argument/argument.formal.method.iteration.scope b/data/fixtures/scopes/go/argument/argument.formal.method.iteration.scope new file mode 100644 index 0000000000..b30e516cd7 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.method.iteration.scope @@ -0,0 +1,10 @@ +func (f Foo) bar(aaa int, bbb string, ccc int) {} +--- + +[Content] = 0:17-0:45 + >----------------------------< +0| func (f Foo) bar(aaa int, bbb string, ccc int) {} + +[Domain] = 0:0-0:49 + >-------------------------------------------------< +0| func (f Foo) bar(aaa int, bbb string, ccc int) {} diff --git a/data/fixtures/scopes/go/argument/argument.formal.method.multiLine.scope b/data/fixtures/scopes/go/argument/argument.formal.method.multiLine.scope new file mode 100644 index 0000000000..d071c6aecd --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.method.multiLine.scope @@ -0,0 +1,53 @@ +func (f Foo) bar( + aaa int, + bbb string, +) {} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:6-0:11 + >-----< +0| func (f Foo) bar( + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 1:4-1:11 + >-------< +1| aaa int, + +[#2 Removal] = 1:4-2:4 + >-------- +1| aaa int, +2| bbb string, + ----< + +[#2 Trailing delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#2 Insertion delimiter] = ",\n" + + +[#3 Content] = +[#3 Domain] = 2:4-2:14 + >----------< +2| bbb string, + +[#3 Removal] = 1:11-2:14 + >- +1| aaa int, +2| bbb string, + --------------< + +[#3 Leading delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#3 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argument/argument.formal.method.singleLine.scope b/data/fixtures/scopes/go/argument/argument.formal.method.singleLine.scope new file mode 100644 index 0000000000..d81c3a56e9 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.method.singleLine.scope @@ -0,0 +1,42 @@ +func (f Foo) bar(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:6-0:11 + >-----< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:17-0:24 + >-------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#2 Removal] = 0:17-0:26 + >---------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#2 Trailing delimiter] = 0:24-0:26 + >--< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#2 Insertion delimiter] = ", " + + +[#3 Content] = +[#3 Domain] = 0:26-0:36 + >----------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#3 Removal] = 0:24-0:36 + >------------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#3 Leading delimiter] = 0:24-0:26 + >--< +0| func (f Foo) bar(aaa int, bbb string) {} + +[#3 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argument/argument.formal.multiLine.scope b/data/fixtures/scopes/go/argument/argument.formal.multiLine.scope new file mode 100644 index 0000000000..c9b0898619 --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.multiLine.scope @@ -0,0 +1,44 @@ +func foo( + aaa int, + bbb string, +) {} +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:11 + >-------< +1| aaa int, + +[#1 Removal] = 1:4-2:4 + >-------- +1| aaa int, +2| bbb string, + ----< + +[#1 Trailing delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:14 + >----------< +2| bbb string, + +[#2 Removal] = 1:11-2:14 + >- +1| aaa int, +2| bbb string, + --------------< + +[#2 Leading delimiter] = 1:11-2:4 + >- +1| aaa int, +2| bbb string, + ----< + +[#2 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argument/argument.formal.singleLine.scope b/data/fixtures/scopes/go/argument/argument.formal.singleLine.scope new file mode 100644 index 0000000000..3915fbd53e --- /dev/null +++ b/data/fixtures/scopes/go/argument/argument.formal.singleLine.scope @@ -0,0 +1,33 @@ +func foo(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:9-0:16 + >-------< +0| func foo(aaa int, bbb string) {} + +[#1 Removal] = 0:9-0:18 + >---------< +0| func foo(aaa int, bbb string) {} + +[#1 Trailing delimiter] = 0:16-0:18 + >--< +0| func foo(aaa int, bbb string) {} + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:18-0:28 + >----------< +0| func foo(aaa int, bbb string) {} + +[#2 Removal] = 0:16-0:28 + >------------< +0| func foo(aaa int, bbb string) {} + +[#2 Leading delimiter] = 0:16-0:18 + >--< +0| func foo(aaa int, bbb string) {} + +[#2 Insertion delimiter] = ", " diff --git a/queries/go.scm b/queries/go.scm index 51c5e4a9b7..e410b75c8f 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -453,8 +453,10 @@ (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) +;;!! func bar( ) {} +;;! ^ (_ - (parameter_list + parameters: (parameter_list "(" @argumentOrParameter.iteration.start.endOf ")" @argumentOrParameter.iteration.end.startOf ) From c5ed1db4db0f0fcddfba43d5ff22cc5050fc1838 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 15:34:38 +0100 Subject: [PATCH 10/17] argument list --- .../argumentList.actual.empty.scope | 13 ++++++++ .../argumentList.actual.method.empty.scope | 13 ++++++++ ...argumentList.actual.method.multiLine.scope | 33 +++++++++++++++++++ ...rgumentList.actual.method.singleLine.scope | 13 ++++++++ .../argumentList.actual.multiLine.scope | 33 +++++++++++++++++++ .../argumentList.actual.singleLine.scope | 13 ++++++++ .../argumentList.formal.empty.scope | 13 ++++++++ .../argumentList.formal.lambda.empty.scope | 13 ++++++++ ...argumentList.formal.lambda.multiLine.scope | 33 +++++++++++++++++++ ...rgumentList.formal.lambda.singleLine.scope | 13 ++++++++ .../argumentList.formal.method.empty.scope | 13 ++++++++ ...argumentList.formal.method.multiLine.scope | 33 +++++++++++++++++++ ...rgumentList.formal.method.singleLine.scope | 13 ++++++++ .../argumentList.formal.multiLine.scope | 33 +++++++++++++++++++ .../argumentList.formal.singleLine.scope | 13 ++++++++ queries/go.scm | 24 +++++++++----- 16 files changed, 310 insertions(+), 9 deletions(-) create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.empty.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.method.empty.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.method.multiLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.method.singleLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.multiLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.actual.singleLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.empty.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.empty.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.multiLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.singleLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.method.empty.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.method.multiLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.method.singleLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.multiLine.scope create mode 100644 data/fixtures/scopes/go/argumentList/argumentList.formal.singleLine.scope diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.empty.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.empty.scope new file mode 100644 index 0000000000..947915ef96 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.empty.scope @@ -0,0 +1,13 @@ +foo() +--- + +[Content] = +[Removal] = 0:4-0:4 + >< +0| foo() + +[Domain] = 0:0-0:5 + >-----< +0| foo() + +[Insertion delimiter] = "" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.method.empty.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.empty.scope new file mode 100644 index 0000000000..ed61422204 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.empty.scope @@ -0,0 +1,13 @@ +foo.bar() +--- + +[Content] = +[Removal] = 0:8-0:8 + >< +0| foo.bar() + +[Domain] = 0:0-0:9 + >---------< +0| foo.bar() + +[Insertion delimiter] = "" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.method.multiLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.multiLine.scope new file mode 100644 index 0000000000..322349d0e1 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.multiLine.scope @@ -0,0 +1,33 @@ +foo.bar( + aaa, + bbb, +) +--- + +[Content] = 1:4-2:8 + >---- +1| aaa, +2| bbb, + --------< + +[Removal] = 0:8-3:0 + > +0| foo.bar( +1| aaa, +2| bbb, +3| ) + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| aaa, + +[Domain] = 0:0-3:1 + >-------- +0| foo.bar( +1| aaa, +2| bbb, +3| ) + -< + +[Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.method.singleLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.singleLine.scope new file mode 100644 index 0000000000..69cf068256 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.method.singleLine.scope @@ -0,0 +1,13 @@ +foo.bar(aaa, bbb) +--- + +[Content] = +[Removal] = 0:8-0:16 + >--------< +0| foo.bar(aaa, bbb) + +[Domain] = 0:0-0:17 + >-----------------< +0| foo.bar(aaa, bbb) + +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.multiLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.multiLine.scope new file mode 100644 index 0000000000..2781ed2967 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.multiLine.scope @@ -0,0 +1,33 @@ +foo( + aaa, + bbb, +) +--- + +[Content] = 1:4-2:8 + >---- +1| aaa, +2| bbb, + --------< + +[Removal] = 0:4-3:0 + > +0| foo( +1| aaa, +2| bbb, +3| ) + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| aaa, + +[Domain] = 0:0-3:1 + >---- +0| foo( +1| aaa, +2| bbb, +3| ) + -< + +[Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.actual.singleLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.actual.singleLine.scope new file mode 100644 index 0000000000..f0de18dd5d --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.actual.singleLine.scope @@ -0,0 +1,13 @@ +foo(aaa, bbb) +--- + +[Content] = +[Removal] = 0:4-0:12 + >--------< +0| foo(aaa, bbb) + +[Domain] = 0:0-0:13 + >-------------< +0| foo(aaa, bbb) + +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.empty.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.empty.scope new file mode 100644 index 0000000000..cdfade5856 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.empty.scope @@ -0,0 +1,13 @@ +func foo() {} +--- + +[Content] = +[Removal] = 0:9-0:9 + >< +0| func foo() {} + +[Domain] = 0:0-0:13 + >-------------< +0| func foo() {} + +[Insertion delimiter] = "" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.empty.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.empty.scope new file mode 100644 index 0000000000..d883d27f58 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.empty.scope @@ -0,0 +1,13 @@ +func() {} +--- + +[Content] = +[Removal] = 0:5-0:5 + >< +0| func() {} + +[Domain] = 0:0-0:9 + >---------< +0| func() {} + +[Insertion delimiter] = "" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.multiLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.multiLine.scope new file mode 100644 index 0000000000..0a3dc1a323 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.multiLine.scope @@ -0,0 +1,33 @@ +func( + aaa int, + bbb string, +) {} +--- + +[Content] = 1:4-2:15 + >-------- +1| aaa int, +2| bbb string, + ---------------< + +[Removal] = 0:5-3:0 + > +0| func( +1| aaa int, +2| bbb string, +3| ) {} + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| aaa int, + +[Domain] = 0:0-3:4 + >----- +0| func( +1| aaa int, +2| bbb string, +3| ) {} + ----< + +[Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.singleLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.singleLine.scope new file mode 100644 index 0000000000..b347f64e7d --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.lambda.singleLine.scope @@ -0,0 +1,13 @@ +func(aaa int, bbb string) {} +--- + +[Content] = +[Removal] = 0:5-0:24 + >-------------------< +0| func(aaa int, bbb string) {} + +[Domain] = 0:0-0:28 + >----------------------------< +0| func(aaa int, bbb string) {} + +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.method.empty.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.empty.scope new file mode 100644 index 0000000000..28a013fff7 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.empty.scope @@ -0,0 +1,13 @@ +func (f Foo) bar() {} +--- + +[Content] = +[Removal] = 0:17-0:17 + >< +0| func (f Foo) bar() {} + +[Domain] = 0:0-0:21 + >---------------------< +0| func (f Foo) bar() {} + +[Insertion delimiter] = "" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.method.multiLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.multiLine.scope new file mode 100644 index 0000000000..44dac7fc46 --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.multiLine.scope @@ -0,0 +1,33 @@ +func (f Foo) bar( + aaa int, + bbb string, +) {} +--- + +[Content] = 1:4-2:15 + >-------- +1| aaa int, +2| bbb string, + ---------------< + +[Removal] = 0:17-3:0 + > +0| func (f Foo) bar( +1| aaa int, +2| bbb string, +3| ) {} + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| aaa int, + +[Domain] = 0:0-3:4 + >----------------- +0| func (f Foo) bar( +1| aaa int, +2| bbb string, +3| ) {} + ----< + +[Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.method.singleLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.singleLine.scope new file mode 100644 index 0000000000..de87859bba --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.method.singleLine.scope @@ -0,0 +1,13 @@ +func (f Foo) bar(aaa int, bbb string) {} +--- + +[Content] = +[Removal] = 0:17-0:36 + >-------------------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[Domain] = 0:0-0:40 + >----------------------------------------< +0| func (f Foo) bar(aaa int, bbb string) {} + +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.multiLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.multiLine.scope new file mode 100644 index 0000000000..e3b13c6a4d --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.multiLine.scope @@ -0,0 +1,33 @@ +func foo( + aaa int, + bbb string, +) {} +--- + +[Content] = 1:4-2:15 + >-------- +1| aaa int, +2| bbb string, + ---------------< + +[Removal] = 0:9-3:0 + > +0| func foo( +1| aaa int, +2| bbb string, +3| ) {} + < + +[Leading delimiter] = 1:0-1:4 + >----< +1| aaa int, + +[Domain] = 0:0-3:4 + >--------- +0| func foo( +1| aaa int, +2| bbb string, +3| ) {} + ----< + +[Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/go/argumentList/argumentList.formal.singleLine.scope b/data/fixtures/scopes/go/argumentList/argumentList.formal.singleLine.scope new file mode 100644 index 0000000000..8203cbd40f --- /dev/null +++ b/data/fixtures/scopes/go/argumentList/argumentList.formal.singleLine.scope @@ -0,0 +1,13 @@ +func foo(aaa int, bbb string) {} +--- + +[Content] = +[Removal] = 0:9-0:28 + >-------------------< +0| func foo(aaa int, bbb string) {} + +[Domain] = 0:0-0:32 + >--------------------------------< +0| func foo(aaa int, bbb string) {} + +[Insertion delimiter] = ", " diff --git a/queries/go.scm b/queries/go.scm index e410b75c8f..062f6e53f7 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -457,17 +457,23 @@ ;;! ^ (_ parameters: (parameter_list - "(" @argumentOrParameter.iteration.start.endOf - ")" @argumentOrParameter.iteration.end.startOf - ) -) @argumentOrParameter.iteration.domain - + "(" @argumentList.removal.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.removal.end.startOf @argumentOrParameter.iteration.end.startOf + ) @argumentList + (#empty-single-multi-delimiter! @argumentList @argumentList "" ", " ",\n") + (#child-range! @argumentList 1 -2) +) @argumentList.domain @argumentOrParameter.iteration.domain + +;;!! foo( ) +;;! ^ (_ (argument_list - "(" @argumentOrParameter.iteration.start.endOf - ")" @argumentOrParameter.iteration.end.startOf - ) -) @argumentOrParameter.iteration.domain + "(" @argumentList.removal.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.removal.end.startOf @argumentOrParameter.iteration.end.startOf + ) @argumentList + (#empty-single-multi-delimiter! @argumentList @argumentList "" ", " ",\n") + (#child-range! @argumentList 1 -2) +) @argumentList.domain @argumentOrParameter.iteration.domain ;;!! var foo int = 0 ;;! ^^^ From 114cb38ea94325f2b66c3c195dabf0c0d39d3526 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 15:42:02 +0100 Subject: [PATCH 11/17] arguments --- .../name/name.argument.formal.iteration.scope | 13 +++++ ...ame.argument.formal.method.iteration.scope | 13 +++++ .../go/name/name.argument.formal.method.scope | 55 +++++++++++++++++++ .../scopes/go/name/name.argument.formal.scope | 36 ++++++++++++ .../fixtures/scopes/go/name/name.method.scope | 29 ++++++++-- .../type/type.argument.formal.iteration.scope | 13 +++++ ...ype.argument.formal.method.iteration.scope | 13 +++++ .../go/type/type.argument.formal.method.scope | 39 +++++++++++++ .../scopes/go/type/type.argument.formal.scope | 20 +++++++ queries/go.scm | 13 +++++ 10 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 data/fixtures/scopes/go/name/name.argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/go/name/name.argument.formal.method.iteration.scope create mode 100644 data/fixtures/scopes/go/name/name.argument.formal.method.scope create mode 100644 data/fixtures/scopes/go/name/name.argument.formal.scope create mode 100644 data/fixtures/scopes/go/type/type.argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/go/type/type.argument.formal.method.iteration.scope create mode 100644 data/fixtures/scopes/go/type/type.argument.formal.method.scope create mode 100644 data/fixtures/scopes/go/type/type.argument.formal.scope diff --git a/data/fixtures/scopes/go/name/name.argument.formal.iteration.scope b/data/fixtures/scopes/go/name/name.argument.formal.iteration.scope new file mode 100644 index 0000000000..da67ab7983 --- /dev/null +++ b/data/fixtures/scopes/go/name/name.argument.formal.iteration.scope @@ -0,0 +1,13 @@ +func foo(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| func foo(aaa int, bbb string) {} + + +[#2 Content] = +[#2 Domain] = 0:9-0:28 + >-------------------< +0| func foo(aaa int, bbb string) {} diff --git a/data/fixtures/scopes/go/name/name.argument.formal.method.iteration.scope b/data/fixtures/scopes/go/name/name.argument.formal.method.iteration.scope new file mode 100644 index 0000000000..a86e6ecf9b --- /dev/null +++ b/data/fixtures/scopes/go/name/name.argument.formal.method.iteration.scope @@ -0,0 +1,13 @@ +func (f Foo) bar(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:40 + >----------------------------------------< +0| func (f Foo) bar(aaa int, bbb string) {} + + +[#2 Content] = +[#2 Domain] = 0:17-0:36 + >-------------------< +0| func (f Foo) bar(aaa int, bbb string) {} diff --git a/data/fixtures/scopes/go/name/name.argument.formal.method.scope b/data/fixtures/scopes/go/name/name.argument.formal.method.scope new file mode 100644 index 0000000000..a9d14ea6ac --- /dev/null +++ b/data/fixtures/scopes/go/name/name.argument.formal.method.scope @@ -0,0 +1,55 @@ +func (f Foo) bar(aaa int) {} +--- + +[#1 Content] = +[#1 Removal] = 0:13-0:16 + >---< +0| func (f Foo) bar(aaa int) {} + +[#1 Leading delimiter] = 0:12-0:13 + >-< +0| func (f Foo) bar(aaa int) {} + +[#1 Domain] = 0:0-0:28 + >----------------------------< +0| func (f Foo) bar(aaa int) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:6-0:7 + >-< +0| func (f Foo) bar(aaa int) {} + +[#2 Removal] = 0:6-0:8 + >--< +0| func (f Foo) bar(aaa int) {} + +[#2 Trailing delimiter] = 0:7-0:8 + >-< +0| func (f Foo) bar(aaa int) {} + +[#2 Domain] = 0:6-0:11 + >-----< +0| func (f Foo) bar(aaa int) {} + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 0:17-0:20 + >---< +0| func (f Foo) bar(aaa int) {} + +[#3 Removal] = 0:17-0:21 + >----< +0| func (f Foo) bar(aaa int) {} + +[#3 Trailing delimiter] = 0:20-0:21 + >-< +0| func (f Foo) bar(aaa int) {} + +[#3 Domain] = 0:17-0:24 + >-------< +0| func (f Foo) bar(aaa int) {} + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.argument.formal.scope b/data/fixtures/scopes/go/name/name.argument.formal.scope new file mode 100644 index 0000000000..47ba9e689d --- /dev/null +++ b/data/fixtures/scopes/go/name/name.argument.formal.scope @@ -0,0 +1,36 @@ +func foo(aaa int) {} +--- + +[#1 Content] = +[#1 Removal] = 0:5-0:8 + >---< +0| func foo(aaa int) {} + +[#1 Leading delimiter] = 0:4-0:5 + >-< +0| func foo(aaa int) {} + +[#1 Domain] = 0:0-0:20 + >--------------------< +0| func foo(aaa int) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:9-0:12 + >---< +0| func foo(aaa int) {} + +[#2 Removal] = 0:9-0:13 + >----< +0| func foo(aaa int) {} + +[#2 Trailing delimiter] = 0:12-0:13 + >-< +0| func foo(aaa int) {} + +[#2 Domain] = 0:9-0:16 + >-------< +0| func foo(aaa int) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/name/name.method.scope b/data/fixtures/scopes/go/name/name.method.scope index 647cb8304f..4359f05fa9 100644 --- a/data/fixtures/scopes/go/name/name.method.scope +++ b/data/fixtures/scopes/go/name/name.method.scope @@ -1,17 +1,36 @@ func (f Foo) bar() {} --- -[Content] = -[Removal] = 0:13-0:16 +[#1 Content] = +[#1 Removal] = 0:13-0:16 >---< 0| func (f Foo) bar() {} -[Leading delimiter] = 0:12-0:13 +[#1 Leading delimiter] = 0:12-0:13 >-< 0| func (f Foo) bar() {} -[Domain] = 0:0-0:21 +[#1 Domain] = 0:0-0:21 >---------------------< 0| func (f Foo) bar() {} -[Insertion delimiter] = " " +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:6-0:7 + >-< +0| func (f Foo) bar() {} + +[#2 Removal] = 0:6-0:8 + >--< +0| func (f Foo) bar() {} + +[#2 Trailing delimiter] = 0:7-0:8 + >-< +0| func (f Foo) bar() {} + +[#2 Domain] = 0:6-0:11 + >-----< +0| func (f Foo) bar() {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.argument.formal.iteration.scope b/data/fixtures/scopes/go/type/type.argument.formal.iteration.scope new file mode 100644 index 0000000000..da67ab7983 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.argument.formal.iteration.scope @@ -0,0 +1,13 @@ +func foo(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| func foo(aaa int, bbb string) {} + + +[#2 Content] = +[#2 Domain] = 0:9-0:28 + >-------------------< +0| func foo(aaa int, bbb string) {} diff --git a/data/fixtures/scopes/go/type/type.argument.formal.method.iteration.scope b/data/fixtures/scopes/go/type/type.argument.formal.method.iteration.scope new file mode 100644 index 0000000000..a86e6ecf9b --- /dev/null +++ b/data/fixtures/scopes/go/type/type.argument.formal.method.iteration.scope @@ -0,0 +1,13 @@ +func (f Foo) bar(aaa int, bbb string) {} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:40 + >----------------------------------------< +0| func (f Foo) bar(aaa int, bbb string) {} + + +[#2 Content] = +[#2 Domain] = 0:17-0:36 + >-------------------< +0| func (f Foo) bar(aaa int, bbb string) {} diff --git a/data/fixtures/scopes/go/type/type.argument.formal.method.scope b/data/fixtures/scopes/go/type/type.argument.formal.method.scope new file mode 100644 index 0000000000..35e1edc541 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.argument.formal.method.scope @@ -0,0 +1,39 @@ +func (f Foo) bar(aaa int) {} +--- + +[#1 Content] = 0:8-0:11 + >---< +0| func (f Foo) bar(aaa int) {} + +[#1 Removal] = 0:7-0:11 + >----< +0| func (f Foo) bar(aaa int) {} + +[#1 Leading delimiter] = 0:7-0:8 + >-< +0| func (f Foo) bar(aaa int) {} + +[#1 Domain] = 0:6-0:11 + >-----< +0| func (f Foo) bar(aaa int) {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:21-0:24 + >---< +0| func (f Foo) bar(aaa int) {} + +[#2 Removal] = 0:20-0:24 + >----< +0| func (f Foo) bar(aaa int) {} + +[#2 Leading delimiter] = 0:20-0:21 + >-< +0| func (f Foo) bar(aaa int) {} + +[#2 Domain] = 0:17-0:24 + >-------< +0| func (f Foo) bar(aaa int) {} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.argument.formal.scope b/data/fixtures/scopes/go/type/type.argument.formal.scope new file mode 100644 index 0000000000..b9950be308 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.argument.formal.scope @@ -0,0 +1,20 @@ +func foo(aaa int) {} +--- + +[Content] = 0:13-0:16 + >---< +0| func foo(aaa int) {} + +[Removal] = 0:12-0:16 + >----< +0| func foo(aaa int) {} + +[Leading delimiter] = 0:12-0:13 + >-< +0| func foo(aaa int) {} + +[Domain] = 0:9-0:16 + >-------< +0| func foo(aaa int) {} + +[Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 062f6e53f7..df80c0a8a3 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -464,6 +464,13 @@ (#child-range! @argumentList 1 -2) ) @argumentList.domain @argumentOrParameter.iteration.domain +(_ + parameters: (parameter_list + "(" @name.iteration.start.endOf @type.iteration.start.endOf + ")" @name.iteration.end.startOf @type.iteration.end.startOf + ) +) + ;;!! foo( ) ;;! ^ (_ @@ -475,6 +482,12 @@ (#child-range! @argumentList 1 -2) ) @argumentList.domain @argumentOrParameter.iteration.domain +;;!! func foo(aaa int) {} +(parameter_declaration + name: (_) @name + type: (_) @type +) @_.domain + ;;!! var foo int = 0 ;;! ^^^ ;;! ^^^ From 3b38281fd7236f58bcd7df2969f1075f566c5152 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 16:58:30 +0100 Subject: [PATCH 12/17] type --- data/fixtures/scopes/go/type/type.alias.scope | 10 +++++ .../go/type/type.typeArgument.iteration.scope | 13 ++++++ .../scopes/go/type/type.typeArgument.scope | 45 +++++++++++++++++++ .../scopes/go/value/value.typeAlias.scope | 20 +++++++++ packages/common/src/scopeSupportFacets/go.ts | 2 +- queries/go.scm | 25 +++++++++++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 data/fixtures/scopes/go/type/type.alias.scope create mode 100644 data/fixtures/scopes/go/type/type.typeArgument.iteration.scope create mode 100644 data/fixtures/scopes/go/type/type.typeArgument.scope create mode 100644 data/fixtures/scopes/go/value/value.typeAlias.scope diff --git a/data/fixtures/scopes/go/type/type.alias.scope b/data/fixtures/scopes/go/type/type.alias.scope new file mode 100644 index 0000000000..708ceef5d0 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.alias.scope @@ -0,0 +1,10 @@ +type Foo = Bar +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:14 + >--------------< +0| type Foo = Bar + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/type/type.typeArgument.iteration.scope b/data/fixtures/scopes/go/type/type.typeArgument.iteration.scope new file mode 100644 index 0000000000..821fe1b1b4 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.typeArgument.iteration.scope @@ -0,0 +1,13 @@ +var foo Bar[int, string] +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:24 + >------------------------< +0| var foo Bar[int, string] + + +[#2 Content] = +[#2 Domain] = 0:12-0:23 + >-----------< +0| var foo Bar[int, string] diff --git a/data/fixtures/scopes/go/type/type.typeArgument.scope b/data/fixtures/scopes/go/type/type.typeArgument.scope new file mode 100644 index 0000000000..d16d866169 --- /dev/null +++ b/data/fixtures/scopes/go/type/type.typeArgument.scope @@ -0,0 +1,45 @@ +var foo Bar[int, string] +--- + +[#1 Content] = 0:8-0:24 + >----------------< +0| var foo Bar[int, string] + +[#1 Removal] = 0:7-0:24 + >-----------------< +0| var foo Bar[int, string] + +[#1 Leading delimiter] = 0:7-0:8 + >-< +0| var foo Bar[int, string] + +[#1 Domain] = 0:0-0:24 + >------------------------< +0| var foo Bar[int, string] + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 0:12-0:15 + >---< +0| var foo Bar[int, string] + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Domain] = 0:17-0:23 + >------< +0| var foo Bar[int, string] + +[#3 Removal] = 0:16-0:23 + >-------< +0| var foo Bar[int, string] + +[#3 Leading delimiter] = 0:16-0:17 + >-< +0| var foo Bar[int, string] + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/value/value.typeAlias.scope b/data/fixtures/scopes/go/value/value.typeAlias.scope new file mode 100644 index 0000000000..a6264cfd05 --- /dev/null +++ b/data/fixtures/scopes/go/value/value.typeAlias.scope @@ -0,0 +1,20 @@ +type Foo = Bar +--- + +[Content] = 0:11-0:14 + >---< +0| type Foo = Bar + +[Removal] = 0:8-0:14 + >------< +0| type Foo = Bar + +[Leading delimiter] = 0:8-0:11 + >---< +0| type Foo = Bar + +[Domain] = 0:0-0:14 + >--------------< +0| type Foo = Bar + +[Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/go.ts b/packages/common/src/scopeSupportFacets/go.ts index 741c6c9f8a..335c004ea9 100644 --- a/packages/common/src/scopeSupportFacets/go.ts +++ b/packages/common/src/scopeSupportFacets/go.ts @@ -149,7 +149,6 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "type.interface": supported, "type.field.class": supported, "type.alias": supported, - "type.cast": supported, "type.typeArgument": supported, "type.typeArgument.iteration": supported, "type.iteration.block": supported, @@ -312,6 +311,7 @@ export const goScopeSupport: LanguageScopeSupportFacetMap = { "value.variable.pattern": notApplicable, "value.return.lambda": notApplicable, "type.foreach": notApplicable, + "type.cast": notApplicable, regularExpression: notApplicable, selector: notApplicable, unit: notApplicable, diff --git a/queries/go.scm b/queries/go.scm index df80c0a8a3..d141504fbf 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -384,6 +384,31 @@ (qualified_type) ] @type +;;!! type Foo = Bar +(type_declaration + (type_alias + name: (_) @name @value.leading.endOf + type: (_) @value + ) +) @type @_.domain + +;;!! var foo Bar[int, string] +;;! ^^^ ^^^^^^ +(generic_type + (type_arguments + (_) @type + ) +) + +;;!! var foo Bar[int, string] +;;! ^^^^^^^^^^^ +(generic_type + (type_arguments + "[" @type.iteration.start.endOf + "]" @type.iteration.end.startOf + ) +) + (function_declaration result: (_) @type ) @_.domain From a172f8dd05f125f980a28c3945dafa23f075b1df Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 17:18:49 +0100 Subject: [PATCH 13/17] branch --- .../scopes/go/branch/branch.switchCase.scope | 44 +++++++++++++++++++ .../go/condition/condition.switchCase.scope | 42 ++++++++++++++++++ .../queryPredicateOperators.ts | 30 +++++++------ queries/go.scm | 17 +++++-- 4 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 data/fixtures/scopes/go/branch/branch.switchCase.scope create mode 100644 data/fixtures/scopes/go/condition/condition.switchCase.scope diff --git a/data/fixtures/scopes/go/branch/branch.switchCase.scope b/data/fixtures/scopes/go/branch/branch.switchCase.scope new file mode 100644 index 0000000000..2573c6a39a --- /dev/null +++ b/data/fixtures/scopes/go/branch/branch.switchCase.scope @@ -0,0 +1,44 @@ +switch (foo) { + case 0: + break + default: {} +} +--- + +[#1 Content] = +[#1 Domain] = 1:4-2:13 + >------- +1| case 0: +2| break + -------------< + +[#1 Removal] = 1:0-3:0 + >----------- +1| case 0: +2| break +3| default: {} + < + +[#1 Leading delimiter] = 1:0-1:4 + >----< +1| case 0: + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 3:4-3:15 + >-----------< +3| default: {} + +[#2 Removal] = 3:0-4:0 + >--------------- +3| default: {} +4| } + < + +[#2 Leading delimiter] = 3:0-3:4 + >----< +3| default: {} + +[#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/go/condition/condition.switchCase.scope b/data/fixtures/scopes/go/condition/condition.switchCase.scope new file mode 100644 index 0000000000..12a5a3984c --- /dev/null +++ b/data/fixtures/scopes/go/condition/condition.switchCase.scope @@ -0,0 +1,42 @@ +switch (foo) { + case 0: break + case 1, 2: break +} +--- + +[#1 Content] = 1:9-1:10 + >-< +1| case 0: break + +[#1 Removal] = 1:8-1:10 + >--< +1| case 0: break + +[#1 Leading delimiter] = 1:8-1:9 + >-< +1| case 0: break + +[#1 Domain] = 1:4-1:17 + >-------------< +1| case 0: break + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 2:9-2:13 + >----< +2| case 1, 2: break + +[#2 Removal] = 2:8-2:13 + >-----< +2| case 1, 2: break + +[#2 Leading delimiter] = 2:8-2:9 + >-< +2| case 1, 2: break + +[#2 Domain] = 2:4-2:20 + >----------------< +2| case 1, 2: break + +[#2 Insertion delimiter] = " " diff --git a/packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts b/packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts index a1678b4378..d2d54ffe3e 100644 --- a/packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts +++ b/packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts @@ -286,21 +286,23 @@ class GrowToNamedSiblings extends QueryPredicateOperator { */ class TrimEnd extends QueryPredicateOperator { name = "trim-end!" as const; - schema = z.tuple([q.node]); - - run(capture: MutableQueryCapture) { - const { document, range } = capture; - const text = getNode(capture).text; - const whitespaceLength = text.length - text.trimEnd().length; + schema = z.tuple([q.node]).rest(q.node); - if (whitespaceLength > 0) { - setRange( - capture, - new Range( - range.start, - adjustPosition(document, range.end, -whitespaceLength), - ), - ); + run(...captures: MutableQueryCapture[]) { + for (const capture of captures) { + const { document, range } = capture; + const text = getNode(capture).text; + const whitespaceLength = text.length - text.trimEnd().length; + + if (whitespaceLength > 0) { + setRange( + capture, + new Range( + range.start, + adjustPosition(document, range.end, -whitespaceLength), + ), + ); + } } return true; diff --git a/queries/go.scm b/queries/go.scm index d141504fbf..8da6bd9da6 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -286,11 +286,20 @@ ( [ + ;;!! default: (default_case) - (expression_case) - (type_case) - ] @branch - (#trim-end! @branch) + + ;;!! case 0: + (expression_case + value: (_) @condition + ) + + ;;!! case int: + (type_case + type: (_) @condition + ) + ] @branch @condition.domain + (#trim-end! @branch @condition.domain) (#insertion-delimiter! @branch "\n") ) From 0c1bcae871b6b7de1a550bf168a253723db633f0 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 17:56:02 +0100 Subject: [PATCH 14/17] collection it them --- .../collectionItem.unenclosed.iteration.scope | 19 ++++ .../collectionItem.unenclosed.multiLine.scope | 90 ++++++++++++++++ ...collectionItem.unenclosed.singleLine.scope | 85 +++++++++++++++ .../go/interior/interior.switchCase.scope | 100 ++++++++++++++++++ queries/go.scm | 41 +++++++ 5 files changed, 335 insertions(+) create mode 100644 data/fixtures/scopes/go/collectionItem.unenclosed.iteration.scope create mode 100644 data/fixtures/scopes/go/collectionItem.unenclosed.multiLine.scope create mode 100644 data/fixtures/scopes/go/collectionItem.unenclosed.singleLine.scope create mode 100644 data/fixtures/scopes/go/interior/interior.switchCase.scope diff --git a/data/fixtures/scopes/go/collectionItem.unenclosed.iteration.scope b/data/fixtures/scopes/go/collectionItem.unenclosed.iteration.scope new file mode 100644 index 0000000000..dfd6e14f6c --- /dev/null +++ b/data/fixtures/scopes/go/collectionItem.unenclosed.iteration.scope @@ -0,0 +1,19 @@ +foo, bar := 1, 2 +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:8 + >--------< +0| foo, bar := 1, 2 + + +[#2 Content] = +[#2 Domain] = 0:0-0:16 + >----------------< +0| foo, bar := 1, 2 + + +[#3 Content] = +[#3 Domain] = 0:12-0:16 + >----< +0| foo, bar := 1, 2 diff --git a/data/fixtures/scopes/go/collectionItem.unenclosed.multiLine.scope b/data/fixtures/scopes/go/collectionItem.unenclosed.multiLine.scope new file mode 100644 index 0000000000..0bb003ce00 --- /dev/null +++ b/data/fixtures/scopes/go/collectionItem.unenclosed.multiLine.scope @@ -0,0 +1,90 @@ +foo, + baz := 1, 2 +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:3 + >---< +0| foo, + +[#1 Removal] = 0:0-1:4 + >---- +0| foo, +1| baz := 1, 2 + ----< + +[#1 Trailing delimiter] = 0:3-1:4 + >- +0| foo, +1| baz := 1, 2 + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 1:4-1:7 + >---< +1| baz := 1, 2 + +[#2 Removal] = 0:3-1:7 + >- +0| foo, +1| baz := 1, 2 + -------< + +[#2 Leading delimiter] = 0:3-1:4 + >- +0| foo, +1| baz := 1, 2 + ----< + +[#2 Insertion delimiter] = ",\n" + + +[#3 Content] = +[#3 Domain] = 1:4-1:12 + >--------< +1| baz := 1, 2 + +[#3 Removal] = 1:4-1:14 + >----------< +1| baz := 1, 2 + +[#3 Trailing delimiter] = 1:12-1:14 + >--< +1| baz := 1, 2 + +[#3 Insertion delimiter] = ", " + + +[#4 Content] = +[#4 Domain] = 1:11-1:12 + >-< +1| baz := 1, 2 + +[#4 Removal] = 1:11-1:14 + >---< +1| baz := 1, 2 + +[#4 Trailing delimiter] = 1:12-1:14 + >--< +1| baz := 1, 2 + +[#4 Insertion delimiter] = ", " + + +[#5 Content] = +[#5 Domain] = 1:14-1:15 + >-< +1| baz := 1, 2 + +[#5 Removal] = 1:12-1:15 + >---< +1| baz := 1, 2 + +[#5 Leading delimiter] = 1:12-1:14 + >--< +1| baz := 1, 2 + +[#5 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/collectionItem.unenclosed.singleLine.scope b/data/fixtures/scopes/go/collectionItem.unenclosed.singleLine.scope new file mode 100644 index 0000000000..966939e494 --- /dev/null +++ b/data/fixtures/scopes/go/collectionItem.unenclosed.singleLine.scope @@ -0,0 +1,85 @@ +foo, bar := 1, 2 +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:3 + >---< +0| foo, bar := 1, 2 + +[#1 Removal] = 0:0-0:5 + >-----< +0| foo, bar := 1, 2 + +[#1 Trailing delimiter] = 0:3-0:5 + >--< +0| foo, bar := 1, 2 + +[#1 Insertion delimiter] = ", " + + +[#2 Content] = +[#2 Domain] = 0:5-0:8 + >---< +0| foo, bar := 1, 2 + +[#2 Removal] = 0:3-0:8 + >-----< +0| foo, bar := 1, 2 + +[#2 Leading delimiter] = 0:3-0:5 + >--< +0| foo, bar := 1, 2 + +[#2 Insertion delimiter] = ", " + + +[#3 Content] = +[#3 Domain] = 0:5-0:13 + >--------< +0| foo, bar := 1, 2 + +[#3 Removal] = 0:5-0:15 + >----------< +0| foo, bar := 1, 2 + +[#3 Leading delimiter] = 0:3-0:5 + >--< +0| foo, bar := 1, 2 + +[#3 Trailing delimiter] = 0:13-0:15 + >--< +0| foo, bar := 1, 2 + +[#3 Insertion delimiter] = ", " + + +[#4 Content] = +[#4 Domain] = 0:12-0:13 + >-< +0| foo, bar := 1, 2 + +[#4 Removal] = 0:12-0:15 + >---< +0| foo, bar := 1, 2 + +[#4 Trailing delimiter] = 0:13-0:15 + >--< +0| foo, bar := 1, 2 + +[#4 Insertion delimiter] = ", " + + +[#5 Content] = +[#5 Domain] = 0:15-0:16 + >-< +0| foo, bar := 1, 2 + +[#5 Removal] = 0:13-0:16 + >---< +0| foo, bar := 1, 2 + +[#5 Leading delimiter] = 0:13-0:15 + >--< +0| foo, bar := 1, 2 + +[#5 Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/go/interior/interior.switchCase.scope b/data/fixtures/scopes/go/interior/interior.switchCase.scope new file mode 100644 index 0000000000..52039fb2b3 --- /dev/null +++ b/data/fixtures/scopes/go/interior/interior.switchCase.scope @@ -0,0 +1,100 @@ +switch foo { + case 0: + bar + break + case 1: { + break + } + default: + break +} +--- + +[#1 Content] = 1:4-8:13 + >------- +1| case 0: +2| bar +3| break +4| case 1: { +5| break +6| } +7| default: +8| break + -------------< + +[#1 Removal] = +[#1 Domain] = 0:12-9:0 + > +0| switch foo { +1| case 0: +2| bar +3| break +4| case 1: { +5| break +6| } +7| default: +8| break +9| } + < + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 2:8-2:11 + >---< +2| bar + +[#2 Removal] = +[#2 Domain] = 1:11-2:11 + > +1| case 0: +2| bar + -----------< + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 2:8-3:13 + >--- +2| bar +3| break + -------------< + +[#3 Removal] = +[#3 Domain] = 1:11-3:13 + > +1| case 0: +2| bar +3| break + -------------< + +[#3 Insertion delimiter] = " " + + +[#4 Content] = 5:8-5:13 + >-----< +5| break + +[#4 Removal] = +[#4 Domain] = 4:13-6:4 + > +4| case 1: { +5| break +6| } + ----< + +[#4 Insertion delimiter] = " " + + +[#5 Content] = 8:8-8:13 + >-----< +8| break + +[#5 Removal] = +[#5 Domain] = 7:12-8:13 + > +7| default: +8| break + -------------< + +[#5 Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 8da6bd9da6..77b427bcb2 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -303,6 +303,32 @@ (#insertion-delimiter! @branch "\n") ) +;; The parent object has trailing whitespace that we want to exclude. +;; Our trim predicate can't operate on positions only ranges. +(_ + [ + "case" + "default" + ] + ":" @interior.start.endOf + . + (_) @_dummy + (_) @interior.end.endOf + . + (#not-type? @_dummy block) +) +(_ + [ + "case" + "default" + ] + ":" @interior.start.endOf + . + (_) @interior.end.endOf + . + (#not-type? @interior.end.endOf block) +) + ;;!! switch foo {} (expression_switch_statement value: (_) @value @@ -461,6 +487,21 @@ ) ) @_.domain +;;!! foo, bar := 1, 2 +;;! ^^^ ^^^ ^ ^ +( + (expression_list + (_)? @collectionItem.leading.endOf + . + (_) @collectionItem + . + (_)? @collectionItem.trailing.startOf + ) @_dummy + (#single-or-multi-line-delimiter! @collectionItem @_dummy ", " ",\n") +) + +(expression_list) @collectionItem.iteration + ;;!! func add(x int, y int) int {} ( (parameter_list From cd28363f4ad1aeffe26c629f0db36bcf93ce10b6 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 18:10:53 +0100 Subject: [PATCH 15/17] Update listen map --- data/fixtures/scopes/go/list.scope | 4 +- data/fixtures/scopes/go/map.scope | 8 +- queries/go.scm | 151 ++--------------------------- 3 files changed, 15 insertions(+), 148 deletions(-) diff --git a/data/fixtures/scopes/go/list.scope b/data/fixtures/scopes/go/list.scope index 3106e513ff..03b5fd3cbc 100644 --- a/data/fixtures/scopes/go/list.scope +++ b/data/fixtures/scopes/go/list.scope @@ -3,8 +3,8 @@ [Content] = [Removal] = -[Domain] = 0:0-0:15 - >---------------< +[Domain] = 0:5-0:15 + >----------< 0| []int{aaa, bbb} [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/map.scope b/data/fixtures/scopes/go/map.scope index 488d5fbb5b..bfb614d399 100644 --- a/data/fixtures/scopes/go/map.scope +++ b/data/fixtures/scopes/go/map.scope @@ -1,10 +1,10 @@ -map[string]int{"aaa": 1, "bbb": 2} +map[string]int{"aaa": 0, "bbb": 1} --- [Content] = [Removal] = -[Domain] = 0:0-0:34 - >----------------------------------< -0| map[string]int{"aaa": 1, "bbb": 2} +[Domain] = 0:14-0:34 + >--------------------< +0| map[string]int{"aaa": 0, "bbb": 1} [Insertion delimiter] = " " diff --git a/queries/go.scm b/queries/go.scm index 77b427bcb2..06cd820e3a 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -116,153 +116,20 @@ type: (_) @type ) @statement @_.domain -;; What should map and list refer to in Go programs? -;; -;; The obvious answer is that map should refer to map and struct composite literals, -;; and that list should refer to slice and array composite literals. -;; -;; There are two problems with this answer. -;; -;; * The type of a composite literal is a semantic, not a syntactic property of a program. -;; - What is the type of T{1: 2}? It could be array, map, or slice. -;; - What about T{a: 1}? It could be map or struct. -;; - What about T{1, 2}? It could be struct, array, or slice. -;; Cursorless only has syntactic information available to it. -;; -;; * The user might not know the type either. With a named type, the type definition might be far away. -;; Or it might just be offscreen. Either way, the user needs to be able to make a decision about -;; what scope to use using only locally available, syntactic information. -;; Note that this also means that has-a predicates work better than has-no predicates. -;; The user can locally confirm that there is a keyed element. -;; She cannot confirm locally that there is no keyed element; it might just not be visible. -;; -;; Combining all these constraints suggests the following simple rules: -;; -;; * If there is a keyed element present, then it is a map. -;; * If there is a non-keyed element present, then it is a list. -;; * If there are both or neither, then it is both a map and a list. -;; -;; Conveniently, this is also simple to implement. -;; -;; This guarantees that a user always knows how to refer to any composite literal. -;; There are cases in which being overgenerous in matching is not ideal, -;; but they are rarer, so let's optimize for the common case. -;; Mixed keyed and non-keyed elements are also rare in practice. -;; The main ambiguity is with {}, but there's little we can do about that. -;; -;; Go users also expect that the map and list scopes will include the type definition, -;; as well as any & before the type. (Strictly speaking it is not part of the literal, -;; but that's not how most humans think about it.) -;; -;; If you are considering changing the map and list scopes, take a look at the examples in -;; data/playground/go/maps_and_lists.go, which cover a fairly wide variety of cases. - -;; maps - -;; &T{a: 1} -(unary_expression - operator: "&" - (composite_literal - body: (literal_value - (keyed_element) - ) - ) -) @map - -;; T{a: 1} -( - (composite_literal - body: (literal_value - (keyed_element) - ) - ) @map - (#not-parent-type? @map unary_expression) -) - -;; {a: 1} -( - (literal_value +;;!! T{a: 1} +;;! ^^^^^^ +(composite_literal + body: (literal_value (keyed_element) ) @map - (#not-parent-type? @map composite_literal) ) -;; lists - -;; &T{1} -(unary_expression - operator: "&" - (composite_literal - body: (literal_value - (literal_element) - ) - ) -) @list - -;; T{1} -( - (composite_literal - body: (literal_value - (literal_element) - ) - ) @list - (#not-parent-type? @list unary_expression) -) - -;; {1} -( - (literal_value +;;!! T{1, 2} +;;! ^^^^^^ +(composite_literal + body: (literal_value (literal_element) ) @list - (#not-parent-type? @list composite_literal) -) - -;; empty composite literals - -;; &T{} -(unary_expression - operator: "&" - (composite_literal - body: (literal_value - . - "{" - . - (comment)* - . - "}" - . - ) - ) -) @list @map - -;; T{} -( - (composite_literal - body: (literal_value - . - "{" - . - (comment)* - . - "}" - . - ) - ) @list @map - (#not-parent-type? @list unary_expression) -) - -;; {} -( - (literal_value - . - "{" - . - (comment)* - . - "}" - . - ) @list @map - (#not-parent-type? @list composite_literal) ) ;; Functions @@ -303,7 +170,7 @@ (#insertion-delimiter! @branch "\n") ) -;; The parent object has trailing whitespace that we want to exclude. +;; The parent object has trailing whitespace that we want to exclude. ;; Our trim predicate can't operate on positions only ranges. (_ [ From 3fdc030a81121107b8da92827505696832dbdfd1 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 18:17:03 +0100 Subject: [PATCH 16/17] Missing iteration scopes --- .../scopes/go/class.iteration.block.scope | 13 +++++++++++++ .../scopes/go/namedFunction.iteration.class.scope | 13 +++++++++++++ queries/go.scm | 15 +++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 data/fixtures/scopes/go/class.iteration.block.scope create mode 100644 data/fixtures/scopes/go/namedFunction.iteration.class.scope diff --git a/data/fixtures/scopes/go/class.iteration.block.scope b/data/fixtures/scopes/go/class.iteration.block.scope new file mode 100644 index 0000000000..eb1487158f --- /dev/null +++ b/data/fixtures/scopes/go/class.iteration.block.scope @@ -0,0 +1,13 @@ +func foo() { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:14 + >--------------< +0| func foo() { } + + +[#2 Content] = +[#2 Domain] = 0:12-0:13 + >-< +0| func foo() { } diff --git a/data/fixtures/scopes/go/namedFunction.iteration.class.scope b/data/fixtures/scopes/go/namedFunction.iteration.class.scope new file mode 100644 index 0000000000..90d5342216 --- /dev/null +++ b/data/fixtures/scopes/go/namedFunction.iteration.class.scope @@ -0,0 +1,13 @@ +type Foo struct { } +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:19 + >-------------------< +0| type Foo struct { } + + +[#2 Content] = +[#2 Domain] = 0:17-0:18 + >-< +0| type Foo struct { } diff --git a/queries/go.scm b/queries/go.scm index 06cd820e3a..feaca459a2 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -41,8 +41,8 @@ ) ( - (source_file) @class.iteration @statement.iteration @namedFunction.iteration - (#document-range! @class.iteration @statement.iteration @namedFunction.iteration) + (source_file) @statement.iteration @class.iteration @namedFunction.iteration + (#document-range! @statement.iteration @class.iteration @namedFunction.iteration) ) ( (source_file) @name.iteration @value.iteration @type.iteration @@ -50,8 +50,8 @@ ) (block - "{" @statement.iteration.start.endOf - "}" @statement.iteration.end.startOf + "{" @class.iteration.start.endOf @statement.iteration.start.endOf + "}" @class.iteration.end.startOf @statement.iteration.end.startOf ) (block "{" @name.iteration.start.endOf @value.iteration.start.endOf @type.iteration.start.endOf @@ -93,6 +93,13 @@ ) ) @class @type @name.domain +(struct_type + (field_declaration_list + "{" @namedFunction.iteration.start.endOf + "}" @namedFunction.iteration.end.startOf + ) +) + ;;!! type Foo interface {} (type_declaration (type_spec From 7ed79f5655a598bcc7a98bc74591e63bd6cad533 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 6 Jan 2026 18:34:52 +0100 Subject: [PATCH 17/17] Update map and list --- .../languages/go/changeEveryBranchSun.yml | 38 ------------------- .../recorded/languages/go/changeFunk.yml | 23 ----------- .../recorded/languages/go/changeListCap.yml | 29 -------------- .../recorded/languages/go/changeListCap2.yml | 29 -------------- .../recorded/languages/go/changeListOne.yml | 27 ------------- .../recorded/languages/go/changeListOne2.yml | 27 ------------- .../recorded/languages/go/changeListTrap.yml | 27 ------------- .../recorded/languages/go/changeListTrap2.yml | 27 ------------- .../recorded/languages/go/changeListTrap3.yml | 27 ------------- .../recorded/languages/go/changeListTrap4.yml | 27 ------------- .../recorded/languages/go/changeListTwo.yml | 27 ------------- .../recorded/languages/go/changeMapCap.yml | 29 -------------- .../recorded/languages/go/changeMapCap2.yml | 29 -------------- .../recorded/languages/go/changeMapOne2.yml | 27 ------------- .../recorded/languages/go/changeMapTrap.yml | 27 ------------- .../recorded/languages/go/changeMapTrap2.yml | 27 ------------- .../recorded/languages/go/changeMapTrap3.yml | 27 ------------- .../recorded/languages/go/changeMapTrap4.yml | 27 ------------- .../recorded/languages/go/takeList.yml | 23 ----------- .../recorded/languages/go/takeMap.yml | 23 ----------- .../recorded/languages/go/takeState.yml | 23 ----------- data/fixtures/scopes/go/list.scope | 8 ++-- data/fixtures/scopes/go/list2.scope | 10 +++++ data/fixtures/scopes/go/list3.scope | 10 +++++ data/fixtures/scopes/go/map.scope | 8 ++-- data/fixtures/scopes/go/map2.scope | 10 +++++ data/fixtures/scopes/go/map3.scope | 10 +++++ data/fixtures/scopes/go/namedFunction2.scope | 10 +++++ queries/go.scm | 21 +++++++++- 29 files changed, 78 insertions(+), 579 deletions(-) delete mode 100644 data/fixtures/recorded/languages/go/changeEveryBranchSun.yml delete mode 100644 data/fixtures/recorded/languages/go/changeFunk.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListCap.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListCap2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListOne.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListOne2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListTrap.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListTrap2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListTrap3.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListTrap4.yml delete mode 100644 data/fixtures/recorded/languages/go/changeListTwo.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapCap.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapCap2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapOne2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapTrap.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapTrap2.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapTrap3.yml delete mode 100644 data/fixtures/recorded/languages/go/changeMapTrap4.yml delete mode 100644 data/fixtures/recorded/languages/go/takeList.yml delete mode 100644 data/fixtures/recorded/languages/go/takeMap.yml delete mode 100644 data/fixtures/recorded/languages/go/takeState.yml create mode 100644 data/fixtures/scopes/go/list2.scope create mode 100644 data/fixtures/scopes/go/list3.scope create mode 100644 data/fixtures/scopes/go/map2.scope create mode 100644 data/fixtures/scopes/go/map3.scope create mode 100644 data/fixtures/scopes/go/namedFunction2.scope diff --git a/data/fixtures/recorded/languages/go/changeEveryBranchSun.yml b/data/fixtures/recorded/languages/go/changeEveryBranchSun.yml deleted file mode 100644 index 8eb778e9c1..0000000000 --- a/data/fixtures/recorded/languages/go/changeEveryBranchSun.yml +++ /dev/null @@ -1,38 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change every branch sun - action: - name: clearAndSetSelection - target: - type: primitive - mark: {type: decoratedSymbol, symbolColor: default, character: s} - modifiers: - - type: everyScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - switch x { - case 1: - default: - panic(x) - } - selections: - - anchor: {line: 0, character: 10} - active: {line: 0, character: 10} - marks: - default.s: - start: {line: 0, character: 0} - end: {line: 0, character: 6} -finalState: - documentContents: |- - switch x { - - - } - selections: - - anchor: {line: 1, character: 0} - active: {line: 1, character: 0} - - anchor: {line: 2, character: 0} - active: {line: 2, character: 0} diff --git a/data/fixtures/recorded/languages/go/changeFunk.yml b/data/fixtures/recorded/languages/go/changeFunk.yml deleted file mode 100644 index 0920f68c35..0000000000 --- a/data/fixtures/recorded/languages/go/changeFunk.yml +++ /dev/null @@ -1,23 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change funk - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: namedFunction} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = func() { /* body */ } - selections: - - anchor: {line: 0, character: 25} - active: {line: 0, character: 25} - marks: {} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListCap.yml b/data/fixtures/recorded/languages/go/changeListCap.yml deleted file mode 100644 index 107308a088..0000000000 --- a/data/fixtures/recorded/languages/go/changeListCap.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list cap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: c} - usePrePhraseSnapshot: true -initialState: - documentContents: | - _ = T{ /* comment */ } - selections: - - anchor: {line: 0, character: 22} - active: {line: 0, character: 22} - marks: - default.c: - start: {line: 0, character: 10} - end: {line: 0, character: 17} -finalState: - documentContents: | - _ = - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListCap2.yml b/data/fixtures/recorded/languages/go/changeListCap2.yml deleted file mode 100644 index 6d4f67b888..0000000000 --- a/data/fixtures/recorded/languages/go/changeListCap2.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list cap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: c} - usePrePhraseSnapshot: true -initialState: - documentContents: | - _ = &T{ /* comment */ } - selections: - - anchor: {line: 0, character: 23} - active: {line: 0, character: 23} - marks: - default.c: - start: {line: 0, character: 11} - end: {line: 0, character: 18} -finalState: - documentContents: | - _ = - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListOne.yml b/data/fixtures/recorded/languages/go/changeListOne.yml deleted file mode 100644 index d387bf0d35..0000000000 --- a/data/fixtures/recorded/languages/go/changeListOne.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list one - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: '1'} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = T{{1}} - selections: - - anchor: {line: 0, character: 10} - active: {line: 0, character: 10} - marks: - default.1: - start: {line: 0, character: 7} - end: {line: 0, character: 8} -finalState: - documentContents: _ = T{} - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} diff --git a/data/fixtures/recorded/languages/go/changeListOne2.yml b/data/fixtures/recorded/languages/go/changeListOne2.yml deleted file mode 100644 index a8a7e60bee..0000000000 --- a/data/fixtures/recorded/languages/go/changeListOne2.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list one - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: '1'} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = T{{1, 2: \"a\"}}" - selections: - - anchor: {line: 0, character: 18} - active: {line: 0, character: 18} - marks: - default.1: - start: {line: 0, character: 7} - end: {line: 0, character: 8} -finalState: - documentContents: _ = T{} - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} diff --git a/data/fixtures/recorded/languages/go/changeListTrap.yml b/data/fixtures/recorded/languages/go/changeListTrap.yml deleted file mode 100644 index 33d13e660a..0000000000 --- a/data/fixtures/recorded/languages/go/changeListTrap.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = &T{} - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: - default.t: - start: {line: 0, character: 5} - end: {line: 0, character: 6} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListTrap2.yml b/data/fixtures/recorded/languages/go/changeListTrap2.yml deleted file mode 100644 index 9a9238d55f..0000000000 --- a/data/fixtures/recorded/languages/go/changeListTrap2.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = &T{1} - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: - default.t: - start: {line: 0, character: 5} - end: {line: 0, character: 6} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListTrap3.yml b/data/fixtures/recorded/languages/go/changeListTrap3.yml deleted file mode 100644 index d9d4560c8e..0000000000 --- a/data/fixtures/recorded/languages/go/changeListTrap3.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = T{} - selections: - - anchor: {line: 0, character: 7} - active: {line: 0, character: 7} - marks: - default.t: - start: {line: 0, character: 4} - end: {line: 0, character: 5} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListTrap4.yml b/data/fixtures/recorded/languages/go/changeListTrap4.yml deleted file mode 100644 index f8683e405f..0000000000 --- a/data/fixtures/recorded/languages/go/changeListTrap4.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = T{1, 2: \"a\"}" - selections: - - anchor: {line: 0, character: 16} - active: {line: 0, character: 16} - marks: - default.t: - start: {line: 0, character: 4} - end: {line: 0, character: 5} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeListTwo.yml b/data/fixtures/recorded/languages/go/changeListTwo.yml deleted file mode 100644 index 2f762529e4..0000000000 --- a/data/fixtures/recorded/languages/go/changeListTwo.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change list two - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - mark: {type: decoratedSymbol, symbolColor: default, character: '2'} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = T{{2: \"a\"}}" - selections: - - anchor: {line: 0, character: 15} - active: {line: 0, character: 15} - marks: - default.2: - start: {line: 0, character: 7} - end: {line: 0, character: 8} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapCap.yml b/data/fixtures/recorded/languages/go/changeMapCap.yml deleted file mode 100644 index 0060d8f7bf..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapCap.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map cap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: c} - usePrePhraseSnapshot: true -initialState: - documentContents: | - _ = T{ /* comment */ } - selections: - - anchor: {line: 0, character: 22} - active: {line: 0, character: 22} - marks: - default.c: - start: {line: 0, character: 10} - end: {line: 0, character: 17} -finalState: - documentContents: | - _ = - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapCap2.yml b/data/fixtures/recorded/languages/go/changeMapCap2.yml deleted file mode 100644 index b8bfb79d1e..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapCap2.yml +++ /dev/null @@ -1,29 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map cap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: c} - usePrePhraseSnapshot: true -initialState: - documentContents: | - _ = &T{ /* comment */ } - selections: - - anchor: {line: 0, character: 23} - active: {line: 0, character: 23} - marks: - default.c: - start: {line: 0, character: 11} - end: {line: 0, character: 18} -finalState: - documentContents: | - _ = - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapOne2.yml b/data/fixtures/recorded/languages/go/changeMapOne2.yml deleted file mode 100644 index 55981f8619..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapOne2.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map one - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: '1'} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = T{{1, 2: \"a\"}}" - selections: - - anchor: {line: 0, character: 18} - active: {line: 0, character: 18} - marks: - default.1: - start: {line: 0, character: 7} - end: {line: 0, character: 8} -finalState: - documentContents: _ = T{} - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} diff --git a/data/fixtures/recorded/languages/go/changeMapTrap.yml b/data/fixtures/recorded/languages/go/changeMapTrap.yml deleted file mode 100644 index d67bc1a17d..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapTrap.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = &T{} - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: - default.t: - start: {line: 0, character: 5} - end: {line: 0, character: 6} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapTrap2.yml b/data/fixtures/recorded/languages/go/changeMapTrap2.yml deleted file mode 100644 index 2a231cf5b7..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapTrap2.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = &T{a: 1}" - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: - default.t: - start: {line: 0, character: 5} - end: {line: 0, character: 6} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapTrap3.yml b/data/fixtures/recorded/languages/go/changeMapTrap3.yml deleted file mode 100644 index c651dce1a7..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapTrap3.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: _ = T{} - selections: - - anchor: {line: 0, character: 7} - active: {line: 0, character: 7} - marks: - default.t: - start: {line: 0, character: 4} - end: {line: 0, character: 5} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/changeMapTrap4.yml b/data/fixtures/recorded/languages/go/changeMapTrap4.yml deleted file mode 100644 index 6b1c8a2a46..0000000000 --- a/data/fixtures/recorded/languages/go/changeMapTrap4.yml +++ /dev/null @@ -1,27 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: change map trap - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - mark: {type: decoratedSymbol, symbolColor: default, character: t} - usePrePhraseSnapshot: true -initialState: - documentContents: "_ = T{1, 2: \"a\"}" - selections: - - anchor: {line: 0, character: 16} - active: {line: 0, character: 16} - marks: - default.t: - start: {line: 0, character: 4} - end: {line: 0, character: 5} -finalState: - documentContents: "_ = " - selections: - - anchor: {line: 0, character: 4} - active: {line: 0, character: 4} diff --git a/data/fixtures/recorded/languages/go/takeList.yml b/data/fixtures/recorded/languages/go/takeList.yml deleted file mode 100644 index a6501f9ebc..0000000000 --- a/data/fixtures/recorded/languages/go/takeList.yml +++ /dev/null @@ -1,23 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: take list - action: - name: setSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: list} - usePrePhraseSnapshot: false -initialState: - documentContents: x := []string{"a", "b"} - selections: - - anchor: {line: 0, character: 16} - active: {line: 0, character: 16} - marks: {} -finalState: - documentContents: x := []string{"a", "b"} - selections: - - anchor: {line: 0, character: 5} - active: {line: 0, character: 23} diff --git a/data/fixtures/recorded/languages/go/takeMap.yml b/data/fixtures/recorded/languages/go/takeMap.yml deleted file mode 100644 index 0e2fbeca28..0000000000 --- a/data/fixtures/recorded/languages/go/takeMap.yml +++ /dev/null @@ -1,23 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: take map - action: - name: setSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: map} - usePrePhraseSnapshot: false -initialState: - documentContents: "x := map[string]string{\"a\": \"b\"}" - selections: - - anchor: {line: 0, character: 24} - active: {line: 0, character: 24} - marks: {} -finalState: - documentContents: "x := map[string]string{\"a\": \"b\"}" - selections: - - anchor: {line: 0, character: 5} - active: {line: 0, character: 32} diff --git a/data/fixtures/recorded/languages/go/takeState.yml b/data/fixtures/recorded/languages/go/takeState.yml deleted file mode 100644 index cb38cdde96..0000000000 --- a/data/fixtures/recorded/languages/go/takeState.yml +++ /dev/null @@ -1,23 +0,0 @@ -languageId: go -command: - version: 6 - spokenForm: take state - action: - name: setSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: statement} - usePrePhraseSnapshot: false -initialState: - documentContents: "type Hello struct {\n\tworld string\n}" - selections: - - anchor: {line: 1, character: 12} - active: {line: 1, character: 12} - marks: {} -finalState: - documentContents: "type Hello struct {\n\tworld string\n}" - selections: - - anchor: {line: 0, character: 0} - active: {line: 2, character: 1} diff --git a/data/fixtures/scopes/go/list.scope b/data/fixtures/scopes/go/list.scope index 03b5fd3cbc..3e4099ae86 100644 --- a/data/fixtures/scopes/go/list.scope +++ b/data/fixtures/scopes/go/list.scope @@ -1,10 +1,10 @@ -[]int{aaa, bbb} +T{aaa, bbb} --- [Content] = [Removal] = -[Domain] = 0:5-0:15 - >----------< -0| []int{aaa, bbb} +[Domain] = 0:1-0:11 + >----------< +0| T{aaa, bbb} [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/list2.scope b/data/fixtures/scopes/go/list2.scope new file mode 100644 index 0000000000..47d341f6d1 --- /dev/null +++ b/data/fixtures/scopes/go/list2.scope @@ -0,0 +1,10 @@ +T{aaa, bbb: 0} +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:14 + >-------------< +0| T{aaa, bbb: 0} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/list3.scope b/data/fixtures/scopes/go/list3.scope new file mode 100644 index 0000000000..c5ddfe935b --- /dev/null +++ b/data/fixtures/scopes/go/list3.scope @@ -0,0 +1,10 @@ +T{} +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:3 + >--< +0| T{} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/map.scope b/data/fixtures/scopes/go/map.scope index bfb614d399..55932a0b71 100644 --- a/data/fixtures/scopes/go/map.scope +++ b/data/fixtures/scopes/go/map.scope @@ -1,10 +1,10 @@ -map[string]int{"aaa": 0, "bbb": 1} +T{"aaa": 0, "bbb": 1} --- [Content] = [Removal] = -[Domain] = 0:14-0:34 - >--------------------< -0| map[string]int{"aaa": 0, "bbb": 1} +[Domain] = 0:1-0:21 + >--------------------< +0| T{"aaa": 0, "bbb": 1} [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/map2.scope b/data/fixtures/scopes/go/map2.scope new file mode 100644 index 0000000000..47d341f6d1 --- /dev/null +++ b/data/fixtures/scopes/go/map2.scope @@ -0,0 +1,10 @@ +T{aaa, bbb: 0} +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:14 + >-------------< +0| T{aaa, bbb: 0} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/map3.scope b/data/fixtures/scopes/go/map3.scope new file mode 100644 index 0000000000..c5ddfe935b --- /dev/null +++ b/data/fixtures/scopes/go/map3.scope @@ -0,0 +1,10 @@ +T{} +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:3 + >--< +0| T{} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/go/namedFunction2.scope b/data/fixtures/scopes/go/namedFunction2.scope new file mode 100644 index 0000000000..44b4235299 --- /dev/null +++ b/data/fixtures/scopes/go/namedFunction2.scope @@ -0,0 +1,10 @@ +foo = func() {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:15 + >---------------< +0| foo = func() {} + +[Insertion delimiter] = "\n\n" diff --git a/queries/go.scm b/queries/go.scm index feaca459a2..b713a8c86f 100644 --- a/queries/go.scm +++ b/queries/go.scm @@ -139,6 +139,16 @@ ) @list ) +;;!! T{} +;;! ^^ +(composite_literal + body: (literal_value + "{" + . + "}" + ) @list @map +) + ;; Functions ;; function declaration, generic function declaration, function stub @@ -155,9 +165,18 @@ name: (_) @name ) @namedFunction @statement @name.domain -;; func literal +;;!! func() {} (func_literal) @anonymousFunction +;;!! foo = func() {} +(assignment_statement + right: (expression_list + . + (func_literal) + . + ) +) @namedFunction + ( [ ;;!! default: