Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions esm/vs/editor/editor.api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7431,9 +7431,6 @@ export namespace languages.json {
* `DiagnosticsOptions.allowComments` will override this setting.
*/
readonly allowComments?: boolean;

readonly allowMultilineStrings?: boolean;

/**
* A list of known schemas and/or associations of schemas to file names.
*/
Expand Down
39 changes: 9 additions & 30 deletions esm/vs/language/json/_deps/jsonc-parser/impl/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,18 @@ export function createScanner(text, ignoreTrivia) {
}
return text.substring(start, end);
}
function scanString(multiline = false) {
function scanString() {
var result = '', start = pos;
while (true) {
if (pos >= len || (multiline && pos >= len-2)) {
// TODO check end of string
if (multiline) {
pos += 2;
}
if (pos >= len) {
result += text.substring(start, pos);
scanError = 2 /* UnexpectedEndOfString */;
break;
}
var ch = text.charCodeAt(pos);
const endOfString = multiline ? ch === 34 /* doubleQuote */ && text.charCodeAt(pos + 1) === 34 && text.charCodeAt(pos + 2) === 34 : ch === 34 /* doubleQuote */;
if (endOfString /* doubleQuote */) {
if (ch === 34 /* doubleQuote */) {
result += text.substring(start, pos);
pos+= multiline ? 3 : 1;
pos++;
break;
}
if (ch === 92 /* backslash */) {
Expand All @@ -112,7 +107,6 @@ export function createScanner(text, ignoreTrivia) {
scanError = 2 /* UnexpectedEndOfString */;
break;
}
// TODO escape character end of line
var ch2 = text.charCodeAt(pos++);
switch (ch2) {
case 34 /* doubleQuote */:
Expand Down Expand Up @@ -156,22 +150,9 @@ export function createScanner(text, ignoreTrivia) {
}
if (ch >= 0 && ch <= 0x1f) {
if (isLineBreak(ch)) {
if (multiline) {
result += text.substring(start, pos);
result += "\n";
pos++;
if (ch === 13 /* carriageReturn */ && text.charCodeAt(pos) === 10 /* lineFeed */) {
pos++;
}
lineNumber++;
tokenLineStartOffset = pos;
start=pos;
continue;
} else {
result += text.substring(start, pos);
scanError = 2 /* UnexpectedEndOfString */;
break;
}
result += text.substring(start, pos);
scanError = 2 /* UnexpectedEndOfString */;
break;
}
else {
scanError = 6 /* InvalidCharacter */;
Expand All @@ -180,7 +161,6 @@ export function createScanner(text, ignoreTrivia) {
}
pos++;
}

return result;
}
function scanNext() {
Expand Down Expand Up @@ -238,9 +218,8 @@ export function createScanner(text, ignoreTrivia) {
return token = 5 /* CommaToken */;
// strings
case 34 /* doubleQuote */:
const multiline = (pos + 2 < len) && text.charCodeAt(pos+1) === 34 && text.charCodeAt(pos+2) === 34;
pos += multiline ? 3 : 1;
value = scanString(multiline);
pos++;
value = scanString();
return token = 10 /* StringLiteral */;
// comments
case 47 /* slash */:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ var ValidationResult = /** @class */ (function () {
export { ValidationResult };
export function newJSONDocument(root, diagnostics) {
if (diagnostics === void 0) { diagnostics = []; }
return new JSONDocument(root, diagnostics, [], []);
return new JSONDocument(root, diagnostics, []);
}
export function getNodeValue(node) {
return Json.getNodeValue(node);
Expand All @@ -273,13 +273,12 @@ export function contains(node, offset, includeRightBound) {
return offset >= node.offset && offset < (node.offset + node.length) || includeRightBound && offset === (node.offset + node.length);
}
var JSONDocument = /** @class */ (function () {
function JSONDocument(root, syntaxErrors, comments, multilineStrings) {
function JSONDocument(root, syntaxErrors, comments) {
if (syntaxErrors === void 0) { syntaxErrors = []; }
if (comments === void 0) { comments = []; }
this.root = root;
this.syntaxErrors = syntaxErrors;
this.comments = comments;
this.multilineStrings = multilineStrings;
}
JSONDocument.prototype.getNodeFromOffset = function (offset, includeRightBound) {
if (includeRightBound === void 0) { includeRightBound = false; }
Expand Down Expand Up @@ -931,17 +930,11 @@ export function parse(textDocument, config) {
var text = textDocument.getText();
var scanner = Json.createScanner(text, false);
var commentRanges = config && config.collectComments ? [] : undefined;
var multilineStringRanges = [];
function _scanNext() {
while (true) {
var token_1 = scanner.scan();
_checkScanError();
switch (token_1) {
case 10 /* StringLiteral */:
if (scanner.getTokenLength() > 3 && text.substring(scanner.getTokenOffset(), scanner.getTokenOffset() + 3) === "\"\"\"") {
multilineStringRanges.push(Range.create(textDocument.positionAt(scanner.getTokenOffset()), textDocument.positionAt(scanner.getTokenOffset() + scanner.getTokenLength())));
}
return token_1;
case 12 /* LineCommentTrivia */:
case 13 /* BlockCommentTrivia */:
if (Array.isArray(commentRanges)) {
Expand Down Expand Up @@ -1215,5 +1208,5 @@ export function parse(textDocument, config) {
_error(localize('End of file expected', 'End of file expected.'), ErrorCode.Undefined);
}
}
return new JSONDocument(_root, problems, commentRanges, multilineStringRanges);
return new JSONDocument(_root, problems, commentRanges);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var JSONValidation = /** @class */ (function () {
var getDiagnostics = function (schema) {
var trailingCommaSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.trailingCommas) ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
var commentSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.comments) ? toDiagnosticSeverity(documentSettings.comments) : _this.commentSeverity;
var allowMultiline = documentSettings && documentSettings.allowMultilineStrings;
var schemaValidation = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaValidation) ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
var schemaRequest = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaRequest) ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
if (schema) {
Expand Down Expand Up @@ -83,13 +82,6 @@ var JSONValidation = /** @class */ (function () {
addProblem(Diagnostic.create(c, message_1, commentSeverity, ErrorCode.CommentNotPermitted));
});
}

if (!allowMultiline) {
var message_1 = localize('InvalidMultilineString', 'Multiline strings are not permitted in JSON');
jsonDocument.multilineStrings.forEach(function (c) {
addProblem(Diagnostic.create(c, message_1, DiagnosticSeverity.Error, ErrorCode.UnexpectedEndOfString));
});
}
return diagnostics;
};
if (schema) {
Expand Down
2 changes: 0 additions & 2 deletions esm/vs/language/json/monaco.contribution.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export interface DiagnosticsOptions {
* The severity of reported comments. If not set, 'DiagnosticsOptions.allowComments' defines whether comments are ignored or reported as errors.
*/
readonly comments?: SeverityLevel;

readonly multilineStrings?: SeverityLevel;
}
export declare type SeverityLevel = 'error' | 'warning' | 'ignore';
export interface ModeConfiguration {
Expand Down
10 changes: 4 additions & 6 deletions esm/vs/language/json/tokenization.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ function tokenize(comments, line, state, offsetDelta, stopAtOffset) {
var adjustOffset = false;
switch (state.scanError) {
case 2 /* UnexpectedEndOfString */:
line = '"""' + line;
numberOfInsertedCharacters = 3;
line = '"' + line;
numberOfInsertedCharacters = 1;
break;
case 1 /* UnexpectedEndOfComment */:
line = '/*' + line;
numberOfInsertedCharacters = 2;
break;
break;
}
var scanner = json.createScanner(line);
var lastWasColon = state.lastWasColon;
Expand Down Expand Up @@ -169,9 +169,7 @@ function tokenize(comments, line, state, offsetDelta, stopAtOffset) {
var inArray = currentParent === 1 /* Array */;
type =
lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
if (scanner.getTokenError() != 2) {
lastWasColon = false;
}
lastWasColon = false;
break;
case 11 /* NumericLiteral */:
type = TOKEN_VALUE_NUMBER;
Expand Down