Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/json/build/update-grammars.js
4772 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
'use strict';
6
7
var updateGrammar = require('vscode-grammar-updater');
8
9
function adaptJSON(grammar, name, replacementScope, replaceeScope = 'json') {
10
grammar.name = name;
11
grammar.scopeName = `source${replacementScope}`;
12
const regex = new RegExp(`\\.${replaceeScope}`, 'g');
13
var fixScopeNames = function (rule) {
14
if (typeof rule.name === 'string') {
15
rule.name = rule.name.replace(regex, replacementScope);
16
}
17
if (typeof rule.contentName === 'string') {
18
rule.contentName = rule.contentName.replace(regex, replacementScope);
19
}
20
for (var property in rule) {
21
var value = rule[property];
22
if (typeof value === 'object') {
23
fixScopeNames(value);
24
}
25
}
26
};
27
28
var repository = grammar.repository;
29
for (var key in repository) {
30
fixScopeNames(repository[key]);
31
}
32
}
33
34
var tsGrammarRepo = 'microsoft/vscode-JSON.tmLanguage';
35
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSON.tmLanguage.json');
36
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSONC.tmLanguage.json', grammar => adaptJSON(grammar, 'JSON with Comments', '.json.comments'));
37
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSONL.tmLanguage.json', grammar => adaptJSON(grammar, 'JSON Lines', '.json.lines'));
38
39
updateGrammar.update('jeff-hykin/better-snippet-syntax', 'autogenerated/jsonc.tmLanguage.json', './syntaxes/snippets.tmLanguage.json', grammar => adaptJSON(grammar, 'Snippets', '.json.comments.snippets', 'json.comments'));
40
41