vscode-json-languageservice 5.0.0 → 5.1.1
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 +10 -2
- package/lib/esm/jsonContributions.d.ts +17 -17
- package/lib/esm/jsonContributions.js +1 -1
- package/lib/esm/jsonLanguageService.d.ts +29 -29
- package/lib/esm/jsonLanguageService.js +66 -66
- package/lib/esm/jsonLanguageTypes.d.ts +292 -279
- package/lib/esm/jsonLanguageTypes.js +55 -46
- package/lib/esm/jsonSchema.d.ts +89 -89
- package/lib/esm/jsonSchema.js +1 -1
- package/lib/esm/parser/jsonParser.js +1236 -1214
- package/lib/esm/services/configuration.js +528 -528
- package/lib/esm/services/jsonCompletion.js +924 -918
- package/lib/esm/services/jsonDocumentSymbols.js +267 -267
- package/lib/esm/services/jsonFolding.js +120 -120
- package/lib/esm/services/jsonHover.js +109 -109
- package/lib/esm/services/jsonLinks.js +72 -72
- package/lib/esm/services/jsonSchemaService.js +593 -586
- package/lib/esm/services/jsonSelectionRanges.js +61 -61
- package/lib/esm/services/jsonValidation.js +151 -151
- package/lib/esm/utils/colors.js +68 -68
- package/lib/esm/utils/glob.js +124 -124
- package/lib/esm/utils/json.js +42 -42
- package/lib/esm/utils/objects.js +68 -68
- package/lib/esm/utils/strings.js +79 -64
- package/lib/umd/jsonContributions.d.ts +17 -17
- package/lib/umd/jsonContributions.js +12 -12
- package/lib/umd/jsonLanguageService.d.ts +29 -29
- package/lib/umd/jsonLanguageService.js +94 -90
- package/lib/umd/jsonLanguageTypes.d.ts +292 -279
- package/lib/umd/jsonLanguageTypes.js +103 -93
- package/lib/umd/jsonSchema.d.ts +89 -89
- package/lib/umd/jsonSchema.js +12 -12
- package/lib/umd/parser/jsonParser.js +1265 -1243
- package/lib/umd/services/configuration.js +541 -541
- package/lib/umd/services/jsonCompletion.js +938 -932
- package/lib/umd/services/jsonDocumentSymbols.js +281 -281
- package/lib/umd/services/jsonFolding.js +134 -134
- package/lib/umd/services/jsonHover.js +123 -123
- package/lib/umd/services/jsonLinks.js +86 -86
- package/lib/umd/services/jsonSchemaService.js +609 -602
- package/lib/umd/services/jsonSelectionRanges.js +75 -75
- package/lib/umd/services/jsonValidation.js +165 -165
- package/lib/umd/utils/colors.js +84 -84
- package/lib/umd/utils/glob.js +138 -138
- package/lib/umd/utils/json.js +56 -56
- package/lib/umd/utils/objects.js +87 -87
- package/lib/umd/utils/strings.js +98 -82
- package/package.json +11 -10
|
@@ -1,267 +1,267 @@
|
|
|
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
|
-
import * as Parser from '../parser/jsonParser';
|
|
6
|
-
import * as Strings from '../utils/strings';
|
|
7
|
-
import { colorFromHex } from '../utils/colors';
|
|
8
|
-
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes";
|
|
9
|
-
export class JSONDocumentSymbols {
|
|
10
|
-
constructor(schemaService) {
|
|
11
|
-
this.schemaService = schemaService;
|
|
12
|
-
}
|
|
13
|
-
findDocumentSymbols(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
|
|
14
|
-
const root = doc.root;
|
|
15
|
-
if (!root) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
let limit = context.resultLimit || Number.MAX_VALUE;
|
|
19
|
-
// special handling for key bindings
|
|
20
|
-
const resourceString = document.uri;
|
|
21
|
-
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
|
22
|
-
if (root.type === 'array') {
|
|
23
|
-
const result = [];
|
|
24
|
-
for (const item of root.items) {
|
|
25
|
-
if (item.type === 'object') {
|
|
26
|
-
for (const property of item.properties) {
|
|
27
|
-
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
28
|
-
const location = Location.create(document.uri, getRange(document, item));
|
|
29
|
-
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location });
|
|
30
|
-
limit--;
|
|
31
|
-
if (limit <= 0) {
|
|
32
|
-
if (context && context.onResultLimitExceeded) {
|
|
33
|
-
context.onResultLimitExceeded(resourceString);
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const toVisit = [
|
|
45
|
-
{ node: root, containerName: '' }
|
|
46
|
-
];
|
|
47
|
-
let nextToVisit = 0;
|
|
48
|
-
let limitExceeded = false;
|
|
49
|
-
const result = [];
|
|
50
|
-
const collectOutlineEntries = (node, containerName) => {
|
|
51
|
-
if (node.type === 'array') {
|
|
52
|
-
node.items.forEach(node => {
|
|
53
|
-
if (node) {
|
|
54
|
-
toVisit.push({ node, containerName });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else if (node.type === 'object') {
|
|
59
|
-
node.properties.forEach((property) => {
|
|
60
|
-
const valueNode = property.valueNode;
|
|
61
|
-
if (valueNode) {
|
|
62
|
-
if (limit > 0) {
|
|
63
|
-
limit--;
|
|
64
|
-
const location = Location.create(document.uri, getRange(document, property));
|
|
65
|
-
const childContainerName = containerName ? containerName + '.' + property.keyNode.value : property.keyNode.value;
|
|
66
|
-
result.push({ name: this.getKeyLabel(property), kind: this.getSymbolKind(valueNode.type), location: location, containerName: containerName });
|
|
67
|
-
toVisit.push({ node: valueNode, containerName: childContainerName });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
limitExceeded = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
// breath first traversal
|
|
77
|
-
while (nextToVisit < toVisit.length) {
|
|
78
|
-
const next = toVisit[nextToVisit++];
|
|
79
|
-
collectOutlineEntries(next.node, next.containerName);
|
|
80
|
-
}
|
|
81
|
-
if (limitExceeded && context && context.onResultLimitExceeded) {
|
|
82
|
-
context.onResultLimitExceeded(resourceString);
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
findDocumentSymbols2(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
|
|
87
|
-
const root = doc.root;
|
|
88
|
-
if (!root) {
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
let limit = context.resultLimit || Number.MAX_VALUE;
|
|
92
|
-
// special handling for key bindings
|
|
93
|
-
const resourceString = document.uri;
|
|
94
|
-
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
|
95
|
-
if (root.type === 'array') {
|
|
96
|
-
const result = [];
|
|
97
|
-
for (const item of root.items) {
|
|
98
|
-
if (item.type === 'object') {
|
|
99
|
-
for (const property of item.properties) {
|
|
100
|
-
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
101
|
-
const range = getRange(document, item);
|
|
102
|
-
const selectionRange = getRange(document, property.keyNode);
|
|
103
|
-
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, range, selectionRange });
|
|
104
|
-
limit--;
|
|
105
|
-
if (limit <= 0) {
|
|
106
|
-
if (context && context.onResultLimitExceeded) {
|
|
107
|
-
context.onResultLimitExceeded(resourceString);
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const result = [];
|
|
119
|
-
const toVisit = [
|
|
120
|
-
{ node: root, result }
|
|
121
|
-
];
|
|
122
|
-
let nextToVisit = 0;
|
|
123
|
-
let limitExceeded = false;
|
|
124
|
-
const collectOutlineEntries = (node, result) => {
|
|
125
|
-
if (node.type === 'array') {
|
|
126
|
-
node.items.forEach((node, index) => {
|
|
127
|
-
if (node) {
|
|
128
|
-
if (limit > 0) {
|
|
129
|
-
limit--;
|
|
130
|
-
const range = getRange(document, node);
|
|
131
|
-
const selectionRange = range;
|
|
132
|
-
const name = String(index);
|
|
133
|
-
const symbol = { name, kind: this.getSymbolKind(node.type), range, selectionRange, children: [] };
|
|
134
|
-
result.push(symbol);
|
|
135
|
-
toVisit.push({ result: symbol.children, node });
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
limitExceeded = true;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
else if (node.type === 'object') {
|
|
144
|
-
node.properties.forEach((property) => {
|
|
145
|
-
const valueNode = property.valueNode;
|
|
146
|
-
if (valueNode) {
|
|
147
|
-
if (limit > 0) {
|
|
148
|
-
limit--;
|
|
149
|
-
const range = getRange(document, property);
|
|
150
|
-
const selectionRange = getRange(document, property.keyNode);
|
|
151
|
-
const children = [];
|
|
152
|
-
const symbol = { name: this.getKeyLabel(property), kind: this.getSymbolKind(valueNode.type), range, selectionRange, children, detail: this.getDetail(valueNode) };
|
|
153
|
-
result.push(symbol);
|
|
154
|
-
toVisit.push({ result: children, node: valueNode });
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
limitExceeded = true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
// breath first traversal
|
|
164
|
-
while (nextToVisit < toVisit.length) {
|
|
165
|
-
const next = toVisit[nextToVisit++];
|
|
166
|
-
collectOutlineEntries(next.node, next.result);
|
|
167
|
-
}
|
|
168
|
-
if (limitExceeded && context && context.onResultLimitExceeded) {
|
|
169
|
-
context.onResultLimitExceeded(resourceString);
|
|
170
|
-
}
|
|
171
|
-
return result;
|
|
172
|
-
}
|
|
173
|
-
getSymbolKind(nodeType) {
|
|
174
|
-
switch (nodeType) {
|
|
175
|
-
case 'object':
|
|
176
|
-
return SymbolKind.Module;
|
|
177
|
-
case 'string':
|
|
178
|
-
return SymbolKind.String;
|
|
179
|
-
case 'number':
|
|
180
|
-
return SymbolKind.Number;
|
|
181
|
-
case 'array':
|
|
182
|
-
return SymbolKind.Array;
|
|
183
|
-
case 'boolean':
|
|
184
|
-
return SymbolKind.Boolean;
|
|
185
|
-
default: // 'null'
|
|
186
|
-
return SymbolKind.Variable;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
getKeyLabel(property) {
|
|
190
|
-
let name = property.keyNode.value;
|
|
191
|
-
if (name) {
|
|
192
|
-
name = name.replace(/[\n]/g, '↵');
|
|
193
|
-
}
|
|
194
|
-
if (name && name.trim()) {
|
|
195
|
-
return name;
|
|
196
|
-
}
|
|
197
|
-
return `"${name}"`;
|
|
198
|
-
}
|
|
199
|
-
getDetail(node) {
|
|
200
|
-
if (!node) {
|
|
201
|
-
return undefined;
|
|
202
|
-
}
|
|
203
|
-
if (node.type === 'boolean' || node.type === 'number' || node.type === 'null' || node.type === 'string') {
|
|
204
|
-
return String(node.value);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
if (node.type === 'array') {
|
|
208
|
-
return node.children.length ? undefined : '[]';
|
|
209
|
-
}
|
|
210
|
-
else if (node.type === 'object') {
|
|
211
|
-
return node.children.length ? undefined : '{}';
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
findDocumentColors(document, doc, context) {
|
|
217
|
-
return this.schemaService.getSchemaForResource(document.uri, doc).then(schema => {
|
|
218
|
-
const result = [];
|
|
219
|
-
if (schema) {
|
|
220
|
-
let limit = context && typeof context.resultLimit === 'number' ? context.resultLimit : Number.MAX_VALUE;
|
|
221
|
-
const matchingSchemas = doc.getMatchingSchemas(schema.schema);
|
|
222
|
-
const visitedNode = {};
|
|
223
|
-
for (const s of matchingSchemas) {
|
|
224
|
-
if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
|
|
225
|
-
const nodeId = String(s.node.offset);
|
|
226
|
-
if (!visitedNode[nodeId]) {
|
|
227
|
-
const color = colorFromHex(Parser.getNodeValue(s.node));
|
|
228
|
-
if (color) {
|
|
229
|
-
const range = getRange(document, s.node);
|
|
230
|
-
result.push({ color, range });
|
|
231
|
-
}
|
|
232
|
-
visitedNode[nodeId] = true;
|
|
233
|
-
limit--;
|
|
234
|
-
if (limit <= 0) {
|
|
235
|
-
if (context && context.onResultLimitExceeded) {
|
|
236
|
-
context.onResultLimitExceeded(document.uri);
|
|
237
|
-
}
|
|
238
|
-
return result;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return result;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
getColorPresentations(document, doc, color, range) {
|
|
248
|
-
const result = [];
|
|
249
|
-
const red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
|
|
250
|
-
function toTwoDigitHex(n) {
|
|
251
|
-
const r = n.toString(16);
|
|
252
|
-
return r.length !== 2 ? '0' + r : r;
|
|
253
|
-
}
|
|
254
|
-
let label;
|
|
255
|
-
if (color.alpha === 1) {
|
|
256
|
-
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}`;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}${toTwoDigitHex(Math.round(color.alpha * 255))}`;
|
|
260
|
-
}
|
|
261
|
-
result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function getRange(document, node) {
|
|
266
|
-
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
267
|
-
}
|
|
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
|
+
import * as Parser from '../parser/jsonParser';
|
|
6
|
+
import * as Strings from '../utils/strings';
|
|
7
|
+
import { colorFromHex } from '../utils/colors';
|
|
8
|
+
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes";
|
|
9
|
+
export class JSONDocumentSymbols {
|
|
10
|
+
constructor(schemaService) {
|
|
11
|
+
this.schemaService = schemaService;
|
|
12
|
+
}
|
|
13
|
+
findDocumentSymbols(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
|
|
14
|
+
const root = doc.root;
|
|
15
|
+
if (!root) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
let limit = context.resultLimit || Number.MAX_VALUE;
|
|
19
|
+
// special handling for key bindings
|
|
20
|
+
const resourceString = document.uri;
|
|
21
|
+
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
|
22
|
+
if (root.type === 'array') {
|
|
23
|
+
const result = [];
|
|
24
|
+
for (const item of root.items) {
|
|
25
|
+
if (item.type === 'object') {
|
|
26
|
+
for (const property of item.properties) {
|
|
27
|
+
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
28
|
+
const location = Location.create(document.uri, getRange(document, item));
|
|
29
|
+
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location });
|
|
30
|
+
limit--;
|
|
31
|
+
if (limit <= 0) {
|
|
32
|
+
if (context && context.onResultLimitExceeded) {
|
|
33
|
+
context.onResultLimitExceeded(resourceString);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const toVisit = [
|
|
45
|
+
{ node: root, containerName: '' }
|
|
46
|
+
];
|
|
47
|
+
let nextToVisit = 0;
|
|
48
|
+
let limitExceeded = false;
|
|
49
|
+
const result = [];
|
|
50
|
+
const collectOutlineEntries = (node, containerName) => {
|
|
51
|
+
if (node.type === 'array') {
|
|
52
|
+
node.items.forEach(node => {
|
|
53
|
+
if (node) {
|
|
54
|
+
toVisit.push({ node, containerName });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (node.type === 'object') {
|
|
59
|
+
node.properties.forEach((property) => {
|
|
60
|
+
const valueNode = property.valueNode;
|
|
61
|
+
if (valueNode) {
|
|
62
|
+
if (limit > 0) {
|
|
63
|
+
limit--;
|
|
64
|
+
const location = Location.create(document.uri, getRange(document, property));
|
|
65
|
+
const childContainerName = containerName ? containerName + '.' + property.keyNode.value : property.keyNode.value;
|
|
66
|
+
result.push({ name: this.getKeyLabel(property), kind: this.getSymbolKind(valueNode.type), location: location, containerName: containerName });
|
|
67
|
+
toVisit.push({ node: valueNode, containerName: childContainerName });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
limitExceeded = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// breath first traversal
|
|
77
|
+
while (nextToVisit < toVisit.length) {
|
|
78
|
+
const next = toVisit[nextToVisit++];
|
|
79
|
+
collectOutlineEntries(next.node, next.containerName);
|
|
80
|
+
}
|
|
81
|
+
if (limitExceeded && context && context.onResultLimitExceeded) {
|
|
82
|
+
context.onResultLimitExceeded(resourceString);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
findDocumentSymbols2(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
|
|
87
|
+
const root = doc.root;
|
|
88
|
+
if (!root) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
let limit = context.resultLimit || Number.MAX_VALUE;
|
|
92
|
+
// special handling for key bindings
|
|
93
|
+
const resourceString = document.uri;
|
|
94
|
+
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
|
95
|
+
if (root.type === 'array') {
|
|
96
|
+
const result = [];
|
|
97
|
+
for (const item of root.items) {
|
|
98
|
+
if (item.type === 'object') {
|
|
99
|
+
for (const property of item.properties) {
|
|
100
|
+
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
101
|
+
const range = getRange(document, item);
|
|
102
|
+
const selectionRange = getRange(document, property.keyNode);
|
|
103
|
+
result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, range, selectionRange });
|
|
104
|
+
limit--;
|
|
105
|
+
if (limit <= 0) {
|
|
106
|
+
if (context && context.onResultLimitExceeded) {
|
|
107
|
+
context.onResultLimitExceeded(resourceString);
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const result = [];
|
|
119
|
+
const toVisit = [
|
|
120
|
+
{ node: root, result }
|
|
121
|
+
];
|
|
122
|
+
let nextToVisit = 0;
|
|
123
|
+
let limitExceeded = false;
|
|
124
|
+
const collectOutlineEntries = (node, result) => {
|
|
125
|
+
if (node.type === 'array') {
|
|
126
|
+
node.items.forEach((node, index) => {
|
|
127
|
+
if (node) {
|
|
128
|
+
if (limit > 0) {
|
|
129
|
+
limit--;
|
|
130
|
+
const range = getRange(document, node);
|
|
131
|
+
const selectionRange = range;
|
|
132
|
+
const name = String(index);
|
|
133
|
+
const symbol = { name, kind: this.getSymbolKind(node.type), range, selectionRange, children: [] };
|
|
134
|
+
result.push(symbol);
|
|
135
|
+
toVisit.push({ result: symbol.children, node });
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
limitExceeded = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else if (node.type === 'object') {
|
|
144
|
+
node.properties.forEach((property) => {
|
|
145
|
+
const valueNode = property.valueNode;
|
|
146
|
+
if (valueNode) {
|
|
147
|
+
if (limit > 0) {
|
|
148
|
+
limit--;
|
|
149
|
+
const range = getRange(document, property);
|
|
150
|
+
const selectionRange = getRange(document, property.keyNode);
|
|
151
|
+
const children = [];
|
|
152
|
+
const symbol = { name: this.getKeyLabel(property), kind: this.getSymbolKind(valueNode.type), range, selectionRange, children, detail: this.getDetail(valueNode) };
|
|
153
|
+
result.push(symbol);
|
|
154
|
+
toVisit.push({ result: children, node: valueNode });
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
limitExceeded = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
// breath first traversal
|
|
164
|
+
while (nextToVisit < toVisit.length) {
|
|
165
|
+
const next = toVisit[nextToVisit++];
|
|
166
|
+
collectOutlineEntries(next.node, next.result);
|
|
167
|
+
}
|
|
168
|
+
if (limitExceeded && context && context.onResultLimitExceeded) {
|
|
169
|
+
context.onResultLimitExceeded(resourceString);
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
getSymbolKind(nodeType) {
|
|
174
|
+
switch (nodeType) {
|
|
175
|
+
case 'object':
|
|
176
|
+
return SymbolKind.Module;
|
|
177
|
+
case 'string':
|
|
178
|
+
return SymbolKind.String;
|
|
179
|
+
case 'number':
|
|
180
|
+
return SymbolKind.Number;
|
|
181
|
+
case 'array':
|
|
182
|
+
return SymbolKind.Array;
|
|
183
|
+
case 'boolean':
|
|
184
|
+
return SymbolKind.Boolean;
|
|
185
|
+
default: // 'null'
|
|
186
|
+
return SymbolKind.Variable;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
getKeyLabel(property) {
|
|
190
|
+
let name = property.keyNode.value;
|
|
191
|
+
if (name) {
|
|
192
|
+
name = name.replace(/[\n]/g, '↵');
|
|
193
|
+
}
|
|
194
|
+
if (name && name.trim()) {
|
|
195
|
+
return name;
|
|
196
|
+
}
|
|
197
|
+
return `"${name}"`;
|
|
198
|
+
}
|
|
199
|
+
getDetail(node) {
|
|
200
|
+
if (!node) {
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
if (node.type === 'boolean' || node.type === 'number' || node.type === 'null' || node.type === 'string') {
|
|
204
|
+
return String(node.value);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
if (node.type === 'array') {
|
|
208
|
+
return node.children.length ? undefined : '[]';
|
|
209
|
+
}
|
|
210
|
+
else if (node.type === 'object') {
|
|
211
|
+
return node.children.length ? undefined : '{}';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
findDocumentColors(document, doc, context) {
|
|
217
|
+
return this.schemaService.getSchemaForResource(document.uri, doc).then(schema => {
|
|
218
|
+
const result = [];
|
|
219
|
+
if (schema) {
|
|
220
|
+
let limit = context && typeof context.resultLimit === 'number' ? context.resultLimit : Number.MAX_VALUE;
|
|
221
|
+
const matchingSchemas = doc.getMatchingSchemas(schema.schema);
|
|
222
|
+
const visitedNode = {};
|
|
223
|
+
for (const s of matchingSchemas) {
|
|
224
|
+
if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
|
|
225
|
+
const nodeId = String(s.node.offset);
|
|
226
|
+
if (!visitedNode[nodeId]) {
|
|
227
|
+
const color = colorFromHex(Parser.getNodeValue(s.node));
|
|
228
|
+
if (color) {
|
|
229
|
+
const range = getRange(document, s.node);
|
|
230
|
+
result.push({ color, range });
|
|
231
|
+
}
|
|
232
|
+
visitedNode[nodeId] = true;
|
|
233
|
+
limit--;
|
|
234
|
+
if (limit <= 0) {
|
|
235
|
+
if (context && context.onResultLimitExceeded) {
|
|
236
|
+
context.onResultLimitExceeded(document.uri);
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return result;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
getColorPresentations(document, doc, color, range) {
|
|
248
|
+
const result = [];
|
|
249
|
+
const red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
|
|
250
|
+
function toTwoDigitHex(n) {
|
|
251
|
+
const r = n.toString(16);
|
|
252
|
+
return r.length !== 2 ? '0' + r : r;
|
|
253
|
+
}
|
|
254
|
+
let label;
|
|
255
|
+
if (color.alpha === 1) {
|
|
256
|
+
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}`;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}${toTwoDigitHex(Math.round(color.alpha * 255))}`;
|
|
260
|
+
}
|
|
261
|
+
result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function getRange(document, node) {
|
|
266
|
+
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
267
|
+
}
|