vscode-json-languageservice 3.3.0-next.7 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- NEXT
1
+ 3.3.3 / 2019-0829
2
+ =================
3
+ Schemas can configure wheter comments and/or trailing are permitted.
4
+
5
+ 3.3.0 / 2019-06-12
2
6
  ==================
3
7
  * New API `LanguageService.getSelectionRanges` to get semantic selection ranges.
4
8
  * Manage schema dependencies so that `resetSchema` also resets schemas that depend on the schema.
@@ -22,6 +22,6 @@ export interface LanguageService {
22
22
  getFoldingRanges(document: TextDocument, context?: {
23
23
  rangeLimit?: number;
24
24
  }): FoldingRange[];
25
- getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[][];
25
+ getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
26
26
  }
27
27
  export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
@@ -1,40 +1,7 @@
1
1
  import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
2
2
  import { JSONSchema } from './jsonSchema';
3
- import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind } from 'vscode-languageserver-types';
4
- export { Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind };
5
- /**
6
- * Enum of known selection range kinds
7
- */
8
- export declare enum SelectionRangeKind {
9
- /**
10
- * Empty Kind.
11
- */
12
- Empty = "",
13
- /**
14
- * The statment kind, its value is `statement`, possible extensions can be
15
- * `statement.if` etc
16
- */
17
- Statement = "statement",
18
- /**
19
- * The declaration kind, its value is `declaration`, possible extensions can be
20
- * `declaration.function`, `declaration.class` etc.
21
- */
22
- Declaration = "declaration"
23
- }
24
- /**
25
- * Represents a selection range
26
- */
27
- export interface SelectionRange {
28
- /**
29
- * Range of the selection.
30
- */
31
- range: Range;
32
- /**
33
- * Describes the kind of the selection range such as `statemet' or 'declaration'. See
34
- * [SelectionRangeKind](#SelectionRangeKind) for an enumeration of standardized kinds.
35
- */
36
- kind: string;
37
- }
3
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange } from 'vscode-languageserver-types';
4
+ export { Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange };
38
5
  /**
39
6
  * Error codes used by diagnostics
40
7
  */
@@ -1,27 +1,5 @@
1
- import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind } from 'vscode-languageserver-types';
2
- export { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind };
3
- // #region Proposed types, remove once added to vscode-languageserver-types
4
- /**
5
- * Enum of known selection range kinds
6
- */
7
- export var SelectionRangeKind;
8
- (function (SelectionRangeKind) {
9
- /**
10
- * Empty Kind.
11
- */
12
- SelectionRangeKind["Empty"] = "";
13
- /**
14
- * The statment kind, its value is `statement`, possible extensions can be
15
- * `statement.if` etc
16
- */
17
- SelectionRangeKind["Statement"] = "statement";
18
- /**
19
- * The declaration kind, its value is `declaration`, possible extensions can be
20
- * `declaration.function`, `declaration.class` etc.
21
- */
22
- SelectionRangeKind["Declaration"] = "declaration";
23
- })(SelectionRangeKind || (SelectionRangeKind = {}));
24
- // #endregion
1
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange } from 'vscode-languageserver-types';
2
+ export { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange };
25
3
  /**
26
4
  * Error codes used by diagnostics
27
5
  */
@@ -62,6 +62,7 @@ export interface JSONSchema {
62
62
  markdownDescription?: string;
63
63
  doNotSuggest?: boolean;
64
64
  allowComments?: boolean;
65
+ allowsTrailingCommas?: boolean;
65
66
  }
