vscode-json-languageservice 4.2.0 → 5.1.0

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/jsonLanguageService.js +22 -22
  4. package/lib/esm/jsonLanguageTypes.d.ts +3 -1
  5. package/lib/esm/jsonLanguageTypes.js +3 -2
  6. package/lib/esm/jsonSchema.d.ts +21 -2
  7. package/lib/esm/parser/jsonParser.js +488 -488
  8. package/lib/esm/services/configuration.js +9 -9
  9. package/lib/esm/services/jsonCompletion.js +280 -290
  10. package/lib/esm/services/jsonDocumentSymbols.js +88 -99
  11. package/lib/esm/services/jsonFolding.js +38 -39
  12. package/lib/esm/services/jsonHover.js +40 -43
  13. package/lib/esm/services/jsonLinks.js +12 -13
  14. package/lib/esm/services/jsonSchemaService.js +234 -253
  15. package/lib/esm/services/jsonSelectionRanges.js +9 -9
  16. package/lib/esm/services/jsonValidation.js +53 -51
  17. package/lib/esm/utils/colors.js +7 -8
  18. package/lib/esm/utils/glob.js +12 -12
  19. package/lib/esm/utils/json.js +7 -7
  20. package/lib/esm/utils/objects.js +3 -0
  21. package/lib/esm/utils/strings.js +3 -3
  22. package/lib/umd/jsonLanguageService.js +36 -32
  23. package/lib/umd/jsonLanguageTypes.d.ts +3 -1
  24. package/lib/umd/jsonLanguageTypes.js +5 -3
  25. package/lib/umd/jsonSchema.d.ts +21 -2
  26. package/lib/umd/parser/jsonParser.js +492 -482
  27. package/lib/umd/services/configuration.js +9 -9
  28. package/lib/umd/services/jsonCompletion.js +287 -296
  29. package/lib/umd/services/jsonDocumentSymbols.js +92 -102
  30. package/lib/umd/services/jsonFolding.js +40 -41
  31. package/lib/umd/services/jsonHover.js +42 -44
  32. package/lib/umd/services/jsonLinks.js +13 -14
  33. package/lib/umd/services/jsonSchemaService.js +241 -257
  34. package/lib/umd/services/jsonSelectionRanges.js +11 -11
  35. package/lib/umd/services/jsonValidation.js +56 -53
  36. package/lib/umd/utils/colors.js +7 -8
  37. package/lib/umd/utils/glob.js +12 -12
  38. package/lib/umd/utils/json.js +7 -7
  39. package/lib/umd/utils/objects.js +5 -1
  40. package/lib/umd/utils/strings.js +3 -3
  41. package/package.json +12 -12
@@ -6,16 +6,16 @@ import { Range, SelectionRange } from '../jsonLanguageTypes';
6
6
  import { createScanner } from 'jsonc-parser';
