vscode-json-languageservice 4.2.1 → 5.0.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 (49) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/jsonContributions.d.ts +17 -17
  4. package/lib/esm/jsonContributions.js +1 -1
  5. package/lib/esm/jsonLanguageService.d.ts +29 -29
  6. package/lib/esm/jsonLanguageService.js +66 -66
  7. package/lib/esm/jsonLanguageTypes.d.ts +279 -278
  8. package/lib/esm/jsonLanguageTypes.js +46 -45
  9. package/lib/esm/jsonSchema.d.ts +89 -70
  10. package/lib/esm/jsonSchema.js +1 -1
  11. package/lib/esm/parser/jsonParser.js +1214 -1218
  12. package/lib/esm/services/configuration.js +528 -528
  13. package/lib/esm/services/jsonCompletion.js +918 -934
  14. package/lib/esm/services/jsonDocumentSymbols.js +267 -278
  15. package/lib/esm/services/jsonFolding.js +120 -121
  16. package/lib/esm/services/jsonHover.js +109 -112
  17. package/lib/esm/services/jsonLinks.js +72 -73
  18. package/lib/esm/services/jsonSchemaService.js +586 -605
  19. package/lib/esm/services/jsonSelectionRanges.js +61 -61
  20. package/lib/esm/services/jsonValidation.js +151 -149
  21. package/lib/esm/utils/colors.js +68 -69
  22. package/lib/esm/utils/glob.js +124 -124
  23. package/lib/esm/utils/json.js +42 -42
  24. package/lib/esm/utils/objects.js +68 -65
  25. package/lib/esm/utils/strings.js +64 -64
  26. package/lib/umd/jsonContributions.d.ts +17 -17
  27. package/lib/umd/jsonContributions.js +12 -12
  28. package/lib/umd/jsonLanguageService.d.ts +29 -29
  29. package/lib/umd/jsonLanguageService.js +90 -90
  30. package/lib/umd/jsonLanguageTypes.d.ts +279 -278
  31. package/lib/umd/jsonLanguageTypes.js +93 -92
  32. package/lib/umd/jsonSchema.d.ts +89 -70
  33. package/lib/umd/jsonSchema.js +12 -12
  34. package/lib/umd/parser/jsonParser.js +1243 -1237
  35. package/lib/umd/services/configuration.js +541 -541
  36. package/lib/umd/services/jsonCompletion.js +932 -947
  37. package/lib/umd/services/jsonDocumentSymbols.js +281 -291
  38. package/lib/umd/services/jsonFolding.js +134 -135
  39. package/lib/umd/services/jsonHover.js +123 -125
  40. package/lib/umd/services/jsonLinks.js +86 -87
  41. package/lib/umd/services/jsonSchemaService.js +602 -618
  42. package/lib/umd/services/jsonSelectionRanges.js +75 -75
  43. package/lib/umd/services/jsonValidation.js +165 -162
  44. package/lib/umd/utils/colors.js +84 -85
  45. package/lib/umd/utils/glob.js +138 -138
  46. package/lib/umd/utils/json.js +56 -56
  47. package/lib/umd/utils/objects.js +87 -83
  48. package/lib/umd/utils/strings.js +82 -82
  49. package/package.json +10 -10
