From 3385750145e5742a5f5991df4d139ba9bc14ee37 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 12 Feb 2025 12:41:50 +0100 Subject: [PATCH 1/3] Added json facets --- .../scopes/json/key.mapPair.iteration.scope | 7 + data/fixtures/scopes/json/key.mapPair.scope | 20 +++ data/fixtures/scopes/json/list.scope | 10 ++ .../scopes/json/string.singleLine.scope | 10 ++ .../json/textFragment.comment.block.scope | 10 ++ .../json/textFragment.comment.line.scope | 10 ++ .../json/textFragment.string.singleLine.scope | 10 ++ .../scopes/json/value.mapPair.iteration.scope | 7 + data/fixtures/scopes/json/value.mapPair.scope | 20 +++ .../common/src/scopeSupportFacets/json.ts | 165 +++++++++++++++++- queries/json.scm | 8 +- 11 files changed, 271 insertions(+), 6 deletions(-) create mode 100644 data/fixtures/scopes/json/key.mapPair.iteration.scope create mode 100644 data/fixtures/scopes/json/key.mapPair.scope create mode 100644 data/fixtures/scopes/json/list.scope create mode 100644 data/fixtures/scopes/json/string.singleLine.scope create mode 100644 data/fixtures/scopes/json/textFragment.comment.block.scope create mode 100644 data/fixtures/scopes/json/textFragment.comment.line.scope create mode 100644 data/fixtures/scopes/json/textFragment.string.singleLine.scope create mode 100644 data/fixtures/scopes/json/value.mapPair.iteration.scope create mode 100644 data/fixtures/scopes/json/value.mapPair.scope diff --git a/data/fixtures/scopes/json/key.mapPair.iteration.scope b/data/fixtures/scopes/json/key.mapPair.iteration.scope new file mode 100644 index 0000000000..7d13226625 --- /dev/null +++ b/data/fixtures/scopes/json/key.mapPair.iteration.scope @@ -0,0 +1,7 @@ +{"value": 123} +--- + +[Range] = +[Domain] = 0:1-0:13 + >------------< +0| {"value": 123} diff --git a/data/fixtures/scopes/json/key.mapPair.scope b/data/fixtures/scopes/json/key.mapPair.scope new file mode 100644 index 0000000000..57faf5cca5 --- /dev/null +++ b/data/fixtures/scopes/json/key.mapPair.scope @@ -0,0 +1,20 @@ +{"value": 123} +--- + +[Content] = 0:1-0:8 + >-------< +0| {"value": 123} + +[Removal] = 0:1-0:10 + >---------< +0| {"value": 123} + +[Trailing delimiter] = 0:8-0:10 + >--< +0| {"value": 123} + +[Domain] = 0:1-0:13 + >------------< +0| {"value": 123} + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/list.scope b/data/fixtures/scopes/json/list.scope new file mode 100644 index 0000000000..54a5d795c2 --- /dev/null +++ b/data/fixtures/scopes/json/list.scope @@ -0,0 +1,10 @@ +[1, 2, 3] +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:9 + >---------< +0| [1, 2, 3] + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/string.singleLine.scope b/data/fixtures/scopes/json/string.singleLine.scope new file mode 100644 index 0000000000..9a81284fe2 --- /dev/null +++ b/data/fixtures/scopes/json/string.singleLine.scope @@ -0,0 +1,10 @@ +"value" +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:7 + >-------< +0| "value" + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/textFragment.comment.block.scope b/data/fixtures/scopes/json/textFragment.comment.block.scope new file mode 100644 index 0000000000..af33f95d00 --- /dev/null +++ b/data/fixtures/scopes/json/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/json/textFragment.comment.line.scope b/data/fixtures/scopes/json/textFragment.comment.line.scope new file mode 100644 index 0000000000..6758f81490 --- /dev/null +++ b/data/fixtures/scopes/json/textFragment.comment.line.scope @@ -0,0 +1,10 @@ +// Hello world +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:14 + >--------------< +0| // Hello world + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/textFragment.string.singleLine.scope b/data/fixtures/scopes/json/textFragment.string.singleLine.scope new file mode 100644 index 0000000000..472aea176e --- /dev/null +++ b/data/fixtures/scopes/json/textFragment.string.singleLine.scope @@ -0,0 +1,10 @@ +"value" +--- + +[Content] = +[Removal] = +[Domain] = 0:1-0:6 + >-----< +0| "value" + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/value.mapPair.iteration.scope b/data/fixtures/scopes/json/value.mapPair.iteration.scope new file mode 100644 index 0000000000..7d13226625 --- /dev/null +++ b/data/fixtures/scopes/json/value.mapPair.iteration.scope @@ -0,0 +1,7 @@ +{"value": 123} +--- + +[Range] = +[Domain] = 0:1-0:13 + >------------< +0| {"value": 123} diff --git a/data/fixtures/scopes/json/value.mapPair.scope b/data/fixtures/scopes/json/value.mapPair.scope new file mode 100644 index 0000000000..9feb69506f --- /dev/null +++ b/data/fixtures/scopes/json/value.mapPair.scope @@ -0,0 +1,20 @@ +{"value": 123} +--- + +[Content] = 0:10-0:13 + >---< +0| {"value": 123} + +[Removal] = 0:8-0:13 + >-----< +0| {"value": 123} + +[Leading delimiter] = 0:8-0:10 + >--< +0| {"value": 123} + +[Domain] = 0:1-0:13 + >------------< +0| {"value": 123} + +[Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/json.ts b/packages/common/src/scopeSupportFacets/json.ts index 1e7efd0e50..fbc25050cc 100644 --- a/packages/common/src/scopeSupportFacets/json.ts +++ b/packages/common/src/scopeSupportFacets/json.ts @@ -1,10 +1,171 @@ import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; -const { supported } = ScopeSupportFacetLevel; +const { supported, notApplicable } = ScopeSupportFacetLevel; export const jsonScopeSupport: LanguageScopeSupportFacetMap = { - "comment.line": supported, "comment.block": supported, + "comment.line": supported, + "key.mapPair.iteration": supported, + "key.mapPair": supported, + list: supported, map: supported, + "string.singleLine": supported, + "textFragment.comment.block": supported, + "textFragment.comment.line": supported, + "textFragment.string.singleLine": supported, + "value.mapPair.iteration": supported, + "value.mapPair": supported, + + // Not applicable + + anonymousFunction: notApplicable, + "argument.actual": notApplicable, + "argument.actual.constructor": notApplicable, + "argument.actual.constructor.iteration": notApplicable, + "argument.actual.iteration": notApplicable, + "argument.actual.method": notApplicable, + "argument.actual.method.iteration": notApplicable, + "argument.formal": notApplicable, + "argument.formal.constructor": notApplicable, + "argument.formal.constructor.iteration": notApplicable, + "argument.formal.iteration": notApplicable, + "argument.formal.method": notApplicable, + "argument.formal.method.iteration": notApplicable, + attribute: notApplicable, + "branch.if": notApplicable, + "branch.if.iteration": notApplicable, + "branch.loop": notApplicable, + "branch.switchCase": notApplicable, + "branch.switchCase.iteration": notApplicable, + "branch.ternary": notApplicable, + "branch.try": notApplicable, + "branch.try.iteration": notApplicable, + class: notApplicable, + "class.iteration.block": notApplicable, + "class.iteration.document": notApplicable, + className: notApplicable, + "className.iteration.block": notApplicable, + "className.iteration.document": notApplicable, + "collectionItem.unenclosed": notApplicable, + "collectionItem.unenclosed.iteration": notApplicable, + command: notApplicable, + "condition.doWhile": notApplicable, + "condition.for": notApplicable, + "condition.if": notApplicable, + "condition.switchCase": notApplicable, + "condition.switchCase.iteration": notApplicable, + "condition.ternary": notApplicable, + "condition.while": notApplicable, + disqualifyDelimiter: notApplicable, + element: notApplicable, + endTag: notApplicable, + environment: notApplicable, + fieldAccess: notApplicable, + functionCall: notApplicable, + "functionCall.constructor": notApplicable, + functionCallee: notApplicable, + "functionCallee.constructor": notApplicable, + functionName: notApplicable, + "functionName.constructor": notApplicable, + "functionName.iteration.block": notApplicable, + "functionName.iteration.document": notApplicable, + "functionName.method": notApplicable, + "functionName.method.iteration.class": notApplicable, + ifStatement: notApplicable, + "interior.cell": notApplicable, + "interior.class": notApplicable, + "interior.command": notApplicable, + "interior.element": notApplicable, + "interior.function": notApplicable, + "interior.if": notApplicable, + "interior.lambda": notApplicable, + "interior.loop": notApplicable, + "interior.resource": notApplicable, + "interior.switchCase": notApplicable, + "interior.ternary": notApplicable, + "interior.try": notApplicable, + "key.attribute": notApplicable, + "name.argument.actual": notApplicable, + "name.argument.actual.iteration": notApplicable, + "name.argument.formal": notApplicable, + "name.argument.formal.constructor": notApplicable, + "name.argument.formal.constructor.iteration": notApplicable, + "name.argument.formal.iteration": notApplicable, + "name.argument.formal.method": notApplicable, + "name.argument.formal.method.iteration": notApplicable, + "name.assignment": notApplicable, + "name.assignment.pattern": notApplicable, + "name.class": notApplicable, + "name.constructor": notApplicable, + "name.field": notApplicable, + "name.foreach": notApplicable, + "name.function": notApplicable, + "name.iteration.block": notApplicable, + "name.iteration.document": notApplicable, + "name.method": notApplicable, + "name.resource": notApplicable, + "name.resource.iteration": notApplicable, + "name.variable": notApplicable, + "name.variable.pattern": notApplicable, + namedFunction: notApplicable, + "namedFunction.constructor": notApplicable, + "namedFunction.iteration.block": notApplicable, + "namedFunction.iteration.document": notApplicable, + "namedFunction.method": notApplicable, + "namedFunction.method.iteration.class": notApplicable, + notebookCell: notApplicable, + pairDelimiter: notApplicable, + regularExpression: notApplicable, + section: notApplicable, + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + startTag: notApplicable, + statement: notApplicable, + "statement.class": notApplicable, + "statement.iteration.block": notApplicable, + "statement.iteration.document": notApplicable, + "string.multiLine": notApplicable, + switchStatementSubject: notApplicable, + tags: notApplicable, + "textFragment.element": notApplicable, + "textFragment.string.multiLine": notApplicable, + "type.alias": notApplicable, + "type.argument.formal": notApplicable, + "type.argument.formal.constructor": notApplicable, + "type.argument.formal.constructor.iteration": notApplicable, + "type.argument.formal.iteration": notApplicable, + "type.argument.formal.method": notApplicable, + "type.argument.formal.method.iteration": notApplicable, + "type.cast": notApplicable, + "type.class": notApplicable, + "type.enum": notApplicable, + "type.field": notApplicable, + "type.field.iteration": notApplicable, + "type.foreach": notApplicable, + "type.interface": notApplicable, + "type.return": notApplicable, + "type.typeArgument": notApplicable, + "type.typeArgument.iteration": notApplicable, + "type.variable": notApplicable, + "value.argument.actual": notApplicable, + "value.argument.actual.iteration": notApplicable, + "value.argument.formal": notApplicable, + "value.argument.formal.constructor": notApplicable, + "value.argument.formal.constructor.iteration": notApplicable, + "value.argument.formal.iteration": notApplicable, + "value.argument.formal.method": notApplicable, + "value.argument.formal.method.iteration": notApplicable, + "value.assignment": notApplicable, + "value.attribute": notApplicable, + "value.field": notApplicable, + "value.foreach": notApplicable, + "value.resource": notApplicable, + "value.resource.iteration": notApplicable, + "value.return": notApplicable, + "value.return.lambda": notApplicable, + "value.typeAlias": notApplicable, + "value.variable": notApplicable, + "value.variable.pattern": notApplicable, + "value.yield": notApplicable, }; diff --git a/queries/json.scm b/queries/json.scm index cdcd8e2d19..a63ed7a8dd 100644 --- a/queries/json.scm +++ b/queries/json.scm @@ -1,9 +1,5 @@ ;; https://github.com/tree-sitter/tree-sitter-json/blob/master/src/grammar.json -;;!! "string" -;;! ^^^^^^ -(string_content) @textFragment - ;;!! {"value": 0} ;;! ^^^^^^^^^^^^ (object) @map @@ -16,6 +12,10 @@ ;;! ^^^^^^^^ (string) @string +;;!! "string" +;;! ^^^^^^ +(string_content) @textFragment + ;;!! // aaa ;;! ^^^^^^ ;;!! /* aaa */ From 0589912a3df9239115a470027b2334c4b94cc482 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 12 Feb 2025 12:44:04 +0100 Subject: [PATCH 2/3] Clean up --- packages/common/src/scopeSupportFacets/json.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/json.ts b/packages/common/src/scopeSupportFacets/json.ts index fbc25050cc..8089ee0f2d 100644 --- a/packages/common/src/scopeSupportFacets/json.ts +++ b/packages/common/src/scopeSupportFacets/json.ts @@ -4,18 +4,22 @@ import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; const { supported, notApplicable } = ScopeSupportFacetLevel; export const jsonScopeSupport: LanguageScopeSupportFacetMap = { - "comment.block": supported, - "comment.line": supported, - "key.mapPair.iteration": supported, - "key.mapPair": supported, list: supported, map: supported, "string.singleLine": supported, + + "key.mapPair.iteration": supported, + "key.mapPair": supported, + + "value.mapPair.iteration": supported, + "value.mapPair": supported, + + "comment.block": supported, + "comment.line": supported, + "textFragment.comment.block": supported, "textFragment.comment.line": supported, "textFragment.string.singleLine": supported, - "value.mapPair.iteration": supported, - "value.mapPair": supported, // Not applicable From 2d817c8e4a2fbbd029928661afebf349e7d8d722 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 12 Feb 2025 12:47:26 +0100 Subject: [PATCH 3/3] Update tests --- .../scopes/json/key.mapPair.iteration.scope | 8 ++-- data/fixtures/scopes/json/key.mapPair.scope | 45 +++++++++++++----- data/fixtures/scopes/json/map.scope | 8 ++-- .../scopes/json/string.singleLine2.scope | 26 ++++++++++ .../json/textFragment.comment.block.scope | 13 +++-- .../textFragment.string.singleLine2.scope | 19 ++++++++ .../scopes/json/value.mapPair.iteration.scope | 8 ++-- data/fixtures/scopes/json/value.mapPair.scope | 47 +++++++++++++------ 8 files changed, 131 insertions(+), 43 deletions(-) create mode 100644 data/fixtures/scopes/json/string.singleLine2.scope create mode 100644 data/fixtures/scopes/json/textFragment.string.singleLine2.scope diff --git a/data/fixtures/scopes/json/key.mapPair.iteration.scope b/data/fixtures/scopes/json/key.mapPair.iteration.scope index 7d13226625..348e646e91 100644 --- a/data/fixtures/scopes/json/key.mapPair.iteration.scope +++ b/data/fixtures/scopes/json/key.mapPair.iteration.scope @@ -1,7 +1,7 @@ -{"value": 123} +{"aaa": 123, "bbb": 456} --- [Range] = -[Domain] = 0:1-0:13 - >------------< -0| {"value": 123} +[Domain] = 0:1-0:23 + >----------------------< +0| {"aaa": 123, "bbb": 456} diff --git a/data/fixtures/scopes/json/key.mapPair.scope b/data/fixtures/scopes/json/key.mapPair.scope index 57faf5cca5..d77e7977cf 100644 --- a/data/fixtures/scopes/json/key.mapPair.scope +++ b/data/fixtures/scopes/json/key.mapPair.scope @@ -1,20 +1,39 @@ -{"value": 123} +{"aaa": 123, "bbb": 456} --- -[Content] = 0:1-0:8 +[#1 Content] = 0:1-0:6 + >-----< +0| {"aaa": 123, "bbb": 456} + +[#1 Removal] = 0:1-0:8 >-------< -0| {"value": 123} +0| {"aaa": 123, "bbb": 456} + +[#1 Trailing delimiter] = 0:6-0:8 + >--< +0| {"aaa": 123, "bbb": 456} + +[#1 Domain] = 0:1-0:11 + >----------< +0| {"aaa": 123, "bbb": 456} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:13-0:18 + >-----< +0| {"aaa": 123, "bbb": 456} -[Removal] = 0:1-0:10 - >---------< -0| {"value": 123} +[#2 Removal] = 0:13-0:20 + >-------< +0| {"aaa": 123, "bbb": 456} -[Trailing delimiter] = 0:8-0:10 - >--< -0| {"value": 123} +[#2 Trailing delimiter] = 0:18-0:20 + >--< +0| {"aaa": 123, "bbb": 456} -[Domain] = 0:1-0:13 - >------------< -0| {"value": 123} +[#2 Domain] = 0:13-0:23 + >----------< +0| {"aaa": 123, "bbb": 456} -[Insertion delimiter] = " " +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/map.scope b/data/fixtures/scopes/json/map.scope index 5adc61b4a8..213d54caa1 100644 --- a/data/fixtures/scopes/json/map.scope +++ b/data/fixtures/scopes/json/map.scope @@ -1,10 +1,10 @@ -{"aaa": 0} +{"aaa": 123, "bbb": 456} --- [Content] = [Removal] = -[Domain] = 0:0-0:10 - >----------< -0| {"aaa": 0} +[Domain] = 0:0-0:24 + >------------------------< +0| {"aaa": 123, "bbb": 456} [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/string.singleLine2.scope b/data/fixtures/scopes/json/string.singleLine2.scope new file mode 100644 index 0000000000..ac6fe7e5ee --- /dev/null +++ b/data/fixtures/scopes/json/string.singleLine2.scope @@ -0,0 +1,26 @@ +{"key": "value"} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:1-0:6 + >-----< +0| {"key": "value"} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 0:8-0:15 + >-------< +0| {"key": "value"} + +[#2 Removal] = 0:7-0:15 + >--------< +0| {"key": "value"} + +[#2 Leading delimiter] = 0:7-0:8 + >-< +0| {"key": "value"} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/textFragment.comment.block.scope b/data/fixtures/scopes/json/textFragment.comment.block.scope index af33f95d00..e037658206 100644 --- a/data/fixtures/scopes/json/textFragment.comment.block.scope +++ b/data/fixtures/scopes/json/textFragment.comment.block.scope @@ -1,10 +1,15 @@ -/* Hello world */ +/* + Hello world +*/ --- [Content] = [Removal] = -[Domain] = 0:0-0:17 - >-----------------< -0| /* Hello world */ +[Domain] = 0:0-2:2 + >-- +0| /* +1| Hello world +2| */ + --< [Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/textFragment.string.singleLine2.scope b/data/fixtures/scopes/json/textFragment.string.singleLine2.scope new file mode 100644 index 0000000000..9c86ca8d55 --- /dev/null +++ b/data/fixtures/scopes/json/textFragment.string.singleLine2.scope @@ -0,0 +1,19 @@ +{"key": "value"} +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:2-0:5 + >---< +0| {"key": "value"} + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 0:9-0:14 + >-----< +0| {"key": "value"} + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/json/value.mapPair.iteration.scope b/data/fixtures/scopes/json/value.mapPair.iteration.scope index 7d13226625..348e646e91 100644 --- a/data/fixtures/scopes/json/value.mapPair.iteration.scope +++ b/data/fixtures/scopes/json/value.mapPair.iteration.scope @@ -1,7 +1,7 @@ -{"value": 123} +{"aaa": 123, "bbb": 456} --- [Range] = -[Domain] = 0:1-0:13 - >------------< -0| {"value": 123} +[Domain] = 0:1-0:23 + >----------------------< +0| {"aaa": 123, "bbb": 456} diff --git a/data/fixtures/scopes/json/value.mapPair.scope b/data/fixtures/scopes/json/value.mapPair.scope index 9feb69506f..d4cf96e4d9 100644 --- a/data/fixtures/scopes/json/value.mapPair.scope +++ b/data/fixtures/scopes/json/value.mapPair.scope @@ -1,20 +1,39 @@ -{"value": 123} +{"aaa": 123, "bbb": 456} --- -[Content] = 0:10-0:13 - >---< -0| {"value": 123} +[#1 Content] = 0:8-0:11 + >---< +0| {"aaa": 123, "bbb": 456} -[Removal] = 0:8-0:13 - >-----< -0| {"value": 123} +[#1 Removal] = 0:6-0:11 + >-----< +0| {"aaa": 123, "bbb": 456} -[Leading delimiter] = 0:8-0:10 - >--< -0| {"value": 123} +[#1 Leading delimiter] = 0:6-0:8 + >--< +0| {"aaa": 123, "bbb": 456} -[Domain] = 0:1-0:13 - >------------< -0| {"value": 123} +[#1 Domain] = 0:1-0:11 + >----------< +0| {"aaa": 123, "bbb": 456} -[Insertion delimiter] = " " +[#1 Insertion delimiter] = " " + + +[#2 Content] = 0:20-0:23 + >---< +0| {"aaa": 123, "bbb": 456} + +[#2 Removal] = 0:18-0:23 + >-----< +0| {"aaa": 123, "bbb": 456} + +[#2 Leading delimiter] = 0:18-0:20 + >--< +0| {"aaa": 123, "bbb": 456} + +[#2 Domain] = 0:13-0:23 + >----------< +0| {"aaa": 123, "bbb": 456} + +[#2 Insertion delimiter] = " "