7
7
  export function getSelectionRanges(document, positions, doc) {
8
8
  function getSelectionRange(position) {
9
- var offset = document.offsetAt(position);
10
- var node = doc.getNodeFromOffset(offset, true);
11
- var result = [];
9
+ let offset = document.offsetAt(position);
10
+ let node = doc.getNodeFromOffset(offset, true);
11
+ const result = [];
12
12
  while (node) {
13
13
  switch (node.type) {
14
14
  case 'string':
15
15
  case 'object':
16
16
  case 'array':
17
17
  // range without ", [ or {
18
- var cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
18
+ const cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
19
19
  if (cStart < cEnd && offset >= cStart && offset <= cEnd) {
20
20
  result.push(newRange(cStart, cEnd));
21
21
  }
@@ -29,15 +29,15 @@ export function getSelectionRanges(document, positions, doc) {
29
29
  break;
30
30
  }
31
31
  if (node.type === 'property' || node.parent && node.parent.type === 'array') {
32
- var afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, 5 /* CommaToken */);
32
+ const afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, 5 /* SyntaxKind.CommaToken */);
33
33
  if (afterCommaOffset !== -1) {
34
34
  result.push(newRange(node.offset, afterCommaOffset));
35
35
  }
36
36
  }
37
37
  node = node.parent;
38
38
  }
39
- var current = undefined;
40
- for (var index = result.length - 1; index >= 0; index--) {
39
+ let current = undefined;
40
+ for (let index = result.length - 1; index >= 0; index--) {
41
41
  current = SelectionRange.create(result[index], current);
42
42
  }
43
43
  if (!current) {
@@ -48,10 +48,10 @@ export function getSelectionRanges(document, positions, doc) {
48
48
  function newRange(start, end) {
49
49
  return Range.create(document.positionAt(start), document.positionAt(end));
50
50
  }
51
- var scanner = createScanner(document.getText(), true);
51
+ const scanner = createScanner(document.getText(), true);
52
52
  function getOffsetAfterNextToken(offset, expectedToken) {
53
53
  scanner.setPosition(offset);
54
- var token = scanner.scan();
54
+ let token = scanner.scan();
55
55
  if (token === expectedToken) {
56
56
  return scanner.getTokenOffset() + scanner.getTokenLength();
57
57
  }
@@ -5,55 +5,62 @@
5
5
  import { ErrorCode, Diagnostic, DiagnosticSeverity, Range } from '../jsonLanguageTypes';
6
6
  import * as nls from 'vscode-nls';
7
7
  import { isBoolean } from '../utils/objects';
8
- var localize = nls.loadMessageBundle();
9
- var JSONValidation = /** @class */ (function () {
10
- function JSONValidation(jsonSchemaService, promiseConstructor) {
8
+ const localize = nls.loadMessageBundle();
9
+ export class JSONValidation {
10
+ constructor(jsonSchemaService, promiseConstructor) {
11
11
  this.jsonSchemaService = jsonSchemaService;
12
12
  this.promise = promiseConstructor;
13
13
  this.validationEnabled = true;
14
14
  }
15
- JSONValidation.prototype.configure = function (raw) {
15
+ configure(raw) {
16
16
  if (raw) {
17
17
  this.validationEnabled = raw.validate !== false;
18
18
  this.commentSeverity = raw.allowComments ? undefined : DiagnosticSeverity.Error;
19
19
  }
20
- };
21
- JSONValidation.prototype.doValidation = function (textDocument, jsonDocument, documentSettings, schema) {
22
- var _this = this;
20
+ }
21
+ doValidation(textDocument, jsonDocument, documentSettings, schema) {
23
22
  if (!this.validationEnabled) {
24
23
  return this.promise.resolve([]);
25
24
  }
26
- var diagnostics = [];
27
- var added = {};
28
- var addProblem = function (problem) {
25
+ const diagnostics = [];
26
+ const added = {};
27
+ const addProblem = (problem) => {
29
28
  // remove duplicated messages
30
- var signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
29
+ const signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
31
30
  if (!added[signature]) {
32
31
  added[signature] = true;
33
32
  diagnostics.push(problem);
34
33
  }
35
34
  };
36
- var getDiagnostics = function (schema) {
37
- var trailingCommaSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.trailingCommas) ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
38
- var commentSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.comments) ? toDiagnosticSeverity(documentSettings.comments) : _this.commentSeverity;
39
- var schemaValidation = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaValidation) ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
40
- var schemaRequest = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaRequest) ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
35
+ const getDiagnostics = (schema) => {
36
+ let trailingCommaSeverity = documentSettings?.trailingCommas ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
37
+ let commentSeverity = documentSettings?.comments ? toDiagnosticSeverity(documentSettings.comments) : this.commentSeverity;
38
+ let schemaValidation = documentSettings?.schemaValidation ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
39
+ let schemaRequest = documentSettings?.schemaRequest ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
41
40
  if (schema) {
42
- if (schema.errors.length && jsonDocument.root && schemaRequest) {
43
- var astRoot = jsonDocument.root;
44
- var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
45
- if (property && property.keyNode.value === '$schema') {
46
- var node = property.valueNode || property;
47
- var range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
48
- addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
49
- }
50
- else {
51
- var range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
52
- addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
41
+ const addSchemaProblem = (errorMessage, errorCode) => {
42
+ if (jsonDocument.root && schemaRequest) {
43
+ const astRoot = jsonDocument.root;
44
+ const property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
45
+ if (property && property.keyNode.value === '$schema') {
46
+ const node = property.valueNode || property;
47
+ const range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
48
+ addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
49
+ }
50
+ else {
51
+ const range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
52
+ addProblem(Diagnostic.create(range, errorMessage, schemaRequest, errorCode));
53
+ }
53
54
  }
55
+ };
56
+ if (schema.errors.length) {
57
+ addSchemaProblem(schema.errors[0], ErrorCode.SchemaResolveError);
54
58
  }
55
59
  else if (schemaValidation) {
56
- var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
60
+ for (const warning of schema.warnings) {
61
+ addSchemaProblem(warning, ErrorCode.SchemaUnsupportedFeature);
62
+ }
63
+ const semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
57
64
  if (semanticErrors) {
58
65
  semanticErrors.forEach(addProblem);
59
66
  }
@@ -65,8 +72,7 @@ var JSONValidation = /** @class */ (function () {
65
72
  trailingCommaSeverity = undefined;
66
73
  }
67
74
  }
68
- for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
69
- var p = _a[_i];
75
+ for (const p of jsonDocument.syntaxErrors) {
70
76
  if (p.code === ErrorCode.TrailingComma) {
71
77
  if (typeof trailingCommaSeverity !== 'number') {
72
78
  continue;
@@ -76,40 +82,37 @@ var JSONValidation = /** @class */ (function () {
76
82
  addProblem(p);
77
83
  }
78
84
  if (typeof commentSeverity === 'number') {
79
- var message_1 = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
80
- jsonDocument.comments.forEach(function (c) {
81
- addProblem(Diagnostic.create(c, message_1, commentSeverity, ErrorCode.CommentNotPermitted));
85
+ const message = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
86
+ jsonDocument.comments.forEach(c => {
87
+ addProblem(Diagnostic.create(c, message, commentSeverity, ErrorCode.CommentNotPermitted));
82
88
  });
83
89
  }
84
90
  return diagnostics;
85
91
  };
86
92
  if (schema) {
87
- var id = schema.id || ('schemaservice://untitled/' + idCounter++);
88
- var handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
89
- return handle.getResolvedSchema().then(function (resolvedSchema) {
93
+ const id = schema.id || ('schemaservice://untitled/' + idCounter++);
94
+ const handle = this.jsonSchemaService.registerExternalSchema(id, [], schema);
95
+ return handle.getResolvedSchema().then(resolvedSchema => {
90
96
  return getDiagnostics(resolvedSchema);
91
97
  });
92
98
  }
93
- return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(function (schema) {
99
+ return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(schema => {
94
100
  return getDiagnostics(schema);
95
101
  });
96
- };
97
- JSONValidation.prototype.getLanguageStatus = function (textDocument, jsonDocument) {
102
+ }
103
+ getLanguageStatus(textDocument, jsonDocument) {
98
104
  return { schemas: this.jsonSchemaService.getSchemaURIsForResource(textDocument.uri, jsonDocument) };
99
- };
100
- return JSONValidation;
101
- }());
102
- export { JSONValidation };
103
- var idCounter = 0;
105
+ }
106
+ }
107
+ let idCounter = 0;
104
108
  function schemaAllowsComments(schemaRef) {
105
109
  if (schemaRef && typeof schemaRef === 'object') {
106
110
  if (isBoolean(schemaRef.allowComments)) {
107
111
  return schemaRef.allowComments;
108
112
  }
109
113
  if (schemaRef.allOf) {
110
- for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
111
- var schema = _a[_i];
112
- var allow = schemaAllowsComments(schema);
114
+ for (const schema of schemaRef.allOf) {
115
+ const allow = schemaAllowsComments(schema);
113
116
  if (isBoolean(allow)) {
114
117
  return allow;
115
118
  }
@@ -123,14 +126,13 @@ function schemaAllowsTrailingCommas(schemaRef) {
123
126
  if (isBoolean(schemaRef.allowTrailingCommas)) {
124
127
  return schemaRef.allowTrailingCommas;
125
128
  }
126
- var deprSchemaRef = schemaRef;
129
+ const deprSchemaRef = schemaRef;
127
130
  if (isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
128
131
  return deprSchemaRef['allowsTrailingCommas'];
129
132
  }
130
133
  if (schemaRef.allOf) {
131
- for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
132
- var schema = _a[_i];
133
- var allow = schemaAllowsTrailingCommas(schema);
134
+ for (const schema of schemaRef.allOf) {
135
+ const allow = schemaAllowsTrailingCommas(schema);
134
136
  if (isBoolean(allow)) {
135
137
  return allow;
136
138
  }
@@ -2,11 +2,11 @@
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
- var Digit0 = 48;
6
- var Digit9 = 57;
7
- var A = 65;
8
- var a = 97;
9
- var f = 102;
5
+ const Digit0 = 48;
6
+ const Digit9 = 57;
7
+ const A = 65;
8
+ const a = 97;
9
+ const f = 102;
10
10
  export function hexDigit(charCode) {
11
11
  if (charCode < Digit0) {
12
12
  return 0;
@@ -58,12 +58,11 @@ export function colorFromHex(text) {
58
58
  }
59
59
  return undefined;
60
60
  }
61
- export function colorFrom256RGB(red, green, blue, alpha) {
62
- if (alpha === void 0) { alpha = 1.0; }
61
+ export function colorFrom256RGB(red, green, blue, alpha = 1.0) {
63
62
  return {
64
63
  red: red / 255.0,
65
64
  green: green / 255.0,
66
65
  blue: blue / 255.0,
67
- alpha: alpha
66
+ alpha
68
67
  };
69
68
  }
@@ -7,13 +7,13 @@ export function createRegex(glob, opts) {
7
7
  if (typeof glob !== 'string') {
8
8
  throw new TypeError('Expected a string');
9
9
  }
10
- var str = String(glob);
10
+ const str = String(glob);
11
11
  // The regexp we are building, as a string.
12
- var reStr = "";
12
+ let reStr = "";
13
13
  // Whether we are matching so called "extended" globs (like bash) and should
14
14
  // support single character matching, matching ranges of characters, group
15
15
  // matching, etc.
16
- var extended = opts ? !!opts.extended : false;
16
+ const extended = opts ? !!opts.extended : false;
17
17
  // When globstar is _false_ (default), '/foo/*' is translated a regexp like
18
18
  // '^\/foo\/.*$' which will match any string beginning with '/foo/'
19
19
  // When globstar is _true_, '/foo/*' is translated to regexp like
@@ -23,14 +23,14 @@ export function createRegex(glob, opts) {
23
23
  // these will not '/foo/bar/baz', '/foo/bar/baz.txt'
24
24
  // Lastely, when globstar is _true_, '/foo/**' is equivelant to '/foo/*' when
25
25
  // globstar is _false_
26
- var globstar = opts ? !!opts.globstar : false;
26
+ const globstar = opts ? !!opts.globstar : false;
27
27
  // If we are doing extended matching, this boolean is true when we are inside
28
28
  // a group (eg {*.html,*.js}), and false otherwise.
29
- var inGroup = false;
29
+ let inGroup = false;
30
30
  // RegExp flags (eg "i" ) to pass in to RegExp constructor.
31
- var flags = opts && typeof (opts.flags) === "string" ? opts.flags : "";
32
- var c;
33
- for (var i = 0, len = str.length; i < len; i++) {
31
+ const flags = opts && typeof (opts.flags) === "string" ? opts.flags : "";
32
+ let c;
33
+ for (let i = 0, len = str.length; i < len; i++) {
34
34
  c = str[i];
35
35
  switch (c) {
36
36
  case "/":
@@ -78,20 +78,20 @@ export function createRegex(glob, opts) {
78
78
  case "*":
79
79
  // Move over all consecutive "*"'s.
80
80
  // Also store the previous and next characters
81
- var prevChar = str[i - 1];
82
- var starCount = 1;
81
+ const prevChar = str[i - 1];
82
+ let starCount = 1;
83
83
  while (str[i + 1] === "*") {
84
84
  starCount++;
85
85
  i++;
86
86
  }
87
- var nextChar = str[i + 1];
87
+ const nextChar = str[i + 1];
88
88
  if (!globstar) {
89
89
  // globstar is disabled, so treat any number of "*" as one
90
90
  reStr += ".*";
91
91
  }
92
92
  else {
93
93
  // globstar is enabled, so determine if this is a globstar segment
94
- var isGlobstar = starCount > 1 // multiple "*"'s
94
+ const isGlobstar = starCount > 1 // multiple "*"'s
95
95
  && (prevChar === "/" || prevChar === undefined || prevChar === '{' || prevChar === ',') // from the start of the segment
96
96
  && (nextChar === "/" || nextChar === undefined || nextChar === ',' || nextChar === '}'); // to the end of the segment
97
97
  if (isGlobstar) {
@@ -4,13 +4,13 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  export function stringifyObject(obj, indent, stringifyLiteral) {
6
6
  if (obj !== null && typeof obj === 'object') {
7
- var newIndent = indent + '\t';
7
+ const newIndent = indent + '\t';
8
8
  if (Array.isArray(obj)) {
9
9
  if (obj.length === 0) {
10
10
  return '[]';
11
11
  }
12
- var result = '[\n';
13
- for (var i = 0; i < obj.length; i++) {
12
+ let result = '[\n';
13
+ for (let i = 0; i < obj.length; i++) {
14
14
  result += newIndent + stringifyObject(obj[i], newIndent, stringifyLiteral);
15
15
  if (i < obj.length - 1) {
16
16
  result += ',';
@@ -21,13 +21,13 @@ export function stringifyObject(obj, indent, stringifyLiteral) {
21
21
  return result;
22
22
  }
23
23
  else {
24
- var keys = Object.keys(obj);
24
+ const keys = Object.keys(obj);
25
25
  if (keys.length === 0) {
26
26
  return '{}';
27
27
  }
28
- var result = '{\n';
29
- for (var i = 0; i < keys.length; i++) {
30
- var key = keys[i];
28
+ let result = '{\n';
29
+ for (let i = 0; i < keys.length; i++) {
30
+ const key = keys[i];
31
31
  result += newIndent + JSON.stringify(key) + ': ' + stringifyObject(obj[key], newIndent, stringifyLiteral);
32
32
  if (i < keys.length - 1) {
33
33
  result += ',';
@@ -63,3 +63,6 @@ export function isBoolean(val) {
63
63
  export function isString(val) {
64
64
  return typeof val === 'string';
65
65
  }
66
+ export function isObject(val) {
67
+ return typeof val === 'object' && val !== null && !Array.isArray(val);
68
+ }
@@ -6,7 +6,7 @@ export function startsWith(haystack, needle) {
6
6
  if (haystack.length < needle.length) {
7
7
  return false;
8
8
  }
9
- for (var i = 0; i < needle.length; i++) {
9
+ for (let i = 0; i < needle.length; i++) {
10
10
  if (haystack[i] !== needle[i]) {
11
11
  return false;
12
12
  }
@@ -17,7 +17,7 @@ export function startsWith(haystack, needle) {
17
17
  * Determines if haystack ends with needle.
18
18
  */
19
19
  export function endsWith(haystack, needle) {
20
- var diff = haystack.length - needle.length;
20
+ const diff = haystack.length - needle.length;
21
21
  if (diff > 0) {
22
22
  return haystack.lastIndexOf(needle) === diff;
23
23
  }
@@ -43,7 +43,7 @@ export function repeat(value, count) {
43
43
  return s;
44
44
  }
45
45
  export function extendedRegExp(pattern) {
46
- var flags = '';
46
+ let flags = '';
47
47
  if (startsWith(pattern, '(?i)')) {
48
48
  pattern = pattern.substring(4);
49
49
  flags = 'i';
@@ -4,7 +4,11 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
6
  if (k2 === undefined) k2 = k;
7
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
8
12
  }) : (function(o, m, k, k2) {
9
13
  if (k2 === undefined) k2 = k;
10
14
  o[k2] = m[k];
@@ -24,42 +28,42 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
28
  "use strict";
25
29
  Object.defineProperty(exports, "__esModule", { value: true });
26
30
  exports.getLanguageService = void 0;
27
- var jsonCompletion_1 = require("./services/jsonCompletion");
28
- var jsonHover_1 = require("./services/jsonHover");
29
- var jsonValidation_1 = require("./services/jsonValidation");
30
- var jsonDocumentSymbols_1 = require("./services/jsonDocumentSymbols");
31
- var jsonParser_1 = require("./parser/jsonParser");
32
- var configuration_1 = require("./services/configuration");
33
- var jsonSchemaService_1 = require("./services/jsonSchemaService");
34
- var jsonFolding_1 = require("./services/jsonFolding");
35
- var jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
36
- var jsonc_parser_1 = require("jsonc-parser");
37
- var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
38
- var jsonLinks_1 = require("./services/jsonLinks");
31
+ const jsonCompletion_1 = require("./services/jsonCompletion");
32
+ const jsonHover_1 = require("./services/jsonHover");
33
+ const jsonValidation_1 = require("./services/jsonValidation");
34
+ const jsonDocumentSymbols_1 = require("./services/jsonDocumentSymbols");
35
+ const jsonParser_1 = require("./parser/jsonParser");
36
+ const configuration_1 = require("./services/configuration");
37
+ const jsonSchemaService_1 = require("./services/jsonSchemaService");
38
+ const jsonFolding_1 = require("./services/jsonFolding");
39
+ const jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
40
+ const jsonc_parser_1 = require("jsonc-parser");
41
+ const jsonLanguageTypes_1 = require("./jsonLanguageTypes");
42
+ const jsonLinks_1 = require("./services/jsonLinks");
39
43
  __exportStar(require("./jsonLanguageTypes"), exports);
40
44
  function getLanguageService(params) {
41
- var promise = params.promiseConstructor || Promise;
42
- var jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
45
+ const promise = params.promiseConstructor || Promise;
46
+ const jsonSchemaService = new jsonSchemaService_1.JSONSchemaService(params.schemaRequestService, params.workspaceContext, promise);
43
47
  jsonSchemaService.setSchemaContributions(configuration_1.schemaContributions);
44
- var jsonCompletion = new jsonCompletion_1.JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
45
- var jsonHover = new jsonHover_1.JSONHover(jsonSchemaService, params.contributions, promise);
46
- var jsonDocumentSymbols = new jsonDocumentSymbols_1.JSONDocumentSymbols(jsonSchemaService);
47
- var jsonValidation = new jsonValidation_1.JSONValidation(jsonSchemaService, promise);
48
+ const jsonCompletion = new jsonCompletion_1.JSONCompletion(jsonSchemaService, params.contributions, promise, params.clientCapabilities);
49
+ const jsonHover = new jsonHover_1.JSONHover(jsonSchemaService, params.contributions, promise);
50
+ const jsonDocumentSymbols = new jsonDocumentSymbols_1.JSONDocumentSymbols(jsonSchemaService);
51
+ const jsonValidation = new jsonValidation_1.JSONValidation(jsonSchemaService, promise);
48
52
  return {
49
- configure: function (settings) {
53
+ configure: (settings) => {
50
54
  jsonSchemaService.clearExternalSchemas();
51
55
  if (settings.schemas) {
52
- settings.schemas.forEach(function (settings) {
56
+ settings.schemas.forEach(settings => {
53
57
  jsonSchemaService.registerExternalSchema(settings.uri, settings.fileMatch, settings.schema);
54
58
  });
55
59
  }
56
60
  jsonValidation.configure(settings);
57
61
  },
58
- resetSchema: function (uri) { return jsonSchemaService.onResourceChange(uri); },
62
+ resetSchema: (uri) => jsonSchemaService.onResourceChange(uri),
59
63
  doValidation: jsonValidation.doValidation.bind(jsonValidation),
60
64
  getLanguageStatus: jsonValidation.getLanguageStatus.bind(jsonValidation),
61
- parseJSONDocument: function (document) { return (0, jsonParser_1.parse)(document, { collectComments: true }); },
62
- newJSONDocument: function (root, diagnostics) { return (0, jsonParser_1.newJSONDocument)(root, diagnostics); },
65
+ parseJSONDocument: (document) => (0, jsonParser_1.parse)(document, { collectComments: true }),
66
+ newJSONDocument: (root, diagnostics) => (0, jsonParser_1.newJSONDocument)(root, diagnostics),
63
67
  getMatchingSchemas: jsonSchemaService.getMatchingSchemas.bind(jsonSchemaService),
64
68
  doResolve: jsonCompletion.doResolve.bind(jsonCompletion),
65
69
  doComplete: jsonCompletion.doComplete.bind(jsonCompletion),
@@ -70,17 +74,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
70
74
  doHover: jsonHover.doHover.bind(jsonHover),
71
75
  getFoldingRanges: jsonFolding_1.getFoldingRanges,
72
76
  getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
73
- findDefinition: function () { return Promise.resolve([]); },
77
+ findDefinition: () => Promise.resolve([]),
74
78
  findLinks: jsonLinks_1.findLinks,
75
- format: function (d, r, o) {
76
- var range = undefined;
79
+ format: (d, r, o) => {
80
+ let range = undefined;
77
81
  if (r) {
78
- var offset = d.offsetAt(r.start);
79
- var length = d.offsetAt(r.end) - offset;
80
- range = { offset: offset, length: length };
82
+ const offset = d.offsetAt(r.start);
83
+ const length = d.offsetAt(r.end) - offset;
84
+ range = { offset, length };
81
85
  }
82
- var options = { tabSize: o ? o.tabSize : 4, insertSpaces: (o === null || o === void 0 ? void 0 : o.insertSpaces) === true, insertFinalNewline: (o === null || o === void 0 ? void 0 : o.insertFinalNewline) === true, eol: '\n' };
83
- return (0, jsonc_parser_1.format)(d.getText(), range, options).map(function (e) {
86
+ const options = { tabSize: o ? o.tabSize : 4, insertSpaces: o?.insertSpaces === true, insertFinalNewline: o?.insertFinalNewline === true, eol: '\n', keepLines: o?.keepLines === true };
87
+ return (0, jsonc_parser_1.format)(d.getText(), range, options).map(e => {
84
88
  return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
85
89
  });
86
90
  }
@@ -25,7 +25,8 @@ export declare enum ErrorCode {
25
25
  TrailingComma = 519,
26
26
  DuplicateKey = 520,
27
27
  CommentNotPermitted = 521,
28
- SchemaResolveError = 768
28
+ SchemaResolveError = 768,
29
+ SchemaUnsupportedFeature = 769
29
30
  }
30
31
  export declare type ASTNode = ObjectASTNode | PropertyASTNode | ArrayASTNode | StringASTNode | NumberASTNode | BooleanASTNode | NullASTNode;
31
32
  export interface BaseASTNode {
@@ -275,4 +276,5 @@ export interface ColorInformationContext {
275
276
  }
276
277
  export interface FormattingOptions extends LSPFormattingOptions {
277
278
  insertFinalNewline?: boolean;
279
+ keepLines?: boolean;
278
280
  }
@@ -13,10 +13,11 @@
13
13
  })(function (require, exports) {
14
14
  "use strict";
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ClientCapabilities = exports.ErrorCode = exports.DocumentHighlightKind = exports.VersionedTextDocumentIdentifier = exports.TextDocumentEdit = exports.CodeActionKind = exports.TextEdit = exports.WorkspaceEdit = exports.DocumentLink = exports.DocumentHighlight = exports.CodeAction = exports.Command = exports.CodeActionContext = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.InsertTextFormat = exports.CompletionItemTag = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.MarkupKind = exports.MarkupContent = exports.Position = exports.Range = exports.TextDocument = void 0;
17
- var vscode_languageserver_types_1 = require("vscode-languageserver-types");
16
+ exports.ClientCapabilities = exports.ErrorCode = exports.DocumentHighlightKind = exports.VersionedTextDocumentIdentifier = exports.TextDocumentEdit = exports.CodeActionKind = exports.TextEdit = exports.WorkspaceEdit = exports.DocumentLink = exports.DocumentHighlight = exports.CodeAction = exports.Command = exports.CodeActionContext = exports.MarkedString = exports.Hover = exports.Location = exports.DocumentSymbol = exports.SymbolKind = exports.SymbolInformation = exports.InsertTextFormat = exports.CompletionItemTag = exports.CompletionList = exports.CompletionItemKind = exports.CompletionItem = exports.DiagnosticSeverity = exports.Diagnostic = exports.SelectionRange = exports.FoldingRangeKind = exports.FoldingRange = exports.ColorPresentation = exports.ColorInformation = exports.Color = exports.MarkupKind = exports.MarkupContent = exports.DocumentUri = exports.Position = exports.Range = exports.TextDocument = void 0;
17
+ const vscode_languageserver_types_1 = require("vscode-languageserver-types");
18
18
  Object.defineProperty(exports, "Range", { enumerable: true, get: function () { return vscode_languageserver_types_1.Range; } });
19
19
  Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return vscode_languageserver_types_1.Position; } });
20
+ Object.defineProperty(exports, "DocumentUri", { enumerable: true, get: function () { return vscode_languageserver_types_1.DocumentUri; } });
20
21
  Object.defineProperty(exports, "MarkupContent", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupContent; } });
21
22
  Object.defineProperty(exports, "MarkupKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.MarkupKind; } });
22
23
  Object.defineProperty(exports, "Color", { enumerable: true, get: function () { return vscode_languageserver_types_1.Color; } });
@@ -49,7 +50,7 @@
49
50
  Object.defineProperty(exports, "TextDocumentEdit", { enumerable: true, get: function () { return vscode_languageserver_types_1.TextDocumentEdit; } });
50
51
  Object.defineProperty(exports, "VersionedTextDocumentIdentifier", { enumerable: true, get: function () { return vscode_languageserver_types_1.VersionedTextDocumentIdentifier; } });
51
52
  Object.defineProperty(exports, "DocumentHighlightKind", { enumerable: true, get: function () { return vscode_languageserver_types_1.DocumentHighlightKind; } });
52
- var vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
53
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
53
54
  Object.defineProperty(exports, "TextDocument", { enumerable: true, get: function () { return vscode_languageserver_textdocument_1.TextDocument; } });
54
55
  /**
55
56
  * Error codes used by diagnostics
@@ -75,6 +76,7 @@
75
76
  ErrorCode[ErrorCode["DuplicateKey"] = 520] = "DuplicateKey";
76
77
  ErrorCode[ErrorCode["CommentNotPermitted"] = 521] = "CommentNotPermitted";
77
78
  ErrorCode[ErrorCode["SchemaResolveError"] = 768] = "SchemaResolveError";
79
+ ErrorCode[ErrorCode["SchemaUnsupportedFeature"] = 769] = "SchemaUnsupportedFeature";
78
80
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
79
81
  var ClientCapabilities;
80
82
  (function (ClientCapabilities) {
@@ -12,7 +12,7 @@ export interface JSONSchema {
12
12
  description?: string;
13
13
  properties?: JSONSchemaMap;
14
14
  patternProperties?: JSONSchemaMap;
15
- additionalProperties?: boolean | JSONSchemaRef;
15
+ additionalProperties?: JSONSchemaRef;
16
16
  minProperties?: number;
17
17
  maxProperties?: number;
18
18
  dependencies?: JSONSchemaMap | {
@@ -22,7 +22,7 @@ export interface JSONSchema {
22
22
  minItems?: number;
23
23
  maxItems?: number;
24
24
  uniqueItems?: boolean;
25
- additionalItems?: boolean | JSONSchemaRef;
25
+ additionalItems?: JSONSchemaRef;
26
26
  pattern?: string;
27
27
  minLength?: number;
28
28
  maxLength?: number;
@@ -47,6 +47,25 @@ export interface JSONSchema {
47
47
  if?: JSONSchemaRef;
48
48
  then?: JSONSchemaRef;
49
49
  else?: JSONSchemaRef;
50
+ unevaluatedProperties?: boolean | JSONSchemaRef;
51
+ unevaluatedItems?: boolean | JSONSchemaRef;
52
+ minContains?: number;
53
+ maxContains?: number;
54
+ deprecated?: boolean;
55
+ dependentRequired?: {
56
+ [prop: string]: string[];
57
+ };
58
+ dependentSchemas?: JSONSchemaMap;
59
+ $defs?: {
60
+ [name: string]: JSONSchema;
61
+ };
62
+ $anchor?: string;
63
+ $recursiveRef?: string;
64
+ $recursiveAnchor?: string;
65
+ $vocabulary?: any;
66
+ prefixItems?: JSONSchemaRef[];
67
+ $dynamicRef?: string;
68
+ $dynamicAnchor?: string;
50
69
  defaultSnippets?: {
51
70
  label?: string;
52
71
  description?: string;