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