Skip to content

Commit

Permalink
Add YAML-TextMate language
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Feb 14, 2025
1 parent 2eb5219 commit 68315f5
Show file tree
Hide file tree
Showing 8 changed files with 6,161 additions and 3 deletions.
43 changes: 43 additions & 0 deletions language-configurations/yaml.language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "#",
// symbols used for start and end a block comment. Remove this entry if your language does not support block comments
// "blockComment": [ "#", "" ]
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["!<", ">"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["!<", ">"],
["\"", "\""],
["'", "'"]
],
"autoCloseBefore": ":,}] \r\n\t",
// symbols that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["\"", "\""],
["'", "'"]
],
// symbols that are colourized
"colorizedBracketPairs": [
["{", "}"],
["[", "]"]
],
// markers that can be folded
"folding": {
"offSide": true,
"markers": {
"start": "^[ \t]*#[ \t]*region\\b|^---[ \t]*(#.*)?$",
"end": "^[ \t]*#[ \t]*endregion\\b|^\\.{3}[ \t]*(#.*)?$"
}
}
}
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@
"light": "assets/TextMate-file-icon.svg"
}
},
{
"id": "yaml-textmate",
"aliases": [
"YAML TextMate"
],
"extensions": [
".tmLanguage.yaml",
".tmLanguage.yml",
".YAML-tmLanguage"
],
"configuration": "./language-configurations/yaml.language-configuration.json",
"icon": {
"dark": "assets/TextMate-file-icon.svg",
"light": "assets/TextMate-file-icon.svg"
}
},
{
"id": "textmate-scopes",
"aliases": [
Expand Down Expand Up @@ -126,6 +142,24 @@
"scopeName": "source.json.textmate.regexp",
"path": "./syntaxes/regex.tmLanguage.json"
},
{
"language": "yaml-textmate",
"scopeName": "source.yaml.textmate",
"path": "./syntaxes/yaml.tmLanguage.json",
"embeddedLanguages": {
"meta.embedded.json.textmate.regexp": "json-textmate-regex",
"meta.embedded.yaml.textmate.regexp": "json-textmate-regex"
},
"unbalancedBracketScopes": [
"invalid.illegal",
"storage.type.tag.shorthand.yaml",
"keyword.control.flow"
]
},
{
"scopeName": "source.yaml.textmate.regexp",
"path": "./syntaxes/yaml-regex.tmLanguage.json"
},
{
"language": "textmate-scopes",
"scopeName": "source.textmate.scopes",
Expand Down Expand Up @@ -215,6 +249,11 @@
"languageId": "json-textmate"
}
],
"yamlLanguageParticipants": [
{
"languageId": "yaml-textmate"
}
],
"jsonValidation": [
{
"fileMatch": [
Expand All @@ -225,6 +264,17 @@
"url": "./vscode.tmLanguage.schema.json"
}
],
"yamlValidation": [
{
"fileMatch": [
"*.tmLanguage.yaml",
"*.tmLanguage.yml",
"*.YAML-tmLanguage",
"*.yaml-tmLanguage"
],
"url": "./vscode.tmLanguage.schema.json"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down
17 changes: 17 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ export async function activate(context: vscode.ExtensionContext) {
// vscode.languages.registerDocumentSemanticTokensProvider(DocumentSelector, DocumentSemanticTokensProvider, SemanticTokensLegend), // Context aware syntax highlighting
// vscode.languages.registerDocumentRangeSemanticTokensProvider(DocumentSelector, DocumentRangeSemanticTokensProvider, SemanticTokensLegend), // Context aware syntax highlighting
vscode.languages.registerDocumentRangeFormattingEditProvider(DocumentSelector, DocumentRangeFormattingEditProvider), // right-click => Format Selection

vscode.workspace.onDidOpenTextDocument(activateRedHatExtension), // Activates YAML language features on yaml-textmate files
);

for (const editor of vscode.window.visibleTextEditors) {
activateRedHatExtension(editor.document);
}

// vscode.window.showInformationMessage(`Extension ${(performance.now() - start).toFixed(3)}ms`);
}

Expand All @@ -79,6 +85,17 @@ export function deactivate() {
}


function activateRedHatExtension(document: vscode.TextDocument) {
if (vscode.languages.match({ language: 'yaml-textmate' }, document)) {
const extensionRedHat = vscode.extensions.getExtension("redhat.vscode-yaml");
if (extensionRedHat) {
if (!extensionRedHat.isActive) {
extensionRedHat.activate();
}
}
}
}

export function sleep(milliseconds: number) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
Expand Down
6 changes: 3 additions & 3 deletions syntaxes/regex.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"name": "capture-group-modify-whole",
"patterns": [
{
"begin": "\\G",
"begin": "(?<=\\?)\\G",
"end": "(?=[):\"])",
"patterns": [
{
Expand Down Expand Up @@ -435,7 +435,7 @@
"name": "capture-group-modify",
"patterns": [
{
"begin": "\\G",
"begin": "(?<=\\?)\\G",
"end": "(:)|(\\))",
"endCaptures": {
"1": { "name": "support.function.tm" },
Expand Down Expand Up @@ -467,7 +467,7 @@
"name": "capture-group-modify-extended",
"patterns": [
{
"begin": "\\G",
"begin": "(?<=\\?)\\G",
"end": "(:)|(\\))|(?=\")",
"endCaptures": {
"1": { "name": "support.function.tm" },
Expand Down
Loading

1 comment on commit 68315f5

@RedCMD
Copy link
Owner Author

@RedCMD RedCMD commented on 68315f5 Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#19

Please sign in to comment.