vscode-json-languageservice 5.7.2 → 6.0.0-next.2
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 +13 -0
- package/lib/esm/jsonContributions.d.ts +1 -1
- package/lib/esm/jsonLanguageService.d.ts +2 -2
- package/lib/esm/jsonLanguageService.js +13 -13
- package/lib/esm/jsonLanguageTypes.d.ts +10 -2
- package/lib/esm/jsonSchema.d.ts +71 -2
- package/lib/esm/parser/jsonParser.js +224 -93
- package/lib/esm/services/configuration.js +2 -2
- package/lib/esm/services/jsonCompletion.js +5 -5
- package/lib/esm/services/jsonDocumentSymbols.js +4 -4
- package/lib/esm/services/jsonFolding.js +1 -1
- package/lib/esm/services/jsonHover.js +2 -2
- package/lib/esm/services/jsonLinks.js +94 -3
- package/lib/esm/services/jsonSchemaService.js +639 -100
- package/lib/esm/services/jsonSelectionRanges.js +1 -1
- package/lib/esm/services/jsonValidation.js +4 -4
- package/lib/esm/services/schemas/draft-2019-09-flat.d.ts +1 -1
- package/lib/esm/services/schemas/draft-2020-12-flat.d.ts +1 -1
- package/lib/esm/services/vocabularies.js +139 -0
- package/lib/esm/utils/format.js +1 -1
- package/lib/esm/utils/sort.js +3 -3
- package/package.json +23 -20
- package/lib/umd/jsonContributions.d.ts +0 -21
- package/lib/umd/jsonContributions.js +0 -12
- package/lib/umd/jsonLanguageService.d.ts +0 -30
- package/lib/umd/jsonLanguageService.js +0 -79
- package/lib/umd/jsonLanguageTypes.d.ts +0 -305
- package/lib/umd/jsonLanguageTypes.js +0 -109
- package/lib/umd/jsonSchema.d.ts +0 -92
- package/lib/umd/jsonSchema.js +0 -12
- package/lib/umd/parser/jsonParser.js +0 -1365
- package/lib/umd/services/configuration.js +0 -536
- package/lib/umd/services/jsonCompletion.js +0 -982
- package/lib/umd/services/jsonDocumentSymbols.js +0 -285
- package/lib/umd/services/jsonFolding.js +0 -133
- package/lib/umd/services/jsonHover.js +0 -125
- package/lib/umd/services/jsonLinks.js +0 -85
- package/lib/umd/services/jsonSchemaService.js +0 -631
- package/lib/umd/services/jsonSelectionRanges.js +0 -74
- package/lib/umd/services/jsonValidation.js +0 -165
- package/lib/umd/services/schemas/draft-2019-09-flat.d.ts +0 -278
- package/lib/umd/services/schemas/draft-2019-09-flat.js +0 -314
- package/lib/umd/services/schemas/draft-2020-12-flat.d.ts +0 -276
- package/lib/umd/services/schemas/draft-2020-12-flat.js +0 -307
- package/lib/umd/utils/colors.js +0 -83
- package/lib/umd/utils/format.js +0 -33
- package/lib/umd/utils/glob.js +0 -137
- package/lib/umd/utils/json.js +0 -55
- package/lib/umd/utils/objects.js +0 -86
- package/lib/umd/utils/propertyTree.js +0 -90
- package/lib/umd/utils/sort.js +0 -384
- package/lib/umd/utils/strings.js +0 -97
|
@@ -2,8 +2,8 @@
|
|
|
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 draft201909Flat from './schemas/draft-2019-09-flat';
|
|
6
|
-
import draft202012Flat from './schemas/draft-2020-12-flat';
|
|
5
|
+
import draft201909Flat from './schemas/draft-2019-09-flat.js';
|
|
6
|
+
import draft202012Flat from './schemas/draft-2020-12-flat.js';
|
|
7
7
|
import * as l10n from '@vscode/l10n';
|
|
8
8
|
export const schemaContributions = {
|
|
9
9
|
schemaAssociations: [],
|
|
@@ -2,12 +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 * as Parser from '../parser/jsonParser';
|
|
5
|
+
import * as Parser from '../parser/jsonParser.js';
|
|
6
6
|
import * as Json from 'jsonc-parser';
|
|
7
|
-
import { stringifyObject } from '../utils/json';
|
|
8
|
-
import { endsWith, extendedRegExp } from '../utils/strings';
|
|
9
|
-
import { isDefined } from '../utils/objects';
|
|
10
|
-
import { CompletionItem, CompletionItemKind, Range, TextEdit, InsertTextFormat, MarkupKind } from '../jsonLanguageTypes';
|
|
7
|
+
import { stringifyObject } from '../utils/json.js';
|
|
8
|
+
import { endsWith, extendedRegExp } from '../utils/strings.js';
|
|
9
|
+
import { isDefined } from '../utils/objects.js';
|
|
10
|
+
import { CompletionItem, CompletionItemKind, Range, TextEdit, InsertTextFormat, MarkupKind } from '../jsonLanguageTypes.js';
|
|
11
11
|
import * as l10n from '@vscode/l10n';
|
|
12
12
|
const valueCommitCharacters = [',', '}', ']'];
|
|
13
13
|
const propertyCommitCharacters = [':'];
|
|
@@ -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
|
-
import * as Parser from '../parser/jsonParser';
|
|
6
|
-
import * as Strings from '../utils/strings';
|
|
7
|
-
import { colorFromHex } from '../utils/colors';
|
|
5
|
+
import * as Parser from '../parser/jsonParser.js';
|
|
6
|
+
import * as Strings from '../utils/strings.js';
|
|
7
|
+
import { colorFromHex } from '../utils/colors.js';
|
|
8
8
|
import * as l10n from '@vscode/l10n';
|
|
9
|
-
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes";
|
|
9
|
+
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes.js";
|
|
10
10
|
export class JSONDocumentSymbols {
|
|
11
11
|
constructor(schemaService) {
|
|
12
12
|
this.schemaService = schemaService;
|
|
@@ -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 { createScanner } from 'jsonc-parser';
|
|
6
|
-
import { FoldingRangeKind, Position } from '../jsonLanguageTypes';
|
|
6
|
+
import { FoldingRangeKind, Position } from '../jsonLanguageTypes.js';
|
|
7
7
|
export function getFoldingRanges(document, context) {
|
|
8
8
|
const ranges = [];
|
|
9
9
|
const nestingLevels = [];
|
|
@@ -2,8 +2,8 @@
|
|
|
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 * as Parser from '../parser/jsonParser';
|
|
6
|
-
import { Range } from '../jsonLanguageTypes';
|
|
5
|
+
import * as Parser from '../parser/jsonParser.js';
|
|
6
|
+
import { Range } from '../jsonLanguageTypes.js';
|
|
7
7
|
export class JSONHover {
|
|
8
8
|
constructor(schemaService, contributions = [], promiseConstructor) {
|
|
9
9
|
this.schemaService = schemaService;
|
|
@@ -2,7 +2,7 @@
|
|
|
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 '../jsonLanguageTypes';
|
|
5
|
+
import { Range } from '../jsonLanguageTypes.js';
|
|
6
6
|
export function findLinks(document, doc) {
|
|
7
7
|
const links = [];
|
|
8
8
|
doc.visit(node => {
|
|
@@ -26,10 +26,37 @@ function createRange(document, node) {
|
|
|
26
26
|
}
|
|
27
27
|
function findTargetNode(doc, path) {
|
|
28
28
|
const tokens = parseJSONPointer(path);
|
|
29
|
-
if (
|
|
29
|
+
if (tokens) {
|
|
30
|
+
return findNode(tokens, doc.root);
|
|
31
|
+
}
|
|
32
|
+
if (path.charAt(0) === '#') {
|
|
33
|
+
// Plain-name fragment: anchor reference (e.g. #foo)
|
|
34
|
+
const anchor = path.substring(1);
|
|
35
|
+
if (anchor.length > 0) {
|
|
36
|
+
return findAnchorNode(doc, anchor);
|
|
37
|
+
}
|
|
30
38
|
return null;
|
|
31
39
|
}
|
|
32
|
-
|
|
40
|
+
// Check for references to embedded schemas by $id (e.g. "https://example.com/embedded")
|
|
41
|
+
const hashIndex = path.indexOf('#');
|
|
42
|
+
const uri = hashIndex >= 0 ? path.substring(0, hashIndex) : path;
|
|
43
|
+
const fragment = hashIndex >= 0 ? path.substring(hashIndex + 1) : undefined;
|
|
44
|
+
if (uri.length > 0) {
|
|
45
|
+
const embeddedNode = findEmbeddedSchemaNode(doc, uri);
|
|
46
|
+
if (embeddedNode) {
|
|
47
|
+
if (!fragment || fragment.length === 0) {
|
|
48
|
+
return embeddedNode;
|
|
49
|
+
}
|
|
50
|
+
if (fragment.charAt(0) === '/') {
|
|
51
|
+
// JSON Pointer within the embedded schema
|
|
52
|
+
const pointerTokens = fragment.substring(1).split(/\//).map(unescape);
|
|
53
|
+
return findNode(pointerTokens, embeddedNode);
|
|
54
|
+
}
|
|
55
|
+
// Anchor within the embedded schema
|
|
56
|
+
return findAnchorInSubtree(embeddedNode, fragment);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
33
60
|
}
|
|
34
61
|
function findNode(pointer, node) {
|
|
35
62
|
if (!node) {
|
|
@@ -58,6 +85,70 @@ function findNode(pointer, node) {
|
|
|
58
85
|
}
|
|
59
86
|
return null;
|
|
60
87
|
}
|
|
88
|
+
function findAnchorNode(doc, anchor) {
|
|
89
|
+
return findAnchorInSubtree(doc.root, anchor);
|
|
90
|
+
}
|
|
91
|
+
function findAnchorInSubtree(root, anchor) {
|
|
92
|
+
if (!root) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
let result = null;
|
|
96
|
+
const visit = (node) => {
|
|
97
|
+
if (node.type === 'object') {
|
|
98
|
+
for (const prop of node.properties) {
|
|
99
|
+
// $anchor: "foo" (2019-09+)
|
|
100
|
+
if (prop.keyNode.value === '$anchor' && prop.valueNode?.type === 'string' && prop.valueNode.value === anchor) {
|
|
101
|
+
result = node;
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
// $id: "#foo" (draft-06/07 legacy anchors)
|
|
105
|
+
if (prop.keyNode.value === '$id' && prop.valueNode?.type === 'string' && prop.valueNode.value === '#' + anchor) {
|
|
106
|
+
result = node;
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const children = node.children;
|
|
112
|
+
if (children) {
|
|
113
|
+
for (const child of children) {
|
|
114
|
+
if (!visit(child)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
};
|
|
121
|
+
visit(root);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function findEmbeddedSchemaNode(doc, uri) {
|
|
125
|
+
if (!doc.root) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
let result = null;
|
|
129
|
+
const visit = (node, isRoot) => {
|
|
130
|
+
if (node.type === 'object' && !isRoot) {
|
|
131
|
+
for (const prop of node.properties) {
|
|
132
|
+
if ((prop.keyNode.value === '$id' || prop.keyNode.value === 'id') &&
|
|
133
|
+
prop.valueNode?.type === 'string' && prop.valueNode.value === uri) {
|
|
134
|
+
result = node;
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const children = node.children;
|
|
140
|
+
if (children) {
|
|
141
|
+
for (const child of children) {
|
|
142
|
+
if (!visit(child, false)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
};
|
|
149
|
+
visit(doc.root, true);
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
61
152
|
function parseJSONPointer(path) {
|
|
62
153
|
if (path === "#") {
|
|
63
154
|
return [];
|