Skip to content

Commit d3f5b34

Browse files
committed
fix: ScopeName diagnostics
1 parent 7405338 commit d3f5b34

5 files changed

Lines changed: 40 additions & 140 deletions

File tree

src/DiagnosticCollection.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ function diagnosticsHints(diagnostics: Diagnostic[], document: vscode.TextDocume
12721272
case 'contentName':
12731273
const text = node.text;
12741274
const scopes = text.split(' ');
1275-
const firstSubScopes = text.match(/^[^ ]+(?=\.[^ ]* )/)?.[0];
1275+
const firstSubScopes = scopes[0].split('.').slice(0, -1).join('.');
12761276
diagnostics.push({
12771277
range: range,
12781278
message: `TextMate 2.0 and Github-Linguist handle space separated scopes differently to VSCode TextMate.
@@ -1283,7 +1283,9 @@ function diagnosticsHints(diagnostics: Diagnostic[], document: vscode.TextDocume
12831283
However their theme parser will split scopes on spaces.
12841284
So effectively only the first sub-scope(s) \`${firstSubScopes ?? ''}\` can ever be matched against.
12851285
${name == 'name' ? 'TextMate 2.0 allows you to use "scopeName" to override "name".' : ''}`.replaceAll('\t', ''),
1286-
severity: firstSubScopes ? vscode.DiagnosticSeverity.Hint : vscode.DiagnosticSeverity.Warning,
1286+
severity: firstSubScopes || scopes[0].match(/^\.*\$\d$/)
1287+
? vscode.DiagnosticSeverity.Hint
1288+
: vscode.DiagnosticSeverity.Warning,
12871289
source: 'TextMate',
12881290
code: 'spaceScopes',
12891291
node: node,

src/test/baselines/CodeActionsProvider.json

Lines changed: 4 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -37,79 +37,11 @@
3737
"title": "Add missing scope postfix '.diagnostics'",
3838
"diagnostics": [
3939
{
40-
"startLineNumber": 51,
41-
"startColumn": 13,
42-
"endLineNumber": 0,
43-
"endColumn": 29,
44-
"message": "ScopeName 'string.scope.one' missing postfix '.diagnostics'",
45-
"source": "TextMate",
46-
"code": "scopePostfix",
47-
"severity": 4
48-
}
49-
],
50-
"edit": {
51-
"edits": [
52-
{
53-
"textEdit": {
54-
"text": ".diagnostics",
55-
"range": {
56-
"startLineNumber": 0,
57-
"startColumn": 13,
58-
"endLineNumber": 0,
59-
"endColumn": 29
60-
}
61-
},
62-
"filename": "fixtures/DiagnosticCollection.tmLanguage.json"
63-
}
64-
]
65-
},
66-
"kind": "quickfix.scopePostfix",
67-
"isPreferred": true,
68-
"isAI": false
69-
},
70-
{
71-
"title": "Add missing scope postfix '.diagnostics'",
72-
"diagnostics": [
73-
{
74-
"startLineNumber": 0,
75-
"startColumn": 30,
76-
"endLineNumber": 0,
77-
"endColumn": 47,
78-
"message": "ScopeName 'comment.scope.two' missing postfix '.diagnostics'",
79-
"source": "TextMate",
80-
"code": "scopePostfix",
81-
"severity": 4
82-
}
83-
],
84-
"edit": {
85-
"edits": [
86-
{
87-
"textEdit": {
88-
"text": ".diagnostics",
89-
"range": {
90-
"startLineNumber": 0,
91-
"startColumn": 30,
92-
"endLineNumber": 0,
93-
"endColumn": 47
94-
}
95-
},
96-
"filename": "fixtures/DiagnosticCollection.tmLanguage.json"
97-
}
98-
]
99-
},
100-
"kind": "quickfix.scopePostfix",
101-
"isPreferred": true,
102-
"isAI": false
103-
},
104-
{
105-
"title": "Add missing scope postfix '.diagnostics'",
106-
"diagnostics": [
107-
{
108-
"startLineNumber": 8,
40+
"startLineNumber": 57,
10941
"startColumn": 20,
11042
"endLineNumber": 0,
11143
"endColumn": 78,
112-
"message": "ScopeName 'TextMate 2.0 only. maybe GitHub. scopeName removes warning' missing postfix '.diagnostics'",
44+
"message": "ScopeName 'TextMate.2 0 only. maybe GitHub. scopeName removes warning' missing postfix '.diagnostics'",
11345
"source": "TextMate",
11446
"code": "scopePostfix",
11547
"severity": 4
@@ -513,7 +445,7 @@
513445
"title": "Change spelling to 'source.diagnostic'",
514446
"diagnostics": [
515447
{
516-
"startLineNumber": -164,
448+
"startLineNumber": -162,
517449
"startColumn": 16,
518450
"endLineNumber": 0,
519451
"endColumn": 34,
@@ -780,7 +712,7 @@
780712
"title": "Ignore no reference warnings",
781713
"diagnostics": [
782714
{
783-
"startLineNumber": 112,
715+
"startLineNumber": 110,
784716
"startColumn": 4,
785717
"endLineNumber": 0,
786718
"endColumn": 13,
@@ -793,23 +725,6 @@
793725
"kind": "quickfix.ignore",
794726
"isAI": false
795727
},
796-
{
797-
"title": "Extract single rule from \"patterns\"",
798-
"diagnostics": [
799-
{
800-
"startLineNumber": -79,
801-
"startColumn": 5,
802-
"endLineNumber": 0,
803-
"endColumn": 13,
804-
"message": "Patterns array not required for a single rule.",
805-
"source": "TextMate",
806-
"code": "singlePattern",
807-
"severity": 1
808-
}
809-
],
810-
"kind": "quickfix.singlePattern",
811-
"isAI": false
812-
},
813728
{
814729
"title": "Optimize Regex",
815730
"kind": "refactor.rewrite.minifyRegex",

src/test/baselines/DiagnosticCollection.json

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,46 +1580,14 @@
15801580
},
15811581
{
15821582
"line": 0,
1583-
"character": 28
1583+
"character": 70
15841584
}
15851585
],
1586-
"message": "ScopeName 'string.scope.one' missing postfix '.diagnostics'",
1587-
"severity": 1,
1588-
"source": "TextMate",
1589-
"code": "scopePostfix"
1590-
},
1591-
{
1592-
"range": [
1593-
{
1594-
"line": 0,
1595-
"character": 12
1596-
},
1597-
{
1598-
"line": 0,
1599-
"character": 46
1600-
}
1601-
],
1602-
"message": "TextMate 2.0 and Github-Linguist handle space separated scopes differently to VSCode TextMate.\nVSCode will split the scopes on spaces.\n `string.scope.one comment.scope.two` will apply 2 different scopes; `string.scope.one`, `comment.scope.two`.\nTextMate and Github will not split the scopes.\n They instead will try to match against the literal singular scopeName `string.scope.one comment.scope.two`.\n However their theme parser will split scopes on spaces.\n So effectively only the first sub-scope(s) `string.scope` can ever be matched against.\nTextMate 2.0 allows you to use \"scopeName\" to override \"name\".",
1586+
"message": "TextMate 2.0 and Github-Linguist handle space separated scopes differently to VSCode TextMate.\nVSCode will split the scopes on spaces.\n `string.scope.one.diagnostics comment.scope.two.diagnostics` will apply 2 different scopes; `string.scope.one.diagnostics`, `comment.scope.two.diagnostics`.\nTextMate and Github will not split the scopes.\n They instead will try to match against the literal singular scopeName `string.scope.one.diagnostics comment.scope.two.diagnostics`.\n However their theme parser will split scopes on spaces.\n So effectively only the first sub-scope(s) `string.scope.one` can ever be matched against.\nTextMate 2.0 allows you to use \"scopeName\" to override \"name\".",
16031587
"severity": 3,
16041588
"source": "TextMate",
16051589
"code": "spaceScopes"
16061590
},
1607-
{
1608-
"range": [
1609-
{
1610-
"line": 0,
1611-
"character": 29
1612-
},
1613-
{
1614-
"line": 0,
1615-
"character": 46
1616-
}
1617-
],
1618-
"message": "ScopeName 'comment.scope.two' missing postfix '.diagnostics'",
1619-
"severity": 1,
1620-
"source": "TextMate",
1621-
"code": "scopePostfix"
1622-
},
16231591
{
16241592
"range": [
16251593
{
@@ -1677,25 +1645,28 @@
16771645
{
16781646
"range": [
16791647
{
1680-
"line": 4,
1681-
"character": 4
1648+
"line": 2,
1649+
"character": 3
16821650
},
16831651
{
1684-
"line": 0,
1685-
"character": 12
1652+
"line": 7,
1653+
"character": 4
16861654
}
16871655
],
1688-
"message": "Patterns array not required for a single rule.",
1656+
"message": "\"patterns\" requires \"match\" and \"include\" to be absent.",
16891657
"severity": 3,
16901658
"source": "TextMate",
1691-
"code": "singlePattern"
1659+
"code": "dead",
1660+
"tags": [
1661+
1
1662+
]
16921663
},
16931664
{
16941665
"severity": "Warning",
16951666
"message": "Missing property \"begin\".",
16961667
"range": [
16971668
{
1698-
"line": 1,
1669+
"line": -6,
16991670
"character": 4
17001671
},
17011672
{
@@ -1705,17 +1676,31 @@
17051676
]
17061677
},
17071678
{
1679+
"severity": "Warning",
1680+
"message": "String does not match the pattern of \"^([\\w\\-.]|\\$\\d+|\\${\\d+(:[^}]*)?})*$\".",
17081681
"range": [
17091682
{
17101683
"line": 2,
1684+
"character": 18
1685+
},
1686+
{
1687+
"line": 0,
1688+
"character": 78
1689+
}
1690+
]
1691+
},
1692+
{
1693+
"range": [
1694+
{
1695+
"line": 0,
17111696
"character": 19
17121697
},
17131698
{
17141699
"line": 0,
17151700
"character": 77
17161701
}
17171702
],
1718-
"message": "ScopeName 'TextMate 2.0 only. maybe GitHub. scopeName removes warning' missing postfix '.diagnostics'",
1703+
"message": "ScopeName 'TextMate.2 0 only. maybe GitHub. scopeName removes warning' missing postfix '.diagnostics'",
17191704
"severity": 1,
17201705
"source": "TextMate",
17211706
"code": "scopePostfix"

src/test/fixtures/DiagnosticCollection.tmLanguage.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,13 @@
8484
},
8585
{
8686
"comment": " diagnosticsHints ",
87-
"name": "string.scope.one comment.scope.two",
87+
"name": "string.scope.one.diagnostics comment.scope.two.diagnostics",
8888
"contentName": "bigger warning with no period in the first scope",
89-
"match": "TextMate 2.0 and Github-Linguist handle space separated scopes differently to VSCode TextMate"
90-
},
91-
{
89+
"match": "TextMate 2.0 and Github-Linguist handle space separated scopes differently to VSCode TextMate",
9290
"patterns": [
9391
{
9492
"match": "Patterns array not required for a single rule",
95-
"scopeName": "TextMate 2.0 only. maybe GitHub. scopeName removes warning",
93+
"scopeName": "TextMate.2 0 only. maybe GitHub. scopeName removes warning",
9694
"name": "string.scope.one comment.scope.two",
9795
"contentName": "scopeName doesn't affect contentName"
9896
}

vscode.tmLanguage.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,9 @@
10331033
"$ref": "#/definitions/name-content"
10341034
},
10351035
"scopeName": {
1036-
"markdownDescription": "A single scopeName to be assigned to the provided token. Overrides `\"name\"`. \n_Not currently supported by VSCode_",
1036+
"markdownDescription": "A single scopeName to be assigned to the provided token. \nOverrides `\"name\"`. \nDoes not support separating scopes by spaces. \n_Not currently supported by VSCode_",
10371037
"type": "string",
1038-
"anyOf": [
1038+
"allOf": [
10391039
{ "pattern": "^([\\w\\-.]|\\$\\d+|\\${\\d+(:[^}]*)?})*$" },
10401040
{ "$ref": "#/definitions/name-content" }
10411041
]

0 commit comments

Comments
 (0)