Skip to content

Commit 68315f5

Browse files
committed
Add YAML-TextMate language
1 parent 2eb5219 commit 68315f5

File tree

8 files changed

+6161
-3
lines changed

8 files changed

+6161
-3
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"comments": {
3+
// symbol used for single line comment. Remove this entry if your language does not support line comments
4+
"lineComment": "#",
5+
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
6+
// "blockComment": [ "#", "" ]
7+
},
8+
// symbols used as brackets
9+
"brackets": [
10+
["{", "}"],
11+
["[", "]"],
12+
["!<", ">"]
13+
],
14+
// symbols that are auto closed when typing
15+
"autoClosingPairs": [
16+
["{", "}"],
17+
["[", "]"],
18+
["!<", ">"],
19+
["\"", "\""],
20+
["'", "'"]
21+
],
22+
"autoCloseBefore": ":,}] \r\n\t",
23+
// symbols that can be used to surround a selection
24+
"surroundingPairs": [
25+
["{", "}"],
26+
["[", "]"],
27+
["\"", "\""],
28+
["'", "'"]
29+
],
30+
// symbols that are colourized
31+
"colorizedBracketPairs": [
32+
["{", "}"],
33+
["[", "]"]
34+
],
35+
// markers that can be folded
36+
"folding": {
37+
"offSide": true,
38+
"markers": {
39+
"start": "^[ \t]*#[ \t]*region\\b|^---[ \t]*(#.*)?$",
40+
"end": "^[ \t]*#[ \t]*endregion\\b|^\\.{3}[ \t]*(#.*)?$"
41+
}
42+
}
43+
}

package.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@
8989
"light": "assets/TextMate-file-icon.svg"
9090
}
9191
},
92+
{
93+
"id": "yaml-textmate",
94+
"aliases": [
95+
"YAML TextMate"
96+
],
97+
"extensions": [
98+
".tmLanguage.yaml",
99+
".tmLanguage.yml",
100+
".YAML-tmLanguage"
101+
],
102+
"configuration": "./language-configurations/yaml.language-configuration.json",
103+
"icon": {
104+
"dark": "assets/TextMate-file-icon.svg",
105+
"light": "assets/TextMate-file-icon.svg"
106+
}
107+
},
92108
{
93109
"id": "textmate-scopes",
94110
"aliases": [
@@ -126,6 +142,24 @@
126142
"scopeName": "source.json.textmate.regexp",
127143
"path": "./syntaxes/regex.tmLanguage.json"
128144
},
145+
{
146+
"language": "yaml-textmate",
147+
"scopeName": "source.yaml.textmate",
148+
"path": "./syntaxes/yaml.tmLanguage.json",
149+
"embeddedLanguages": {
150+
"meta.embedded.json.textmate.regexp": "json-textmate-regex",
151+
"meta.embedded.yaml.textmate.regexp": "json-textmate-regex"
152+
},
153+
"unbalancedBracketScopes": [
154+
"invalid.illegal",
155+
"storage.type.tag.shorthand.yaml",
156+
"keyword.control.flow"
157+
]
158+
},
159+
{
160+
"scopeName": "source.yaml.textmate.regexp",
161+
"path": "./syntaxes/yaml-regex.tmLanguage.json"
162+
},
129163
{
130164
"language": "textmate-scopes",
131165
"scopeName": "source.textmate.scopes",
@@ -215,6 +249,11 @@
215249
"languageId": "json-textmate"
216250
}
217251
],
252+
"yamlLanguageParticipants": [
253+
{
254+
"languageId": "yaml-textmate"
255+
}
256+
],
218257
"jsonValidation": [
219258
{
220259
"fileMatch": [
@@ -225,6 +264,17 @@
225264
"url": "./vscode.tmLanguage.schema.json"
226265
}
227266
],
267+
"yamlValidation": [
268+
{
269+
"fileMatch": [
270+
"*.tmLanguage.yaml",
271+
"*.tmLanguage.yml",
272+
"*.YAML-tmLanguage",
273+
"*.yaml-tmLanguage"
274+
],
275+
"url": "./vscode.tmLanguage.schema.json"
276+
}
277+
],
228278
"viewsContainers": {
229279
"activitybar": [
230280
{

src/extension.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ export async function activate(context: vscode.ExtensionContext) {
6565
// vscode.languages.registerDocumentSemanticTokensProvider(DocumentSelector, DocumentSemanticTokensProvider, SemanticTokensLegend), // Context aware syntax highlighting
6666
// vscode.languages.registerDocumentRangeSemanticTokensProvider(DocumentSelector, DocumentRangeSemanticTokensProvider, SemanticTokensLegend), // Context aware syntax highlighting
6767
vscode.languages.registerDocumentRangeFormattingEditProvider(DocumentSelector, DocumentRangeFormattingEditProvider), // right-click => Format Selection
68+
69+
vscode.workspace.onDidOpenTextDocument(activateRedHatExtension), // Activates YAML language features on yaml-textmate files
6870
);
6971

72+
for (const editor of vscode.window.visibleTextEditors) {
73+
activateRedHatExtension(editor.document);
74+
}
75+
7076
// vscode.window.showInformationMessage(`Extension ${(performance.now() - start).toFixed(3)}ms`);
7177
}
7278

@@ -79,6 +85,17 @@ export function deactivate() {
7985
}
8086

8187

88+
function activateRedHatExtension(document: vscode.TextDocument) {
89+
if (vscode.languages.match({ language: 'yaml-textmate' }, document)) {
90+
const extensionRedHat = vscode.extensions.getExtension("redhat.vscode-yaml");
91+
if (extensionRedHat) {
92+
if (!extensionRedHat.isActive) {
93+
extensionRedHat.activate();
94+
}
95+
}
96+
}
97+
}
98+
8299
export function sleep(milliseconds: number) {
83100
return new Promise(resolve => setTimeout(resolve, milliseconds));
84101
}

syntaxes/regex.tmLanguage.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
"name": "capture-group-modify-whole",
381381
"patterns": [
382382
{
383-
"begin": "\\G",
383+
"begin": "(?<=\\?)\\G",
384384
"end": "(?=[):\"])",
385385
"patterns": [
386386
{
@@ -435,7 +435,7 @@
435435
"name": "capture-group-modify",
436436
"patterns": [
437437
{
438-
"begin": "\\G",
438+
"begin": "(?<=\\?)\\G",
439439
"end": "(:)|(\\))",
440440
"endCaptures": {
441441
"1": { "name": "support.function.tm" },
@@ -467,7 +467,7 @@
467467
"name": "capture-group-modify-extended",
468468
"patterns": [
469469
{
470-
"begin": "\\G",
470+
"begin": "(?<=\\?)\\G",
471471
"end": "(:)|(\\))|(?=\")",
472472
"endCaptures": {
473473
"1": { "name": "support.function.tm" },

0 commit comments

Comments
 (0)