66
67
  export interface JSONSchemaMap {
67
68
  [name: string]: JSONSchemaRef;
@@ -19,11 +19,15 @@ import * as Json from 'jsonc-parser';
19
19
  import { isNumber, equals, isBoolean, isString, isDefined } from '../utils/objects';
20
20
  import { ErrorCode } from '../jsonLanguageTypes';
21
21
  import * as nls from 'vscode-nls';
22
- import Uri from 'vscode-uri';
23
22
  import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types';
24
23
  var localize = nls.loadMessageBundle();
25
- var colorHexPattern = /^#([0-9A-Fa-f]{3,4}|([0-9A-Fa-f]{2}){3,4})$/;
26
- var emailPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
24
+ var formats = {
25
+ 'color-hex': { errorMessage: localize('colorHexFormatWarning', 'Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.'), pattern: /^#([0-9A-Fa-f]{3,4}|([0-9A-Fa-f]{2}){3,4})$/ },
26
+ 'date-time': { errorMessage: localize('dateTimeFormatWarning', 'String is not a RFC3339 date-time.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
27
+ 'date': { errorMessage: localize('dateFormatWarning', 'String is not a RFC3339 date.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/i },
28
+ 'time': { errorMessage: localize('timeFormatWarning', 'String is not a RFC3339 time.'), pattern: /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
29
+ 'email': { errorMessage: localize('emailFormatWarning', 'String is not an e-mail address.'), pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ }
30
+ };
27
31
  var ASTNodeImpl = /** @class */ (function () {
28
32
  function ASTNodeImpl(parent, offset, length) {
29
33
  this.offset = offset;
@@ -612,14 +616,12 @@ function validate(node, schema, validationResult, matchingSchemas) {
612
616
  errorMessage = localize('uriEmpty', 'URI expected.');
613
617
  }
614
618
  else {
615
- try {
616
- var uri = Uri.parse(node.value);
617
- if (!uri.scheme && schema.format === 'uri') {
618
- errorMessage = localize('uriSchemeMissing', 'URI with a scheme is expected.');
619
- }
619
+ var match = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(node.value);
620
+ if (!match) {
621
+ errorMessage = localize('uriMissing', 'URI is expected.');
620
622
  }
621
- catch (e) {
622
- errorMessage = e.message;
623
+ else if (!match[2] && schema.format === 'uri') {
624
+ errorMessage = localize('uriSchemeMissing', 'URI with a scheme is expected.');
623
625
  }
624
626
  }
625
627
  if (errorMessage) {
@@ -631,28 +633,19 @@ function validate(node, schema, validationResult, matchingSchemas) {
631
633
  }
632
634
  }
633
635
  break;
634
- case 'email':
635
- {
636
- if (!node.value.match(emailPattern)) {
637
- validationResult.problems.push({
638
- location: { offset: node.offset, length: node.length },
639
- severity: DiagnosticSeverity.Warning,
640
- message: schema.patternErrorMessage || schema.errorMessage || localize('emailFormatWarning', 'String is not an e-mail address.')
641
- });
642
- }
643
- }
644
- break;
645
636
  case 'color-hex':
646
- {
647
- if (!node.value.match(colorHexPattern)) {
648
- validationResult.problems.push({
649
- location: { offset: node.offset, length: node.length },
650
- severity: DiagnosticSeverity.Warning,
651
- message: schema.patternErrorMessage || schema.errorMessage || localize('colorHexFormatWarning', 'Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.')
652
- });
653
- }
637
+ case 'date-time':
638
+ case 'date':
639
+ case 'time':
640
+ case 'email':
641
+ var format = formats[schema.format];
642
+ if (!node.value || !format.pattern.exec(node.value)) {
643
+ validationResult.problems.push({
644
+ location: { offset: node.offset, length: node.length },
645
+ severity: DiagnosticSeverity.Warning,
646
+ message: schema.patternErrorMessage || schema.errorMessage || format.errorMessage
647
+ });
654
648
  }
655
- break;
656
649
  default:
657
650
  }
658
651
  }
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import * as Json from 'jsonc-parser';
6
- import URI from 'vscode-uri';
6
+ import { URI } from 'vscode-uri';
7
7
  import * as Strings from '../utils/strings';
8
8
  import * as Parser from '../parser/jsonParser';
9
9
  import * as nls from 'vscode-nls';
@@ -170,7 +170,12 @@ var JSONSchemaService = /** @class */ (function () {
170
170
  };
171
171
  JSONSchemaService.prototype.normalizeId = function (id) {
172
172
  // remove trailing '#', normalize drive capitalization
173
- return URI.parse(id).toString();
173
+ try {
174
+ return URI.parse(id).toString();
175
+ }
176
+ catch (e) {
177
+ return id;
178
+ }
174
179
  };
175
180
  JSONSchemaService.prototype.setSchemaContributions = function (schemaContributions) {
176
181
  if (schemaContributions.schemas) {
@@ -2,16 +2,12 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License. See License.txt in the project root for license information.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { Range } from 'vscode-languageserver-types';
5
+ import { Range, SelectionRange } from 'vscode-languageserver-types';
6
6
  import { createScanner } from 'jsonc-parser';
7
- import { SelectionRangeKind } from '../jsonLanguageTypes';
8
7
  export function getSelectionRanges(document, positions, doc) {
9
8
  function getSelectionRange(position) {
10
9
  var offset = document.offsetAt(position);
11
10
  var node = doc.getNodeFromOffset(offset, true);
12
- if (!node) {
13
- return [];
14
- }
15
11
  var result = [];
16
12
  while (node) {
17
13
  switch (node.type) {
@@ -40,13 +36,17 @@ export function getSelectionRanges(document, positions, doc) {
40
36
  }
41
37
  node = node.parent;
42
38
  }
43
- return result;
39
+ var current = undefined;
40
+ for (var index = result.length - 1; index >= 0; index--) {
41
+ current = SelectionRange.create(result[index], current);
42
+ }
43
+ if (!current) {
44
+ current = SelectionRange.create(Range.create(position, position));
45
+ }
46
+ return current;
44
47
  }
45
48
  function newRange(start, end) {
46
- return {
47
- range: Range.create(document.positionAt(start), document.positionAt(end)),
48
- kind: SelectionRangeKind.Declaration
49
- };
49
+ return Range.create(document.positionAt(start), document.positionAt(end));
50
50
  }
51
51
  var scanner = createScanner(document.getText(), true);
52
52
  function getOffsetAfterNextToken(offset, expectedToken) {
@@ -6,6 +6,7 @@ import { UnresolvedSchema } from './jsonSchemaService';
6
6
  import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver-types';
7
7
  import { ErrorCode } from '../jsonLanguageTypes';
8
8
  import * as nls from 'vscode-nls';
9
+ import { isBoolean } from '../utils/objects';
9
10
  var localize = nls.loadMessageBundle();
10
11
  var JSONValidation = /** @class */ (function () {
11
12
  function JSONValidation(jsonSchemaService, promiseConstructor) {
@@ -58,7 +59,10 @@ var JSONValidation = /** @class */ (function () {
58
59
  }
59
60
  }
60
61
  if (schemaAllowsComments(schema.schema)) {
61
- trailingCommaSeverity = commentSeverity = void 0;
62
+ commentSeverity = void 0;
63
+ }
64
+ if (schemaAllowsTrailingCommas(schema.schema)) {
65
+ trailingCommaSeverity = void 0;
62
66
  }
63
67
  }
64
68
  for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
@@ -95,14 +99,37 @@ export { JSONValidation };
95
99
  var idCounter = 0;
96
100
  function schemaAllowsComments(schemaRef) {
97
101
  if (schemaRef && typeof schemaRef === 'object') {
98
- if (schemaRef.allowComments) {
99
- return true;
102
+ if (isBoolean(schemaRef.allowComments)) {
103
+ return schemaRef.allowComments;
100
104
  }
101
105
  if (schemaRef.allOf) {
102
- return schemaRef.allOf.some(schemaAllowsComments);
106
+ for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
107
+ var schema = _a[_i];
108
+ var allow = schemaAllowsComments(schema);
109
+ if (isBoolean(allow)) {
110
+ return allow;
111
+ }
112
+ }
113
+ }
114
+ }
115
+ return undefined;
116
+ }
117
+ function schemaAllowsTrailingCommas(schemaRef) {
118
+ if (schemaRef && typeof schemaRef === 'object') {
119
+ if (isBoolean(schemaRef.allowsTrailingCommas)) {
120
+ return schemaRef.allowsTrailingCommas;
121
+ }
122
+ if (schemaRef.allOf) {
123
+ for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
124
+ var schema = _a[_i];
125
+ var allow = schemaAllowsTrailingCommas(schema);
126
+ if (isBoolean(allow)) {
127
+ return allow;
128
+ }
129
+ }
103
130
  }
104
131
  }
105
- return false;
132
+ return undefined;
106
133
  }
107
134
  function toDiagnosticSeverity(severityLevel) {
108
135
  switch (severityLevel) {
@@ -22,6 +22,6 @@ export interface LanguageService {
22
22
  getFoldingRanges(document: TextDocument, context?: {
23
23
  rangeLimit?: number;
24
24
  }): FoldingRange[];
25
- getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[][];
25
+ getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
26
26
  }
27
27
  export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
@@ -1,40 +1,7 @@
1
1
  import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
2
2
  import { JSONSchema } from './jsonSchema';
3
- import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind } from 'vscode-languageserver-types';
4
- export { Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind };
5
- /**
6
- * Enum of known selection range kinds
7
- */
8
- export declare enum SelectionRangeKind {
9
- /**
10
- * Empty Kind.
11
- */
12
- Empty = "",
13
- /**
14
- * The statment kind, its value is `statement`, possible extensions can be
15
- * `statement.if` etc
16
- */
17
- Statement = "statement",
18
- /**
19
- * The declaration kind, its value is `declaration`, possible extensions can be
20
- * `declaration.function`, `declaration.class` etc.
21
- */
22
- Declaration = "declaration"
23
- }
24
- /**
25
- * Represents a selection range
26
- */
27
- export interface SelectionRange {
28
- /**
29
- * Range of the selection.
30
- */
31
- range: Range;
32
- /**
33
- * Describes the kind of the selection range such as `statemet' or 'declaration'. See
34
- * [SelectionRangeKind](#SelectionRangeKind) for an enumeration of standardized kinds.
35
- */
36
- kind: string;
37
- }
3
+ import { Range, TextEdit, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, MarkupKind, SelectionRange } from 'vscode-languageserver-types';
4
+ export { Range, TextEdit, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange };
38
5
  /**
39
6
  * Error codes used by diagnostics
40
7
  */
@@ -17,28 +17,7 @@
17
17
  exports.ColorPresentation = vscode_languageserver_types_1.ColorPresentation;
18
18
  exports.FoldingRange = vscode_languageserver_types_1.FoldingRange;
19
19
  exports.FoldingRangeKind = vscode_languageserver_types_1.FoldingRangeKind;
20
- // #region Proposed types, remove once added to vscode-languageserver-types
21
- /**
22
- * Enum of known selection range kinds
23
- */
24
- var SelectionRangeKind;
25
- (function (SelectionRangeKind) {
26
- /**
27
- * Empty Kind.
28
- */
29
- SelectionRangeKind["Empty"] = "";
30
- /**
31
- * The statment kind, its value is `statement`, possible extensions can be
32
- * `statement.if` etc
33
- */
34
- SelectionRangeKind["Statement"] = "statement";
35
- /**
36
- * The declaration kind, its value is `declaration`, possible extensions can be
37
- * `declaration.function`, `declaration.class` etc.
38
- */
39
- SelectionRangeKind["Declaration"] = "declaration";
40
- })(SelectionRangeKind = exports.SelectionRangeKind || (exports.SelectionRangeKind = {}));
41
- // #endregion
20
+ exports.SelectionRange = vscode_languageserver_types_1.SelectionRange;
42
21
  /**
43
22
  * Error codes used by diagnostics
44
23
  */
@@ -62,6 +62,7 @@ export interface JSONSchema {
62
62
  markdownDescription?: string;
63
63
  doNotSuggest?: boolean;
64
64
  allowComments?: boolean;
65
+ allowsTrailingCommas?: boolean;
65
66
  }
66
67
  export interface JSONSchemaMap {
67
68
  [name: string]: JSONSchemaRef;
@@ -21,7 +21,7 @@ var __extends = (this && this.__extends) || (function () {
21
21
  if (v !== undefined) module.exports = v;
22
22
  }
23
23
  else if (typeof define === "function" && define.amd) {
24
- define(["require", "exports", "jsonc-parser", "../utils/objects", "../jsonLanguageTypes", "vscode-nls", "vscode-uri", "vscode-languageserver-types"], factory);
24
+ define(["require", "exports", "jsonc-parser", "../utils/objects", "../jsonLanguageTypes", "vscode-nls", "vscode-languageserver-types"], factory);
25
25
  }
26
26
  })(function (require, exports) {
27
27
  "use strict";
@@ -30,11 +30,15 @@ var __extends = (this && this.__extends) || (function () {
30
30
  var objects_1 = require("../utils/objects");
31
31
  var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
32
32
  var nls = require("vscode-nls");
33
- var vscode_uri_1 = require("vscode-uri");
34
33
  var vscode_languageserver_types_1 = require("vscode-languageserver-types");
35
34
  var localize = nls.loadMessageBundle();
36
- var colorHexPattern = /^#([0-9A-Fa-f]{3,4}|([0-9A-Fa-f]{2}){3,4})$/;
37
- var emailPattern = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
35
+ var formats = {
36
+ 'color-hex': { errorMessage: localize('colorHexFormatWarning', 'Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.'), pattern: /^#([0-9A-Fa-f]{3,4}|([0-9A-Fa-f]{2}){3,4})$/ },
37
+ 'date-time': { errorMessage: localize('dateTimeFormatWarning', 'String is not a RFC3339 date-time.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
38
+ 'date': { errorMessage: localize('dateFormatWarning', 'String is not a RFC3339 date.'), pattern: /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/i },
39
+ 'time': { errorMessage: localize('timeFormatWarning', 'String is not a RFC3339 time.'), pattern: /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)([01][0-9]|2[0-3]):([0-5][0-9]))$/i },
40
+ 'email': { errorMessage: localize('emailFormatWarning', 'String is not an e-mail address.'), pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ }
41
+ };
38
42
  var ASTNodeImpl = /** @class */ (function () {
39
43
  function ASTNodeImpl(parent, offset, length) {
40
44
  this.offset = offset;
@@ -628,14 +632,12 @@ var __extends = (this && this.__extends) || (function () {
628
632
  errorMessage = localize('uriEmpty', 'URI expected.');
629
633
  }
630
634
  else {
631
- try {
632
- var uri = vscode_uri_1.default.parse(node.value);
633
- if (!uri.scheme && schema.format === 'uri') {
634
- errorMessage = localize('uriSchemeMissing', 'URI with a scheme is expected.');
635
- }
635
+ var match = /^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/.exec(node.value);
636
+ if (!match) {
637
+ errorMessage = localize('uriMissing', 'URI is expected.');
636
638
  }
637
- catch (e) {
638
- errorMessage = e.message;
639
+ else if (!match[2] && schema.format === 'uri') {
640
+ errorMessage = localize('uriSchemeMissing', 'URI with a scheme is expected.');
639
641
  }
640
642
  }
641
643
  if (errorMessage) {
@@ -647,28 +649,19 @@ var __extends = (this && this.__extends) || (function () {
647
649
  }
648
650
  }
649
651
  break;
650
- case 'email':
651
- {
652
- if (!node.value.match(emailPattern)) {
653
- validationResult.problems.push({
654
- location: { offset: node.offset, length: node.length },
655
- severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
656
- message: schema.patternErrorMessage || schema.errorMessage || localize('emailFormatWarning', 'String is not an e-mail address.')
657
- });
658
- }
659
- }
660
- break;
661
652
  case 'color-hex':
662
- {
663
- if (!node.value.match(colorHexPattern)) {
664
- validationResult.problems.push({
665
- location: { offset: node.offset, length: node.length },
666
- severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
667
- message: schema.patternErrorMessage || schema.errorMessage || localize('colorHexFormatWarning', 'Invalid color format. Use #RGB, #RGBA, #RRGGBB or #RRGGBBAA.')
668
- });
669
- }
653
+ case 'date-time':
654
+ case 'date':
655
+ case 'time':
656
+ case 'email':
657
+ var format = formats[schema.format];
658
+ if (!node.value || !format.pattern.exec(node.value)) {
659
+ validationResult.problems.push({
660
+ location: { offset: node.offset, length: node.length },
661
+ severity: vscode_languageserver_types_1.DiagnosticSeverity.Warning,
662
+ message: schema.patternErrorMessage || schema.errorMessage || format.errorMessage
663
+ });
670
664
  }
671
- break;
672
665
  default:
673
666
  }
674
667
  }
@@ -141,7 +141,7 @@
141
141
  }
142
142
  JSONSchemaService.prototype.getRegisteredSchemaIds = function (filter) {
143
143
  return Object.keys(this.registeredSchemasIds).filter(function (id) {
144
- var scheme = vscode_uri_1.default.parse(id).scheme;
144
+ var scheme = vscode_uri_1.URI.parse(id).scheme;
145
145
  return scheme !== 'schemaservice' && (!filter || filter(scheme));
146
146
  });
147
147
  };
@@ -181,7 +181,12 @@
181
181
  };
182
182
  JSONSchemaService.prototype.normalizeId = function (id) {
183
183
  // remove trailing '#', normalize drive capitalization
184
- return vscode_uri_1.default.parse(id).toString();
184
+ try {
185
+ return vscode_uri_1.URI.parse(id).toString();
186
+ }
187
+ catch (e) {
188
+ return id;
189
+ }
185
190
  };
186
191
  JSONSchemaService.prototype.setSchemaContributions = function (schemaContributions) {
187
192
  if (schemaContributions.schemas) {
@@ -470,7 +475,7 @@
470
475
  exports.JSONSchemaService = JSONSchemaService;
471
476
  function toDisplayString(url) {
472
477
  try {
473
- var uri = vscode_uri_1.default.parse(url);
478
+ var uri = vscode_uri_1.URI.parse(url);
474
479
  if (uri.scheme === 'file') {
475
480
  return uri.fsPath;
476
481
  }
@@ -8,21 +8,17 @@
8
8
  if (v !== undefined) module.exports = v;
9
9
  }
10
10
  else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "vscode-languageserver-types", "jsonc-parser", "../jsonLanguageTypes"], factory);
11
+ define(["require", "exports", "vscode-languageserver-types", "jsonc-parser"], factory);
12
12
  }
13
13
  })(function (require, exports) {
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  var vscode_languageserver_types_1 = require("vscode-languageserver-types");
17
17
  var jsonc_parser_1 = require("jsonc-parser");
18
- var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
19
18
  function getSelectionRanges(document, positions, doc) {
20
19
  function getSelectionRange(position) {
21
20
  var offset = document.offsetAt(position);
22
21
  var node = doc.getNodeFromOffset(offset, true);
23
- if (!node) {
24
- return [];
25
- }
26
22
  var result = [];
27
23
  while (node) {
28
24
  switch (node.type) {
@@ -51,13 +47,17 @@
51
47
  }
52
48
  node = node.parent;
53
49
  }
54
- return result;
50
+ var current = undefined;
51
+ for (var index = result.length - 1; index >= 0; index--) {
52
+ current = vscode_languageserver_types_1.SelectionRange.create(result[index], current);
53
+ }
54
+ if (!current) {
55
+ current = vscode_languageserver_types_1.SelectionRange.create(vscode_languageserver_types_1.Range.create(position, position));
56
+ }
57
+ return current;
55
58
  }
56
59
  function newRange(start, end) {
57
- return {
58
- range: vscode_languageserver_types_1.Range.create(document.positionAt(start), document.positionAt(end)),
59
- kind: jsonLanguageTypes_1.SelectionRangeKind.Declaration
60
- };
60
+ return vscode_languageserver_types_1.Range.create(document.positionAt(start), document.positionAt(end));
61
61
  }
62
62
  var scanner = jsonc_parser_1.createScanner(document.getText(), true);
63
63
  function getOffsetAfterNextToken(offset, expectedToken) {
@@ -8,7 +8,7 @@
8
8
  if (v !== undefined) module.exports = v;
9
9
  }
10
10
  else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "./jsonSchemaService", "vscode-languageserver-types", "../jsonLanguageTypes", "vscode-nls"], factory);
11
+ define(["require", "exports", "./jsonSchemaService", "vscode-languageserver-types", "../jsonLanguageTypes", "vscode-nls", "../utils/objects"], factory);
12
12
  }
13
13
  })(function (require, exports) {
14
14
  "use strict";
@@ -17,6 +17,7 @@
17
17
  var vscode_languageserver_types_1 = require("vscode-languageserver-types");
18
18
  var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
19
19
  var nls = require("vscode-nls");
20
+ var objects_1 = require("../utils/objects");
20
21
  var localize = nls.loadMessageBundle();
21
22
  var JSONValidation = /** @class */ (function () {
22
23
  function JSONValidation(jsonSchemaService, promiseConstructor) {
@@ -69,7 +70,10 @@
69
70
  }
70
71
  }
71
72
  if (schemaAllowsComments(schema.schema)) {
72
- trailingCommaSeverity = commentSeverity = void 0;
73
+ commentSeverity = void 0;
74
+ }
75
+ if (schemaAllowsTrailingCommas(schema.schema)) {
76
+ trailingCommaSeverity = void 0;
73
77
  }
74
78
  }
75
79
  for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
@@ -106,14 +110,37 @@
106
110
  var idCounter = 0;
107
111
  function schemaAllowsComments(schemaRef) {
108
112
  if (schemaRef && typeof schemaRef === 'object') {
109
- if (schemaRef.allowComments) {
110
- return true;
113
+ if (objects_1.isBoolean(schemaRef.allowComments)) {
114
+ return schemaRef.allowComments;
111
115
  }
112
116
  if (schemaRef.allOf) {
113
- return schemaRef.allOf.some(schemaAllowsComments);
117
+ for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
118
+ var schema = _a[_i];
119
+ var allow = schemaAllowsComments(schema);
120
+ if (objects_1.isBoolean(allow)) {
121
+ return allow;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ return undefined;
127
+ }
128
+ function schemaAllowsTrailingCommas(schemaRef) {
129
+ if (schemaRef && typeof schemaRef === 'object') {
130
+ if (objects_1.isBoolean(schemaRef.allowsTrailingCommas)) {
131
+ return schemaRef.allowsTrailingCommas;
132
+ }
133
+ if (schemaRef.allOf) {
134
+ for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
135
+ var schema = _a[_i];
136
+ var allow = schemaAllowsTrailingCommas(schema);
137
+ if (objects_1.isBoolean(allow)) {
138
+ return allow;
139
+ }
140
+ }
114
141
  }
115
142
  }
116
- return false;
143
+ return undefined;
117
144
  }
118
145
  function toDiagnosticSeverity(severityLevel) {
119
146
  switch (severityLevel) {