From 3cb55ab8b422bf3ad3fc08cecef79c3944f0045c Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Thu, 27 Nov 2025 16:55:03 +0800 Subject: [PATCH 01/11] Add first zig scope facet --- data/fixtures/scopes/zig/namedFunction.scope | 10 +++++++ data/playground/zig.zig | 3 ++ .../languageScopeSupport.ts | 2 ++ packages/common/src/scopeSupportFacets/zig.ts | 30 +++++++++++++++++++ queries/zig.scm | 14 +++++++++ 5 files changed, 59 insertions(+) create mode 100644 data/fixtures/scopes/zig/namedFunction.scope create mode 100644 data/playground/zig.zig create mode 100644 packages/common/src/scopeSupportFacets/zig.ts create mode 100644 queries/zig.scm diff --git a/data/fixtures/scopes/zig/namedFunction.scope b/data/fixtures/scopes/zig/namedFunction.scope new file mode 100644 index 0000000000..da391d1a06 --- /dev/null +++ b/data/fixtures/scopes/zig/namedFunction.scope @@ -0,0 +1,10 @@ +fn someFunk() void {} +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:21 + >---------------------< +0| fn someFunk() void {} + +[Insertion delimiter] = "\n\n" diff --git a/data/playground/zig.zig b/data/playground/zig.zig new file mode 100644 index 0000000000..29e9078871 --- /dev/null +++ b/data/playground/zig.zig @@ -0,0 +1,3 @@ +const bob = "bobert"; + +fn myFunk() void {} diff --git a/packages/common/src/scopeSupportFacets/languageScopeSupport.ts b/packages/common/src/scopeSupportFacets/languageScopeSupport.ts index d1cfc7879b..41cefba4aa 100644 --- a/packages/common/src/scopeSupportFacets/languageScopeSupport.ts +++ b/packages/common/src/scopeSupportFacets/languageScopeSupport.ts @@ -32,6 +32,7 @@ import { typescriptScopeSupport } from "./typescript"; import { typescriptreactScopeSupport } from "./typescriptreact"; import { xmlScopeSupport } from "./xml"; import { yamlScopeSupport } from "./yaml"; +import { zigScopeSupport } from "./zig"; /* eslint-disable @typescript-eslint/naming-convention */ @@ -69,4 +70,5 @@ export const languageScopeSupport: StringRecord = typescriptreact: typescriptreactScopeSupport, xml: xmlScopeSupport, yaml: yamlScopeSupport, + zig: zigScopeSupport, }; diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts new file mode 100644 index 0000000000..ed1284bac3 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -0,0 +1,30 @@ +import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; +import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; + +const { supported, notApplicable, unsupported } = ScopeSupportFacetLevel; + +export const zigScopeSupport: LanguageScopeSupportFacetMap = { + namedFunction: supported, + list: unsupported, + + "textFragment.string.singleLine": unsupported, + "textFragment.string.multiLine": unsupported, + "textFragment.comment.line": unsupported, + "textFragment.comment.block": unsupported, + + // SectionIf I Take Under + 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, + + // Notebook cell + notebookCell: notApplicable, + "interior.cell": notApplicable, +}; diff --git a/queries/zig.scm b/queries/zig.scm new file mode 100644 index 0000000000..450174fda1 --- /dev/null +++ b/queries/zig.scm @@ -0,0 +1,14 @@ +;;!! (fn foo() void {}) +(function_declaration + "fn" + name: (identifier) + (parameters + "(" + ")" + ) + type: (_) + body: (block + "{" + "}" + ) +) @namedFunction From 0abea276538389a7277c0ceee6c58c689524f911 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin <4970703+Antman261@users.noreply.github.com> Date: Thu, 27 Nov 2025 19:16:56 +0800 Subject: [PATCH 02/11] Update queries/zig.scm Co-authored-by: Andreas Arvidsson --- queries/zig.scm | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/queries/zig.scm b/queries/zig.scm index 450174fda1..11124aeafc 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -1,14 +1,2 @@ ;;!! (fn foo() void {}) -(function_declaration - "fn" - name: (identifier) - (parameters - "(" - ")" - ) - type: (_) - body: (block - "{" - "}" - ) -) @namedFunction +(function_declaration) @namedFunction From c2fe2deb811af77710db94a4ce3cef1aff3ca0b4 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin <4970703+Antman261@users.noreply.github.com> Date: Thu, 27 Nov 2025 19:17:44 +0800 Subject: [PATCH 03/11] Update packages/common/src/scopeSupportFacets/zig.ts Co-authored-by: Andreas Arvidsson --- packages/common/src/scopeSupportFacets/zig.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts index ed1284bac3..0a8d681f05 100644 --- a/packages/common/src/scopeSupportFacets/zig.ts +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -7,6 +7,8 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { namedFunction: supported, list: unsupported, +/* UNSUPPORTED */ + "textFragment.string.singleLine": unsupported, "textFragment.string.multiLine": unsupported, "textFragment.comment.line": unsupported, From d56874b4ae3c0ca3aa83e2dc649685319785950b Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin <4970703+Antman261@users.noreply.github.com> Date: Thu, 27 Nov 2025 19:17:57 +0800 Subject: [PATCH 04/11] Update packages/common/src/scopeSupportFacets/zig.ts Co-authored-by: Andreas Arvidsson --- packages/common/src/scopeSupportFacets/zig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts index 0a8d681f05..9e68840d68 100644 --- a/packages/common/src/scopeSupportFacets/zig.ts +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -14,7 +14,7 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { "textFragment.comment.line": unsupported, "textFragment.comment.block": unsupported, - // SectionIf I Take Under + // Section section: notApplicable, "section.iteration.document": notApplicable, "section.iteration.parent": notApplicable, From 1f32c82b7a1458560815941b6468db75085cf0b2 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin <4970703+Antman261@users.noreply.github.com> Date: Thu, 27 Nov 2025 19:20:33 +0800 Subject: [PATCH 05/11] Apply suggestion from @AndreasArvidsson Co-authored-by: Andreas Arvidsson --- packages/common/src/scopeSupportFacets/zig.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts index 9e68840d68..e9575cb666 100644 --- a/packages/common/src/scopeSupportFacets/zig.ts +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -14,6 +14,8 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { "textFragment.comment.line": unsupported, "textFragment.comment.block": unsupported, +/* NOT APPLICABLE */ + // Section section: notApplicable, "section.iteration.document": notApplicable, From 94a9433721852db78423bc305b6cf2961c4c3b9c Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Thu, 27 Nov 2025 23:29:38 +0800 Subject: [PATCH 06/11] add more scopes and scope tests --- .../zig/argument.actual.singleLine.scope | 10 +++ .../zig/argument.formal.singleLine.scope | 10 +++ .../zig/argumentList.actual.singleLine.scope | 10 +++ .../zig/argumentList.formal.singleLine.scope | 10 +++ data/fixtures/scopes/zig/functionCall.scope | 10 +++ data/fixtures/scopes/zig/functionCallee.scope | 10 +++ .../scopes/zig/statement.assignment.scope | 10 +++ packages/common/src/scopeSupportFacets/zig.ts | 78 +++++++++++++++++-- queries/zig.scm | 49 ++++++++++++ 9 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 data/fixtures/scopes/zig/argument.actual.singleLine.scope create mode 100644 data/fixtures/scopes/zig/argument.formal.singleLine.scope create mode 100644 data/fixtures/scopes/zig/argumentList.actual.singleLine.scope create mode 100644 data/fixtures/scopes/zig/argumentList.formal.singleLine.scope create mode 100644 data/fixtures/scopes/zig/functionCall.scope create mode 100644 data/fixtures/scopes/zig/functionCallee.scope create mode 100644 data/fixtures/scopes/zig/statement.assignment.scope diff --git a/data/fixtures/scopes/zig/argument.actual.singleLine.scope b/data/fixtures/scopes/zig/argument.actual.singleLine.scope new file mode 100644 index 0000000000..9fca368176 --- /dev/null +++ b/data/fixtures/scopes/zig/argument.actual.singleLine.scope @@ -0,0 +1,10 @@ +foo(aa); +--- + +[Content] = +[Removal] = +[Domain] = 0:4-0:6 + >--< +0| foo(aa); + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/argument.formal.singleLine.scope b/data/fixtures/scopes/zig/argument.formal.singleLine.scope new file mode 100644 index 0000000000..513cc99885 --- /dev/null +++ b/data/fixtures/scopes/zig/argument.formal.singleLine.scope @@ -0,0 +1,10 @@ +fn foo(arg: u8) void {} +--- + +[Content] = +[Removal] = +[Domain] = 0:7-0:14 + >-------< +0| fn foo(arg: u8) void {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope b/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope new file mode 100644 index 0000000000..87e925ee76 --- /dev/null +++ b/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope @@ -0,0 +1,10 @@ +foo(aaa, bbb); +--- + +[Content] = +[Removal] = +[Domain] = 0:4-0:12 + >--------< +0| foo(aaa, bbb); + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope b/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope new file mode 100644 index 0000000000..2ffdfcb5df --- /dev/null +++ b/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope @@ -0,0 +1,10 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- + +[Content] = +[Removal] = +[Domain] = 0:7-0:23 + >----------------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/functionCall.scope b/data/fixtures/scopes/zig/functionCall.scope new file mode 100644 index 0000000000..633f02ca5e --- /dev/null +++ b/data/fixtures/scopes/zig/functionCall.scope @@ -0,0 +1,10 @@ +foo(); +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:5 + >-----< +0| foo(); + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/functionCallee.scope b/data/fixtures/scopes/zig/functionCallee.scope new file mode 100644 index 0000000000..e2e112d6fd --- /dev/null +++ b/data/fixtures/scopes/zig/functionCallee.scope @@ -0,0 +1,10 @@ +foo(); +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:3 + >---< +0| foo(); + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/statement.assignment.scope b/data/fixtures/scopes/zig/statement.assignment.scope new file mode 100644 index 0000000000..60eb993e9e --- /dev/null +++ b/data/fixtures/scopes/zig/statement.assignment.scope @@ -0,0 +1,10 @@ +const foo = "hello"; +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:20 + >--------------------< +0| const foo = "hello"; + +[Insertion delimiter] = "\n" diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts index e9575cb666..3e6599c37a 100644 --- a/packages/common/src/scopeSupportFacets/zig.ts +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -5,16 +5,82 @@ const { supported, notApplicable, unsupported } = ScopeSupportFacetLevel; export const zigScopeSupport: LanguageScopeSupportFacetMap = { namedFunction: supported, + functionCall: supported, + functionCallee: supported, + "argument.formal.singleLine": supported, + "argument.actual.singleLine": supported, + "argumentList.formal.singleLine": supported, + "argumentList.actual.singleLine": supported, + "statement.assignment": supported, + + /* UNSUPPORTED */ + list: unsupported, -/* UNSUPPORTED */ + "statement.function": unsupported, + "statement.if": unsupported, + "statement.try": unsupported, + "statement.for": unsupported, + "statement.foreach": unsupported, + "statement.return": unsupported, + "statement.break": unsupported, + "statement.continue": unsupported, + + "argumentList.formal.empty": unsupported, + "argumentList.formal.multiLine": unsupported, + "argumentList.actual.empty": unsupported, + "argumentList.actual.multiLine": unsupported, + "argument.actual.multiLine": unsupported, + + "comment.line": unsupported, + "comment.block": unsupported, + + "branch.if": unsupported, + "branch.if.elif.else": unsupported, + "branch.if.else": unsupported, + "branch.if.iteration": unsupported, + "branch.try": unsupported, + "branch.try.iteration": unsupported, + "branch.switchCase": unsupported, + "branch.switchCase.iteration": unsupported, + + "condition.if": unsupported, + "condition.while": unsupported, + "condition.doWhile": unsupported, + "condition.for": unsupported, + "condition.ternary": unsupported, + "condition.switchCase": unsupported, + "condition.switchCase.iteration": unsupported, + + "name.assignment": unsupported, + "name.function": unsupported, + "name.argument.catch": unsupported, + "name.foreach": unsupported, + + "value.argument.formal": unsupported, + "value.argument.formal.iteration": unsupported, + "value.assignment": unsupported, + "value.variable": unsupported, + "value.foreach": unsupported, + "value.return": unsupported, + "value.switch": unsupported, + "value.iteration.block": unsupported, - "textFragment.string.singleLine": unsupported, - "textFragment.string.multiLine": unsupported, - "textFragment.comment.line": unsupported, - "textFragment.comment.block": unsupported, + "interior.class": unsupported, + "interior.function": unsupported, + // "interior.constructor": unsupported, + // "interior.method": unsupported, + "interior.if": unsupported, + // "interior.lambda": unsupported, + "interior.for": unsupported, + "interior.foreach": unsupported, + "interior.while": unsupported, + "interior.doWhile": unsupported, + "interior.switch": unsupported, + "interior.switchCase": unsupported, + "interior.try": unsupported, -/* NOT APPLICABLE */ + // /* NOT APPLICABLE */ // Section section: notApplicable, diff --git a/queries/zig.scm b/queries/zig.scm index 11124aeafc..860c4f41d5 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -1,2 +1,51 @@ ;;!! (fn foo() void {}) +;;! ^^^^^^^^^^^^^^^^ (function_declaration) @namedFunction + +;;!! (fn foo() void {}) +;;! ^^^^ +(function_declaration + (builtin_type) @type +) + +;;!! (fn foo(aa: u8, bb:u8) void {}) +(_ + (parameters + "(" @argumentList.removal.start.endOf + (parameter + (identifier) @name + ":" + (builtin_type) @type + ) @argumentOrParameter + ")" @argumentList.removal.end.startOf + ) @argumentList + (#child-range! @argumentList 1 -2) +) + +(call_expression + (identifier) @functionCallee + (arguments + "(" + (_)* @argumentOrParameter + ")" + ) @argumentList + (#child-range! @argumentList 1 -2) +) @functionCall + +(statement) @statement + +(variable_declaration + (identifier) @name + ":" + (_) @type + "=" + (_) @value + ";" +) @statement + +(variable_declaration + (identifier) @name + "=" + (_) @value + ";" +) @statement From 957ca9240618ffa46b35306bd2bf260fb1a99c6c Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Fri, 28 Nov 2025 11:42:40 +0800 Subject: [PATCH 07/11] wip: improving zig scm --- data/playground/zig.zig | 11 +++++++++-- queries/zig.scm | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/data/playground/zig.zig b/data/playground/zig.zig index 29e9078871..9a86925df6 100644 --- a/data/playground/zig.zig +++ b/data/playground/zig.zig @@ -1,3 +1,10 @@ -const bob = "bobert"; +const std = @import("std"); -fn myFunk() void {} +const bob: *const [6]u8 = "bobert"; +const b = "bobert"; +fn printNumber(num: u8, numTwo: u8, numThree: u8) void { + std.debug.print("%n", .{ num, numTwo, numThree }); +} +fn main() !void { + printNumber(3, 4, 20); +} diff --git a/queries/zig.scm b/queries/zig.scm index 860c4f41d5..813addcb20 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -1,22 +1,27 @@ -;;!! (fn foo() void {}) -;;! ^^^^^^^^^^^^^^^^ -(function_declaration) @namedFunction - -;;!! (fn foo() void {}) -;;! ^^^^ +;;!! fn foo() void {} +;;! ^^^^ +;;! ^^^^^^^^^^^^^^^^ (function_declaration (builtin_type) @type -) +) @namedFunction -;;!! (fn foo(aa: u8, bb:u8) void {}) +;;!! fn foo(aa: u8, bb:u8) void {} +;;! ^^^^^^^^^^^^^ argumentList +;;! ^^ name +;;! ^^ type +;;! ^^^^^^ argumentOrParameter (_ (parameters "(" @argumentList.removal.start.endOf + (_)? @_.leading.endOf + . (parameter (identifier) @name ":" (builtin_type) @type ) @argumentOrParameter + . + (_)? @_.trailing.startOf ")" @argumentList.removal.end.startOf ) @argumentList (#child-range! @argumentList 1 -2) From 15b273cc71e397e4cf31b805cc11f844e5d5dd11 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Fri, 28 Nov 2025 13:32:38 +0800 Subject: [PATCH 08/11] wip: improve Zig scm --- queries/zig.scm | 61 ++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/queries/zig.scm b/queries/zig.scm index 813addcb20..4dd54ac9f4 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -1,56 +1,61 @@ ;;!! fn foo() void {} -;;! ^^^^ -;;! ^^^^^^^^^^^^^^^^ +;;! ^^^ name +;;! ^^^^ type +;;! ^^^^^^^^^^^^^^^^ namedFunction (function_declaration - (builtin_type) @type -) @namedFunction + name: (_) @name + type: (_) @type +) @namedFunction @_.domain -;;!! fn foo(aa: u8, bb:u8) void {} +;;!! fn foo(aa: u8) void {} ;;! ^^^^^^^^^^^^^ argumentList ;;! ^^ name ;;! ^^ type -;;! ^^^^^^ argumentOrParameter -(_ +(function_declaration (parameters - "(" @argumentList.removal.start.endOf (_)? @_.leading.endOf . (parameter (identifier) @name ":" - (builtin_type) @type - ) @argumentOrParameter + type: (_) @type + ) @argumentOrParameter @_.domain . (_)? @_.trailing.startOf - ")" @argumentList.removal.end.startOf - ) @argumentList - (#child-range! @argumentList 1 -2) + ) ) +;;!! fn foo(aa: u8, bb:u8) void {} +;;! ^^^^^^^^^^^^^ argumentList +(function_declaration + (parameters) @argumentList + (#child-range! @argumentList 1 -2) +) @argumentList.domain + +;;!! foo(aa, bb); +;;! ^^^ functionCallee +;;! ^^^^^^ argumentList +;;! ^^ ^^ argumentOrParameter +;;! ----------- functionCall ^domain (call_expression - (identifier) @functionCallee + function: (_) @functionCallee (arguments - "(" (_)* @argumentOrParameter - ")" - ) @argumentList + ) @argumentList @_.domain (#child-range! @argumentList 1 -2) -) @functionCall +) @functionCall @_.domain (statement) @statement +;;!! const foo: *const [3]u8 = "bar"; +;;! ^^^ name +;;! ^^^^^^^^^^^^ type +;;! ^^^^^ value +;;! -------------------------------- statement ^domain (variable_declaration (identifier) @name - ":" - (_) @type - "=" - (_) @value - ";" -) @statement - -(variable_declaration - (identifier) @name + type: (_)? @type "=" (_) @value ";" -) @statement +) @statement @_.domain From 1c060d3e199099e6d36672f79b5064560c7e8b36 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Mon, 1 Dec 2025 22:35:45 +0800 Subject: [PATCH 09/11] Improve scm examples --- queries/zig.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/queries/zig.scm b/queries/zig.scm index 4dd54ac9f4..8e02ee6260 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -8,7 +8,7 @@ ) @namedFunction @_.domain ;;!! fn foo(aa: u8) void {} -;;! ^^^^^^^^^^^^^ argumentList +;;! ^^^^^^ argumentOrParameter ;;! ^^ name ;;! ^^ type (function_declaration @@ -27,6 +27,7 @@ ;;!! fn foo(aa: u8, bb:u8) void {} ;;! ^^^^^^^^^^^^^ argumentList +;;! ----------------------------- ^domain (function_declaration (parameters) @argumentList (#child-range! @argumentList 1 -2) From 69cd67bf791d0f60a3fbe3df3b7fcae09ffe4726 Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Mon, 1 Dec 2025 22:46:56 +0800 Subject: [PATCH 10/11] Update arg list test --- .../scopes/zig/argumentList.formal.singleLine.scope | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope b/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope index 2ffdfcb5df..4f2ffb899b 100644 --- a/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope +++ b/data/fixtures/scopes/zig/argumentList.formal.singleLine.scope @@ -2,9 +2,12 @@ fn foo(aaa: u8, bbb: u8) void {} --- [Content] = -[Removal] = -[Domain] = 0:7-0:23 +[Removal] = 0:7-0:23 >----------------< 0| fn foo(aaa: u8, bbb: u8) void {} +[Domain] = 0:0-0:32 + >--------------------------------< +0| fn foo(aaa: u8, bbb: u8) void {} + [Insertion delimiter] = " " From e03a4f6e71e5f4b508073b64484f7549e216debd Mon Sep 17 00:00:00 2001 From: Anthony Manning-Franklin Date: Tue, 2 Dec 2025 00:37:29 +0800 Subject: [PATCH 11/11] wip: add more scope tests --- .../zig/argument.actual.iteration.scope | 2 + .../zig/argument.actual.multiLine.scope | 5 ++ .../zig/argument.actual.singleLine.scope | 2 +- .../zig/argument.formal.iteration.scope | 10 +++ .../zig/argument.formal.multiLine.scope | 44 +++++++++++++ .../zig/argument.formal.singleLine.scope | 2 +- .../zig/argumentList.actual.empty.scope | 13 ++++ .../zig/argumentList.actual.multiLine.scope | 2 + .../zig/argumentList.actual.singleLine.scope | 7 ++- .../zig/argumentList.formal.empty.scope | 13 ++++ .../zig/argumentList.formal.multiLine.scope | 32 ++++++++++ data/fixtures/scopes/zig/functionCallee.scope | 11 ++-- .../scopes/zig/name.argument.formal.scope | 55 ++++++++++++++++ .../fixtures/scopes/zig/name.assignment.scope | 24 +++++++ data/fixtures/scopes/zig/name.function.scope | 17 +++++ .../zig/type.argument.formal.iteration.scope | 2 + .../scopes/zig/type.argument.formal.scope | 62 +++++++++++++++++++ data/fixtures/scopes/zig/type.return.scope | 62 +++++++++++++++++++ data/fixtures/scopes/zig/type.variable.scope | 24 +++++++ .../scopes/zig/value.assignment.scope | 20 ++++++ data/playground/zig.zig | 2 + packages/common/src/scopeSupportFacets/zig.ts | 42 +++++++++---- queries/zig.scm | 11 ++-- 23 files changed, 440 insertions(+), 24 deletions(-) create mode 100644 data/fixtures/scopes/zig/argument.actual.iteration.scope create mode 100644 data/fixtures/scopes/zig/argument.actual.multiLine.scope create mode 100644 data/fixtures/scopes/zig/argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/zig/argument.formal.multiLine.scope create mode 100644 data/fixtures/scopes/zig/argumentList.actual.empty.scope create mode 100644 data/fixtures/scopes/zig/argumentList.actual.multiLine.scope create mode 100644 data/fixtures/scopes/zig/argumentList.formal.empty.scope create mode 100644 data/fixtures/scopes/zig/argumentList.formal.multiLine.scope create mode 100644 data/fixtures/scopes/zig/name.argument.formal.scope create mode 100644 data/fixtures/scopes/zig/name.assignment.scope create mode 100644 data/fixtures/scopes/zig/name.function.scope create mode 100644 data/fixtures/scopes/zig/type.argument.formal.iteration.scope create mode 100644 data/fixtures/scopes/zig/type.argument.formal.scope create mode 100644 data/fixtures/scopes/zig/type.return.scope create mode 100644 data/fixtures/scopes/zig/type.variable.scope create mode 100644 data/fixtures/scopes/zig/value.assignment.scope diff --git a/data/fixtures/scopes/zig/argument.actual.iteration.scope b/data/fixtures/scopes/zig/argument.actual.iteration.scope new file mode 100644 index 0000000000..131575792b --- /dev/null +++ b/data/fixtures/scopes/zig/argument.actual.iteration.scope @@ -0,0 +1,2 @@ +foo(aaa, bbb); +--- diff --git a/data/fixtures/scopes/zig/argument.actual.multiLine.scope b/data/fixtures/scopes/zig/argument.actual.multiLine.scope new file mode 100644 index 0000000000..f5787791ec --- /dev/null +++ b/data/fixtures/scopes/zig/argument.actual.multiLine.scope @@ -0,0 +1,5 @@ +foo( + aaa, + bbb +); +--- diff --git a/data/fixtures/scopes/zig/argument.actual.singleLine.scope b/data/fixtures/scopes/zig/argument.actual.singleLine.scope index 9fca368176..6568e7a68c 100644 --- a/data/fixtures/scopes/zig/argument.actual.singleLine.scope +++ b/data/fixtures/scopes/zig/argument.actual.singleLine.scope @@ -1,4 +1,4 @@ -foo(aa); +foo(aaa, bbb); --- [Content] = diff --git a/data/fixtures/scopes/zig/argument.formal.iteration.scope b/data/fixtures/scopes/zig/argument.formal.iteration.scope new file mode 100644 index 0000000000..39b5001413 --- /dev/null +++ b/data/fixtures/scopes/zig/argument.formal.iteration.scope @@ -0,0 +1,10 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- + +[Content] = 0:7-0:23 + >----------------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[Domain] = 0:0-0:32 + >--------------------------------< +0| fn foo(aaa: u8, bbb: u8) void {} diff --git a/data/fixtures/scopes/zig/argument.formal.multiLine.scope b/data/fixtures/scopes/zig/argument.formal.multiLine.scope new file mode 100644 index 0000000000..1d5a0a7a7c --- /dev/null +++ b/data/fixtures/scopes/zig/argument.formal.multiLine.scope @@ -0,0 +1,44 @@ +fn foo( + aa: u8, + bb: u8, +) void {} +--- + +[#1 Content] = +[#1 Domain] = 1:4-1:10 + >------< +1| aa: u8, + +[#1 Removal] = 1:4-2:4 + >------- +1| aa: u8, +2| bb: u8, + ----< + +[#1 Trailing delimiter] = 1:10-2:4 + >- +1| aa: u8, +2| bb: u8, + ----< + +[#1 Insertion delimiter] = ",\n" + + +[#2 Content] = +[#2 Domain] = 2:4-2:10 + >------< +2| bb: u8, + +[#2 Removal] = 1:10-2:10 + >- +1| aa: u8, +2| bb: u8, + ----------< + +[#2 Leading delimiter] = 1:10-2:4 + >- +1| aa: u8, +2| bb: u8, + ----< + +[#2 Insertion delimiter] = ",\n" diff --git a/data/fixtures/scopes/zig/argument.formal.singleLine.scope b/data/fixtures/scopes/zig/argument.formal.singleLine.scope index 513cc99885..04edfa7086 100644 --- a/data/fixtures/scopes/zig/argument.formal.singleLine.scope +++ b/data/fixtures/scopes/zig/argument.formal.singleLine.scope @@ -7,4 +7,4 @@ fn foo(arg: u8) void {} >-------< 0| fn foo(arg: u8) void {} -[Insertion delimiter] = " " +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/zig/argumentList.actual.empty.scope b/data/fixtures/scopes/zig/argumentList.actual.empty.scope new file mode 100644 index 0000000000..7f62df58de --- /dev/null +++ b/data/fixtures/scopes/zig/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/zig/argumentList.actual.multiLine.scope b/data/fixtures/scopes/zig/argumentList.actual.multiLine.scope new file mode 100644 index 0000000000..131575792b --- /dev/null +++ b/data/fixtures/scopes/zig/argumentList.actual.multiLine.scope @@ -0,0 +1,2 @@ +foo(aaa, bbb); +--- diff --git a/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope b/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope index 87e925ee76..e11f994e9f 100644 --- a/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope +++ b/data/fixtures/scopes/zig/argumentList.actual.singleLine.scope @@ -2,9 +2,12 @@ foo(aaa, bbb); --- [Content] = -[Removal] = -[Domain] = 0:4-0:12 +[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/zig/argumentList.formal.empty.scope b/data/fixtures/scopes/zig/argumentList.formal.empty.scope new file mode 100644 index 0000000000..1f9b49ec0f --- /dev/null +++ b/data/fixtures/scopes/zig/argumentList.formal.empty.scope @@ -0,0 +1,13 @@ +fn foo() void {} +--- + +[Content] = +[Removal] = 0:7-0:7 + >< +0| fn foo() void {} + +[Domain] = 0:0-0:16 + >----------------< +0| fn foo() void {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/argumentList.formal.multiLine.scope b/data/fixtures/scopes/zig/argumentList.formal.multiLine.scope new file mode 100644 index 0000000000..5ef23675b0 --- /dev/null +++ b/data/fixtures/scopes/zig/argumentList.formal.multiLine.scope @@ -0,0 +1,32 @@ +foo( + aaa, + bbb +); +--- + +[Content] = 1:4-2:7 + >----- +1| aaa, +2| bbb + -------< + +[Removal] = 1:0-3:0 + >--------- +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] = " " diff --git a/data/fixtures/scopes/zig/functionCallee.scope b/data/fixtures/scopes/zig/functionCallee.scope index e2e112d6fd..66bd7c37f6 100644 --- a/data/fixtures/scopes/zig/functionCallee.scope +++ b/data/fixtures/scopes/zig/functionCallee.scope @@ -1,10 +1,13 @@ -foo(); +foo(aa, bb); --- [Content] = -[Removal] = -[Domain] = 0:0-0:3 +[Removal] = 0:0-0:3 >---< -0| foo(); +0| foo(aa, bb); + +[Domain] = 0:0-0:11 + >-----------< +0| foo(aa, bb); [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/name.argument.formal.scope b/data/fixtures/scopes/zig/name.argument.formal.scope new file mode 100644 index 0000000000..f042beeb11 --- /dev/null +++ b/data/fixtures/scopes/zig/name.argument.formal.scope @@ -0,0 +1,55 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- + +[#1 Content] = +[#1 Removal] = 0:3-0:6 + >---< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Leading delimiter] = 0:2-0:3 + >-< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:7-0:10 + >---< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Removal] = 0:7-0:16 + >---------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Trailing delimiter] = 0:10-0:16 + >------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Domain] = 0:7-0:14 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 0:16-0:19 + >---< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Removal] = 0:14-0:19 + >-----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Leading delimiter] = 0:14-0:16 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Domain] = 0:16-0:23 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/name.assignment.scope b/data/fixtures/scopes/zig/name.assignment.scope new file mode 100644 index 0000000000..cb6a3eab56 --- /dev/null +++ b/data/fixtures/scopes/zig/name.assignment.scope @@ -0,0 +1,24 @@ +const foo = "bar"; +--- + +[Content] = 0:6-0:9 + >---< +0| const foo = "bar"; + +[Removal] = 0:6-0:10 + >----< +0| const foo = "bar"; + +[Leading delimiter] = 0:5-0:6 + >-< +0| const foo = "bar"; + +[Trailing delimiter] = 0:9-0:10 + >-< +0| const foo = "bar"; + +[Domain] = 0:0-0:18 + >------------------< +0| const foo = "bar"; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/name.function.scope b/data/fixtures/scopes/zig/name.function.scope new file mode 100644 index 0000000000..cce2929c6d --- /dev/null +++ b/data/fixtures/scopes/zig/name.function.scope @@ -0,0 +1,17 @@ +fn foo() void {} +--- + +[Content] = +[Removal] = 0:3-0:6 + >---< +0| fn foo() void {} + +[Leading delimiter] = 0:2-0:3 + >-< +0| fn foo() void {} + +[Domain] = 0:0-0:16 + >----------------< +0| fn foo() void {} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/type.argument.formal.iteration.scope b/data/fixtures/scopes/zig/type.argument.formal.iteration.scope new file mode 100644 index 0000000000..571c7b2966 --- /dev/null +++ b/data/fixtures/scopes/zig/type.argument.formal.iteration.scope @@ -0,0 +1,2 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- diff --git a/data/fixtures/scopes/zig/type.argument.formal.scope b/data/fixtures/scopes/zig/type.argument.formal.scope new file mode 100644 index 0000000000..8a179c3571 --- /dev/null +++ b/data/fixtures/scopes/zig/type.argument.formal.scope @@ -0,0 +1,62 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- + +[#1 Content] = 0:25-0:29 + >----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Removal] = 0:25-0:30 + >-----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Leading delimiter] = 0:24-0:25 + >-< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Trailing delimiter] = 0:29-0:30 + >-< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:12-0:14 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Removal] = 0:12-0:16 + >----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Trailing delimiter] = 0:14-0:16 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Domain] = 0:7-0:14 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 0:21-0:23 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Removal] = 0:14-0:23 + >---------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Leading delimiter] = 0:14-0:21 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Domain] = 0:16-0:23 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/type.return.scope b/data/fixtures/scopes/zig/type.return.scope new file mode 100644 index 0000000000..8a179c3571 --- /dev/null +++ b/data/fixtures/scopes/zig/type.return.scope @@ -0,0 +1,62 @@ +fn foo(aaa: u8, bbb: u8) void {} +--- + +[#1 Content] = 0:25-0:29 + >----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Removal] = 0:25-0:30 + >-----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Leading delimiter] = 0:24-0:25 + >-< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Trailing delimiter] = 0:29-0:30 + >-< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Domain] = 0:0-0:32 + >--------------------------------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:12-0:14 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Removal] = 0:12-0:16 + >----< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Trailing delimiter] = 0:14-0:16 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Domain] = 0:7-0:14 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#2 Insertion delimiter] = " " + + +[#3 Content] = 0:21-0:23 + >--< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Removal] = 0:14-0:23 + >---------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Leading delimiter] = 0:14-0:21 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Domain] = 0:16-0:23 + >-------< +0| fn foo(aaa: u8, bbb: u8) void {} + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/type.variable.scope b/data/fixtures/scopes/zig/type.variable.scope new file mode 100644 index 0000000000..33ba156573 --- /dev/null +++ b/data/fixtures/scopes/zig/type.variable.scope @@ -0,0 +1,24 @@ +const foo: u8 = 0; +--- + +[Content] = 0:11-0:13 + >--< +0| const foo: u8 = 0; + +[Removal] = 0:11-0:14 + >---< +0| const foo: u8 = 0; + +[Leading delimiter] = 0:10-0:11 + >-< +0| const foo: u8 = 0; + +[Trailing delimiter] = 0:13-0:14 + >-< +0| const foo: u8 = 0; + +[Domain] = 0:0-0:18 + >------------------< +0| const foo: u8 = 0; + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/zig/value.assignment.scope b/data/fixtures/scopes/zig/value.assignment.scope new file mode 100644 index 0000000000..b679fbff3b --- /dev/null +++ b/data/fixtures/scopes/zig/value.assignment.scope @@ -0,0 +1,20 @@ +const foo = "bar"; +--- + +[Content] = 0:12-0:17 + >-----< +0| const foo = "bar"; + +[Removal] = 0:11-0:17 + >------< +0| const foo = "bar"; + +[Leading delimiter] = 0:11-0:12 + >-< +0| const foo = "bar"; + +[Domain] = 0:0-0:18 + >------------------< +0| const foo = "bar"; + +[Insertion delimiter] = " " diff --git a/data/playground/zig.zig b/data/playground/zig.zig index 9a86925df6..be68c8c3b7 100644 --- a/data/playground/zig.zig +++ b/data/playground/zig.zig @@ -5,6 +5,8 @@ const b = "bobert"; fn printNumber(num: u8, numTwo: u8, numThree: u8) void { std.debug.print("%n", .{ num, numTwo, numThree }); } +fn foo() void {} fn main() !void { printNumber(3, 4, 20); + foo(); } diff --git a/packages/common/src/scopeSupportFacets/zig.ts b/packages/common/src/scopeSupportFacets/zig.ts index 3e6599c37a..057a21933d 100644 --- a/packages/common/src/scopeSupportFacets/zig.ts +++ b/packages/common/src/scopeSupportFacets/zig.ts @@ -8,16 +8,33 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { functionCall: supported, functionCallee: supported, "argument.formal.singleLine": supported, + "argument.formal.multiLine": supported, + "argument.formal.iteration": supported, "argument.actual.singleLine": supported, + "argument.actual.multiLine": supported, + "argument.actual.iteration": supported, "argumentList.formal.singleLine": supported, + "argumentList.formal.multiLine": supported, + "argumentList.formal.empty": supported, "argumentList.actual.singleLine": supported, + "argumentList.actual.multiLine": supported, + "argumentList.actual.empty": supported, "statement.assignment": supported, + "name.assignment": supported, + "name.function": supported, + "name.argument.formal": supported, + "value.assignment": supported, + "type.argument.formal": supported, + "type.argument.formal.iteration": supported, + "type.return": supported, + "type.variable": supported, /* UNSUPPORTED */ list: unsupported, "statement.function": unsupported, + "statement.class": unsupported, "statement.if": unsupported, "statement.try": unsupported, "statement.for": unsupported, @@ -25,16 +42,20 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { "statement.return": unsupported, "statement.break": unsupported, "statement.continue": unsupported, - - "argumentList.formal.empty": unsupported, - "argumentList.formal.multiLine": unsupported, - "argumentList.actual.empty": unsupported, - "argumentList.actual.multiLine": unsupported, - "argument.actual.multiLine": unsupported, + "statement.doWhile": unsupported, + "statement.enum": unsupported, + "statement.field.class": unsupported, + "statement.method": unsupported, + "statement.misc": unsupported, + "statement.switch": unsupported, + "statement.variable": unsupported, "comment.line": unsupported, "comment.block": unsupported, + "string.multiLine": unsupported, + "string.singleLine": unsupported, + "branch.if": unsupported, "branch.if.elif.else": unsupported, "branch.if.else": unsupported, @@ -52,14 +73,11 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { "condition.switchCase": unsupported, "condition.switchCase.iteration": unsupported, - "name.assignment": unsupported, - "name.function": unsupported, "name.argument.catch": unsupported, "name.foreach": unsupported, "value.argument.formal": unsupported, "value.argument.formal.iteration": unsupported, - "value.assignment": unsupported, "value.variable": unsupported, "value.foreach": unsupported, "value.return": unsupported, @@ -68,10 +86,10 @@ export const zigScopeSupport: LanguageScopeSupportFacetMap = { "interior.class": unsupported, "interior.function": unsupported, - // "interior.constructor": unsupported, - // "interior.method": unsupported, + "interior.constructor": unsupported, + "interior.method": unsupported, "interior.if": unsupported, - // "interior.lambda": unsupported, + "interior.lambda": unsupported, "interior.for": unsupported, "interior.foreach": unsupported, "interior.while": unsupported, diff --git a/queries/zig.scm b/queries/zig.scm index 8e02ee6260..dbd2a6bedb 100644 --- a/queries/zig.scm +++ b/queries/zig.scm @@ -1,16 +1,17 @@ ;;!! fn foo() void {} ;;! ^^^ name ;;! ^^^^ type -;;! ^^^^^^^^^^^^^^^^ namedFunction +;;! ---------------- namedFunction ^domain (function_declaration name: (_) @name type: (_) @type ) @namedFunction @_.domain ;;!! fn foo(aa: u8) void {} -;;! ^^^^^^ argumentOrParameter ;;! ^^ name ;;! ^^ type +;;! ^^^^^^ argumentOrParameter ^domain +;;! ---------------------- ^domain (function_declaration (parameters (_)? @_.leading.endOf @@ -22,8 +23,10 @@ ) @argumentOrParameter @_.domain . (_)? @_.trailing.startOf - ) -) + ) @_dummy + (#not-type? @argumentOrParameter "comment") + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) @argumentOrParameter.domain @_.domain ;;!! fn foo(aa: u8, bb:u8) void {} ;;! ^^^^^^^^^^^^^ argumentList