mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
Separate grammar for jsonc (fixes #42539)
This commit is contained in:
parent
f984189246
commit
7f56f200c1
41
extensions/json/build/update-grammars.js
Normal file
41
extensions/json/build/update-grammars.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
var updateGrammar = require('../../../build/npm/update-grammar');
|
||||
|
||||
function adaptJSON(grammar, replacementScope) {
|
||||
grammar.name = 'JSON with comments';
|
||||
grammar.scopeName = `source${replacementScope}`;
|
||||
|
||||
var fixScopeNames = function(rule) {
|
||||
if (typeof rule.name === 'string') {
|
||||
rule.name = rule.name.replace(/\.json/g, replacementScope);
|
||||
}
|
||||
if (typeof rule.contentName === 'string') {
|
||||
rule.contentName = rule.contentName.replace(/\.json/g, replacementScope);
|
||||
}
|
||||
for (var property in rule) {
|
||||
var value = rule[property];
|
||||
if (typeof value === 'object') {
|
||||
fixScopeNames(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var repository = grammar.repository;
|
||||
for (var key in repository) {
|
||||
fixScopeNames(repository[key]);
|
||||
}
|
||||
}
|
||||
|
||||
var tsGrammarRepo = 'Microsoft/vscode-JSON.tmLanguage';
|
||||
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSON.tmLanguage.json');
|
||||
updateGrammar.update(tsGrammarRepo, 'JSON.tmLanguage', './syntaxes/JSONC.tmLanguage.json', grammar => adaptJSON(grammar, '.jsonc'));
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
"vscode": "0.10.x"
|
||||
},
|
||||
"scripts": {
|
||||
"update-grammar": "node ../../build/npm/update-grammar.js Microsoft/vscode-JSON.tmLanguage JSON.tmLanguage ./syntaxes/JSON.tmLanguage.json"
|
||||
"update-grammar": "node ./build/update-grammars.js"
|
||||
},
|
||||
"contributes": {
|
||||
"languages": [
|
||||
|
@ -58,8 +58,8 @@
|
|||
},
|
||||
{
|
||||
"language": "jsonc",
|
||||
"scopeName": "source.json",
|
||||
"path": "./syntaxes/JSON.tmLanguage.json"
|
||||
"scopeName": "source.jsonc",
|
||||
"path": "./syntaxes/JSONC.tmLanguage.json"
|
||||
}
|
||||
],
|
||||
"jsonValidation": [
|
||||
|
|
213
extensions/json/syntaxes/JSONC.tmLanguage.json
Normal file
213
extensions/json/syntaxes/JSONC.tmLanguage.json
Normal file
|
@ -0,0 +1,213 @@
|
|||
{
|
||||
"information_for_contributors": [
|
||||
"This file has been converted from https://github.com/Microsoft/vscode-JSON.tmLanguage/blob/master/JSON.tmLanguage",
|
||||
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
|
||||
"Once accepted there, we are happy to receive an update request."
|
||||
],
|
||||
"version": "https://github.com/Microsoft/vscode-JSON.tmLanguage/commit/9bd83f1c252b375e957203f21793316203f61f70",
|
||||
"name": "JSON with comments",
|
||||
"scopeName": "source.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#value"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"array": {
|
||||
"begin": "\\[",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.array.begin.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\\]",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.array.end.jsonc"
|
||||
}
|
||||
},
|
||||
"name": "meta.structure.array.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#value"
|
||||
},
|
||||
{
|
||||
"match": ",",
|
||||
"name": "punctuation.separator.array.jsonc"
|
||||
},
|
||||
{
|
||||
"match": "[^\\s\\]]",
|
||||
"name": "invalid.illegal.expected-array-separator.jsonc"
|
||||
}
|
||||
]
|
||||
},
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "/\\*\\*(?!/)",
|
||||
"captures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.comment.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\\*/",
|
||||
"name": "comment.block.documentation.jsonc"
|
||||
},
|
||||
{
|
||||
"begin": "/\\*",
|
||||
"captures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.comment.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\\*/",
|
||||
"name": "comment.block.jsonc"
|
||||
},
|
||||
{
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "punctuation.definition.comment.jsonc"
|
||||
}
|
||||
},
|
||||
"match": "(//).*$\\n?",
|
||||
"name": "comment.line.double-slash.js"
|
||||
}
|
||||
]
|
||||
},
|
||||
"constant": {
|
||||
"match": "\\b(?:true|false|null)\\b",
|
||||
"name": "constant.language.jsonc"
|
||||
},
|
||||
"number": {
|
||||
"match": "(?x) # turn on extended mode\n -? # an optional minus\n (?:\n 0 # a zero\n | # ...or...\n [1-9] # a 1-9 character\n \\d* # followed by zero or more digits\n )\n (?:\n (?:\n \\. # a period\n \\d+ # followed by one or more digits\n )?\n (?:\n [eE] # an e character\n [+-]? # followed by an option +/-\n \\d+ # followed by one or more digits\n )? # make exponent optional\n )? # make decimal portion optional",
|
||||
"name": "constant.numeric.jsonc"
|
||||
},
|
||||
"object": {
|
||||
"begin": "\\{",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.dictionary.begin.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\\}",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.dictionary.end.jsonc"
|
||||
}
|
||||
},
|
||||
"name": "meta.structure.dictionary.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "the JSON object key",
|
||||
"include": "#objectkey"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"begin": ":",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.separator.dictionary.key-value.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "(,)|(?=\\})",
|
||||
"endCaptures": {
|
||||
"1": {
|
||||
"name": "punctuation.separator.dictionary.pair.jsonc"
|
||||
}
|
||||
},
|
||||
"name": "meta.structure.dictionary.value.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "the JSON object value",
|
||||
"include": "#value"
|
||||
},
|
||||
{
|
||||
"match": "[^\\s,]",
|
||||
"name": "invalid.illegal.expected-dictionary-separator.jsonc"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"match": "[^\\s\\}]",
|
||||
"name": "invalid.illegal.expected-dictionary-separator.jsonc"
|
||||
}
|
||||
]
|
||||
},
|
||||
"string": {
|
||||
"begin": "\"",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.begin.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\"",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.end.jsonc"
|
||||
}
|
||||
},
|
||||
"name": "string.quoted.double.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#stringcontent"
|
||||
}
|
||||
]
|
||||
},
|
||||
"objectkey": {
|
||||
"begin": "\"",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.support.type.property-name.begin.jsonc"
|
||||
}
|
||||
},
|
||||
"end": "\"",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.support.type.property-name.end.jsonc"
|
||||
}
|
||||
},
|
||||
"name": "string.jsonc support.type.property-name.jsonc",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#stringcontent"
|
||||
}
|
||||
]
|
||||
},
|
||||
"stringcontent": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "(?x) # turn on extended mode\n \\\\ # a literal backslash\n (?: # ...followed by...\n [\"\\\\/bfnrt] # one of these characters\n | # ...or...\n u # a u\n [0-9a-fA-F]{4}) # and four hex digits",
|
||||
"name": "constant.character.escape.jsonc"
|
||||
},
|
||||
{
|
||||
"match": "\\\\.",
|
||||
"name": "invalid.illegal.unrecognized-string-escape.jsonc"
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#constant"
|
||||
},
|
||||
{
|
||||
"include": "#number"
|
||||
},
|
||||
{
|
||||
"include": "#string"
|
||||
},
|
||||
{
|
||||
"include": "#array"
|
||||
},
|
||||
{
|
||||
"include": "#object"
|
||||
},
|
||||
{
|
||||
"include": "#comments"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -290,7 +290,10 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"scope": "support.type.property-name.json",
|
||||
"scope": [
|
||||
"support.type.property-name.json",
|
||||
"support.type.property-name.jsonc",
|
||||
],
|
||||
"settings": {
|
||||
"foreground": "#0451a5"
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[
|
||||
{
|
||||
"c": "{",
|
||||
"t": "source.json meta.structure.dictionary.json punctuation.definition.dictionary.begin.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc punctuation.definition.dictionary.begin.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\t",
|
||||
"t": "source.json meta.structure.dictionary.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -23,7 +23,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json string.json support.type.property-name.json punctuation.support.type.property-name.begin.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc punctuation.support.type.property-name.begin.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -34,7 +34,7 @@
|
|||
},
|
||||
{
|
||||
"c": "compilerOptions",
|
||||
"t": "source.json meta.structure.dictionary.json string.json support.type.property-name.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -45,7 +45,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json string.json support.type.property-name.json punctuation.support.type.property-name.end.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc punctuation.support.type.property-name.end.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -56,7 +56,7 @@
|
|||
},
|
||||
{
|
||||
"c": ":",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json punctuation.separator.dictionary.key-value.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc punctuation.separator.dictionary.key-value.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -67,7 +67,7 @@
|
|||
},
|
||||
{
|
||||
"c": " ",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -78,7 +78,7 @@
|
|||
},
|
||||
{
|
||||
"c": "{",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json punctuation.definition.dictionary.begin.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc punctuation.definition.dictionary.begin.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -89,7 +89,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\t\t",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -100,7 +100,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json string.json support.type.property-name.json punctuation.support.type.property-name.begin.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc punctuation.support.type.property-name.begin.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -111,7 +111,7 @@
|
|||
},
|
||||
{
|
||||
"c": "target",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json string.json support.type.property-name.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -122,7 +122,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json string.json support.type.property-name.json punctuation.support.type.property-name.end.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc string.json.jsonc support.type.property-name.json.jsonc punctuation.support.type.property-name.end.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "support.type.property-name: #9CDCFE",
|
||||
"light_plus": "support.type.property-name.json: #0451A5",
|
||||
|
@ -133,7 +133,7 @@
|
|||
},
|
||||
{
|
||||
"c": ":",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json punctuation.separator.dictionary.key-value.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc punctuation.separator.dictionary.key-value.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -144,7 +144,7 @@
|
|||
},
|
||||
{
|
||||
"c": " ",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -155,7 +155,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json string.quoted.double.json punctuation.definition.string.begin.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc string.quoted.double.json.jsonc punctuation.definition.string.begin.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "string: #CE9178",
|
||||
"light_plus": "string: #A31515",
|
||||
|
@ -166,7 +166,7 @@
|
|||
},
|
||||
{
|
||||
"c": "es6",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json string.quoted.double.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc string.quoted.double.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "string: #CE9178",
|
||||
"light_plus": "string: #A31515",
|
||||
|
@ -177,7 +177,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\"",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json string.quoted.double.json punctuation.definition.string.end.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc string.quoted.double.json.jsonc punctuation.definition.string.end.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "string: #CE9178",
|
||||
"light_plus": "string: #A31515",
|
||||
|
@ -188,7 +188,7 @@
|
|||
},
|
||||
{
|
||||
"c": "\t",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json meta.structure.dictionary.value.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -199,7 +199,7 @@
|
|||
},
|
||||
{
|
||||
"c": "}",
|
||||
"t": "source.json meta.structure.dictionary.json meta.structure.dictionary.value.json meta.structure.dictionary.json punctuation.definition.dictionary.end.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc meta.structure.dictionary.value.json.jsonc meta.structure.dictionary.json.jsonc punctuation.definition.dictionary.end.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
@ -210,7 +210,7 @@
|
|||
},
|
||||
{
|
||||
"c": "}",
|
||||
"t": "source.json meta.structure.dictionary.json punctuation.definition.dictionary.end.json",
|
||||
"t": "source.json.jsonc meta.structure.dictionary.json.jsonc punctuation.definition.dictionary.end.json.jsonc",
|
||||
"r": {
|
||||
"dark_plus": "default: #D4D4D4",
|
||||
"light_plus": "default: #000000",
|
||||
|
|
Loading…
Reference in a new issue