@@ -1,87 +1,86 @@
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
- (function (factory) {
6
- if (typeof module === "object" && typeof module.exports === "object") {
7
- var v = factory(require, exports);
8
- if (v !== undefined) module.exports = v;
9
- }
10
- else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "../jsonLanguageTypes"], factory);
12
- }
13
- })(function (require, exports) {
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.findLinks = void 0;
17
- var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
18
- function findLinks(document, doc) {
19
- var links = [];
20
- doc.visit(function (node) {
21
- var _a;
22
- if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
23
- var path = node.valueNode.value;
24
- var targetNode = findTargetNode(doc, path);
25
- if (targetNode) {
26
- var targetPos = document.positionAt(targetNode.offset);
27
- links.push({
28
- target: "".concat(document.uri, "#").concat(targetPos.line + 1, ",").concat(targetPos.character + 1),
29
- range: createRange(document, node.valueNode)
30
- });
31
- }
32
- }
33
- return true;
34
- });
35
- return Promise.resolve(links);
36
- }
37
- exports.findLinks = findLinks;
38
- function createRange(document, node) {
39
- return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
40
- }
41
- function findTargetNode(doc, path) {
42
- var tokens = parseJSONPointer(path);
43
- if (!tokens) {
44
- return null;
45
- }
46
- return findNode(tokens, doc.root);
47
- }
48
- function findNode(pointer, node) {
49
- if (!node) {
50
- return null;
51
- }
52
- if (pointer.length === 0) {
53
- return node;
54
- }
55
- var token = pointer.shift();
56
- if (node && node.type === 'object') {
57
- var propertyNode = node.properties.find(function (propertyNode) { return propertyNode.keyNode.value === token; });
58
- if (!propertyNode) {
59
- return null;
60
- }
61
- return findNode(pointer, propertyNode.valueNode);
62
- }
63
- else if (node && node.type === 'array') {
64
- if (token.match(/^(0|[1-9][0-9]*)$/)) {
65
- var index = Number.parseInt(token);
66
- var arrayItem = node.items[index];
67
- if (!arrayItem) {
68
- return null;
69
- }
70
- return findNode(pointer, arrayItem);
71
- }
72
- }
73
- return null;
74
- }
75
- function parseJSONPointer(path) {
76
- if (path === "#") {
77
- return [];
78
- }
79
- if (path[0] !== '#' || path[1] !== '/') {
80
- return null;
81
- }
82
- return path.substring(2).split(/\//).map(unescape);
83
- }
84
- function unescape(str) {
85
- return str.replace(/~1/g, '/').replace(/~0/g, '~');
86
- }
87
- });
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
+ (function (factory) {
6
+ if (typeof module === "object" && typeof module.exports === "object") {
7
+ var v = factory(require, exports);
8
+ if (v !== undefined) module.exports = v;
9
+ }
10
+ else if (typeof define === "function" && define.amd) {
11
+ define(["require", "exports", "../jsonLanguageTypes"], factory);
12
+ }
13
+ })(function (require, exports) {
14
+ "use strict";
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.findLinks = void 0;
17
+ const jsonLanguageTypes_1 = require("../jsonLanguageTypes");
18
+ function findLinks(document, doc) {
19
+ const links = [];
20
+ doc.visit(node => {
21
+ if (node.type === "property" && node.keyNode.value === "$ref" && node.valueNode?.type === 'string') {
22
+ const path = node.valueNode.value;
23
+ const targetNode = findTargetNode(doc, path);
24
+ if (targetNode) {
25
+ const targetPos = document.positionAt(targetNode.offset);
26
+ links.push({
27
+ target: `${document.uri}#${targetPos.line + 1},${targetPos.character + 1}`,
28
+ range: createRange(document, node.valueNode)
29
+ });
30
+ }
31
+ }
32
+ return true;
33
+ });
34
+ return Promise.resolve(links);
35
+ }
36
+ exports.findLinks = findLinks;
37
+ function createRange(document, node) {
38
+ return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
39
+ }
40
+ function findTargetNode(doc, path) {
41
+ const tokens = parseJSONPointer(path);
42
+ if (!tokens) {
43
+ return null;
44
+ }
45
+ return findNode(tokens, doc.root);
46
+ }
47
+ function findNode(pointer, node) {
48
+ if (!node) {
49
+ return null;
50
+ }
51
+ if (pointer.length === 0) {
52
+ return node;
53
+ }
54
+ const token = pointer.shift();
55
+ if (node && node.type === 'object') {
56
+ const propertyNode = node.properties.find((propertyNode) => propertyNode.keyNode.value === token);
57
+ if (!propertyNode) {
58
+ return null;
59
+ }
60
+ return findNode(pointer, propertyNode.valueNode);
61
+ }
62
+ else if (node && node.type === 'array') {
63
+ if (token.match(/^(0|[1-9][0-9]*)$/)) {
64
+ const index = Number.parseInt(token);
65
+ const arrayItem = node.items[index];
66
+ if (!arrayItem) {
67
+ return null;
68
+ }
69
+ return findNode(pointer, arrayItem);
70
+ }
71
+ }
72
+ return null;
73
+ }
74
+ function parseJSONPointer(path) {
75
+ if (path === "#") {
76
+ return [];
77
+ }
78
+ if (path[0] !== '#' || path[1] !== '/') {
79
+ return null;
80
+ }
81
+ return path.substring(2).split(/\//).map(unescape);
82
+ }
83
+ function unescape(str) {
84
+ return str.replace(/~1/g, '/').replace(/~0/g, '~');
85
+ }
86
+ });