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,68 +6,64 @@ import * as Parser from '../parser/jsonParser';
6
6
  import * as Strings from '../utils/strings';
7
7
  import { colorFromHex } from '../utils/colors';
8
8
  import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes";
9
- var JSONDocumentSymbols = /** @class */ (function () {
10
- function JSONDocumentSymbols(schemaService) {
9
+ export class JSONDocumentSymbols {
10
+ constructor(schemaService) {
11
11
  this.schemaService = schemaService;
12
12
  }
13
- JSONDocumentSymbols.prototype.findDocumentSymbols = function (document, doc, context) {
14
- var _this = this;
15
- if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
16
- var root = doc.root;
13
+ findDocumentSymbols(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
14
+ const root = doc.root;
17
15
  if (!root) {
18
16
  return [];
19
17
  }
20
- var limit = context.resultLimit || Number.MAX_VALUE;
18
+ let limit = context.resultLimit || Number.MAX_VALUE;
21
19
  // special handling for key bindings
22
- var resourceString = document.uri;
20
+ const resourceString = document.uri;
23
21
  if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
24
22
  if (root.type === 'array') {
25
- var result_1 = [];
26
- for (var _i = 0, _a = root.items; _i < _a.length; _i++) {
27
- var item = _a[_i];
23
+ const result = [];
24
+ for (const item of root.items) {
28
25
  if (item.type === 'object') {
29
- for (var _b = 0, _c = item.properties; _b < _c.length; _b++) {
30
- var property = _c[_b];
26
+ for (const property of item.properties) {
31
27
  if (property.keyNode.value === 'key' && property.valueNode) {
32
- var location = Location.create(document.uri, getRange(document, item));
33
- result_1.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location });
28
+ const location = Location.create(document.uri, getRange(document, item));
29
+ result.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location });
34
30
  limit--;
35
31
  if (limit <= 0) {
36
32
  if (context && context.onResultLimitExceeded) {
37
33
  context.onResultLimitExceeded(resourceString);
38
34
  }
39
- return result_1;
35
+ return result;
40
36
  }
41
37
  }
42
38
  }
43
39
  }
44
40
  }
45
- return result_1;
41
+ return result;
46
42
  }
47
43
  }
48
- var toVisit = [
44
+ const toVisit = [
49
45
  { node: root, containerName: '' }
50
46
  ];
51
- var nextToVisit = 0;
52
- var limitExceeded = false;
53
- var result = [];
54
- var collectOutlineEntries = function (node, containerName) {
47
+ let nextToVisit = 0;
48
+ let limitExceeded = false;
49
+ const result = [];
50
+ const collectOutlineEntries = (node, containerName) => {
55
51
  if (node.type === 'array') {
56
- node.items.forEach(function (node) {
52
+ node.items.forEach(node => {
57
53
  if (node) {
58
- toVisit.push({ node: node, containerName: containerName });
54
+ toVisit.push({ node, containerName });
59
55
  }
60
56
  });
61
57
  }
62
58
  else if (node.type === 'object') {
63
- node.properties.forEach(function (property) {
64
- var valueNode = property.valueNode;
59
+ node.properties.forEach((property) => {
60
+ const valueNode = property.valueNode;
65
61
  if (valueNode) {
66
62
  if (limit > 0) {
67
63
  limit--;
68
- var location = Location.create(document.uri, getRange(document, property));
69
- var childContainerName = containerName ? containerName + '.' + property.keyNode.value : property.keyNode.value;
70
- result.push({ name: _this.getKeyLabel(property), kind: _this.getSymbolKind(valueNode.type), location: location, containerName: containerName });
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 });
71
67
  toVisit.push({ node: valueNode, containerName: childContainerName });
72
68
  }
73
69
  else {
@@ -79,68 +75,64 @@ var JSONDocumentSymbols = /** @class */ (function () {
79
75
  };
80
76
  // breath first traversal
81
77
  while (nextToVisit < toVisit.length) {
82
- var next = toVisit[nextToVisit++];
78
+ const next = toVisit[nextToVisit++];
83
79
  collectOutlineEntries(next.node, next.containerName);
84
80
  }
85
81
  if (limitExceeded && context && context.onResultLimitExceeded) {
86
82
  context.onResultLimitExceeded(resourceString);
87
83
  }
88
84
  return result;
89
- };
90
- JSONDocumentSymbols.prototype.findDocumentSymbols2 = function (document, doc, context) {
91
- var _this = this;
92
- if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
93
- var root = doc.root;
85
+ }
86
+ findDocumentSymbols2(document, doc, context = { resultLimit: Number.MAX_VALUE }) {
87
+ const root = doc.root;
94
88
  if (!root) {
95
89
  return [];
96
90
  }
97
- var limit = context.resultLimit || Number.MAX_VALUE;
91
+ let limit = context.resultLimit || Number.MAX_VALUE;
98
92
  // special handling for key bindings
99
- var resourceString = document.uri;
93
+ const resourceString = document.uri;
100
94
  if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
101
95
  if (root.type === 'array') {
102
- var result_2 = [];
103
- for (var _i = 0, _a = root.items; _i < _a.length; _i++) {
104
- var item = _a[_i];
96
+ const result = [];
97
+ for (const item of root.items) {
105
98
  if (item.type === 'object') {
106
- for (var _b = 0, _c = item.properties; _b < _c.length; _b++) {
107
- var property = _c[_b];
99
+ for (const property of item.properties) {
108
100
  if (property.keyNode.value === 'key' && property.valueNode) {
109
- var range = getRange(document, item);
110
- var selectionRange = getRange(document, property.keyNode);
111
- result_2.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, range: range, selectionRange: selectionRange });
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 });
112
104
  limit--;
113
105
  if (limit <= 0) {
114
106
  if (context && context.onResultLimitExceeded) {
115
107
  context.onResultLimitExceeded(resourceString);
116
108
  }
117
- return result_2;
109
+ return result;
118
110
  }
119
111
  }
120
112
  }
121
113
  }
122
114
  }
123
- return result_2;
115
+ return result;
124
116
  }
125
117
  }
126
- var result = [];
127
- var toVisit = [
128
- { node: root, result: result }
118
+ const result = [];
119
+ const toVisit = [
120
+ { node: root, result }
129
121
  ];
130
- var nextToVisit = 0;
131
- var limitExceeded = false;
132
- var collectOutlineEntries = function (node, result) {
122
+ let nextToVisit = 0;
123
+ let limitExceeded = false;
124
+ const collectOutlineEntries = (node, result) => {
133
125
  if (node.type === 'array') {
134
- node.items.forEach(function (node, index) {
126
+ node.items.forEach((node, index) => {
135
127
  if (node) {
136
128
  if (limit > 0) {
137
129
  limit--;
138
- var range = getRange(document, node);
139
- var selectionRange = range;
140
- var name = String(index);
141
- var symbol = { name: name, kind: _this.getSymbolKind(node.type), range: range, selectionRange: selectionRange, children: [] };
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: [] };
142
134
  result.push(symbol);
143
- toVisit.push({ result: symbol.children, node: node });
135
+ toVisit.push({ result: symbol.children, node });
144
136
  }
145
137
  else {
146
138
  limitExceeded = true;
@@ -149,15 +141,15 @@ var JSONDocumentSymbols = /** @class */ (function () {
149
141
  });
150
142
  }
151
143
  else if (node.type === 'object') {
152
- node.properties.forEach(function (property) {
153
- var valueNode = property.valueNode;
144
+ node.properties.forEach((property) => {
145
+ const valueNode = property.valueNode;
154
146
  if (valueNode) {
155
147
  if (limit > 0) {
156
148
  limit--;
157
- var range = getRange(document, property);
158
- var selectionRange = getRange(document, property.keyNode);
159
- var children = [];
160
- var symbol = { name: _this.getKeyLabel(property), kind: _this.getSymbolKind(valueNode.type), range: range, selectionRange: selectionRange, children: children, detail: _this.getDetail(valueNode) };
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) };
161
153
  result.push(symbol);
162
154
  toVisit.push({ result: children, node: valueNode });
163
155
  }
@@ -170,15 +162,15 @@ var JSONDocumentSymbols = /** @class */ (function () {
170
162
  };
171
163
  // breath first traversal
172
164
  while (nextToVisit < toVisit.length) {
173
- var next = toVisit[nextToVisit++];
165
+ const next = toVisit[nextToVisit++];
174
166
  collectOutlineEntries(next.node, next.result);
175
167
  }
176
168
  if (limitExceeded && context && context.onResultLimitExceeded) {
177
169
  context.onResultLimitExceeded(resourceString);
178
170
  }
179
171
  return result;
180
- };
181
- JSONDocumentSymbols.prototype.getSymbolKind = function (nodeType) {
172
+ }
173
+ getSymbolKind(nodeType) {
182
174
  switch (nodeType) {
183
175
  case 'object':
184
176
  return SymbolKind.Module;
@@ -193,18 +185,18 @@ var JSONDocumentSymbols = /** @class */ (function () {
193
185
  default: // 'null'
194
186
  return SymbolKind.Variable;
195
187
  }
196
- };
197
- JSONDocumentSymbols.prototype.getKeyLabel = function (property) {
198
- var name = property.keyNode.value;
188
+ }
189
+ getKeyLabel(property) {
190
+ let name = property.keyNode.value;
199
191
  if (name) {
200
192
  name = name.replace(/[\n]/g, '↵');
201
193
  }
202
194
  if (name && name.trim()) {
203
195
  return name;
204
196
  }
205
- return "\"".concat(name, "\"");
206
- };
207
- JSONDocumentSymbols.prototype.getDetail = function (node) {
197
+ return `"${name}"`;
198
+ }
199
+ getDetail(node) {
208
200
  if (!node) {
209
201
  return undefined;
210
202
  }
@@ -220,23 +212,22 @@ var JSONDocumentSymbols = /** @class */ (function () {
220
212
  }
221
213
  }
222
214
  return undefined;
223
- };
224
- JSONDocumentSymbols.prototype.findDocumentColors = function (document, doc, context) {
225
- return this.schemaService.getSchemaForResource(document.uri, doc).then(function (schema) {
226
- var result = [];
215
+ }
216
+ findDocumentColors(document, doc, context) {
217
+ return this.schemaService.getSchemaForResource(document.uri, doc).then(schema => {
218
+ const result = [];
227
219
  if (schema) {
228
- var limit = context && typeof context.resultLimit === 'number' ? context.resultLimit : Number.MAX_VALUE;
229
- var matchingSchemas = doc.getMatchingSchemas(schema.schema);
230
- var visitedNode = {};
231
- for (var _i = 0, matchingSchemas_1 = matchingSchemas; _i < matchingSchemas_1.length; _i++) {
232
- var s = matchingSchemas_1[_i];
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) {
233
224
  if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
234
- var nodeId = String(s.node.offset);
225
+ const nodeId = String(s.node.offset);
235
226
  if (!visitedNode[nodeId]) {
236
- var color = colorFromHex(Parser.getNodeValue(s.node));
227
+ const color = colorFromHex(Parser.getNodeValue(s.node));
237
228
  if (color) {
238
- var range = getRange(document, s.node);
239
- result.push({ color: color, range: range });
229
+ const range = getRange(document, s.node);
230
+ result.push({ color, range });
240
231
  }
241
232
  visitedNode[nodeId] = true;
242
233
  limit--;
@@ -252,27 +243,25 @@ var JSONDocumentSymbols = /** @class */ (function () {
252
243
  }
253
244
  return result;
254
245
  });
255
- };
256
- JSONDocumentSymbols.prototype.getColorPresentations = function (document, doc, color, range) {
257
- var result = [];
258
- var red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
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);
259
250
  function toTwoDigitHex(n) {
260
- var r = n.toString(16);
251
+ const r = n.toString(16);
261
252
  return r.length !== 2 ? '0' + r : r;
262
253
  }
263
- var label;
254
+ let label;
264
255
  if (color.alpha === 1) {
265
- label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256));
256
+ label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}`;
266
257
  }
267
258
  else {
268
- label = "#".concat(toTwoDigitHex(red256)).concat(toTwoDigitHex(green256)).concat(toTwoDigitHex(blue256)).concat(toTwoDigitHex(Math.round(color.alpha * 255)));
259
+ label = `#${toTwoDigitHex(red256)}${toTwoDigitHex(green256)}${toTwoDigitHex(blue256)}${toTwoDigitHex(Math.round(color.alpha * 255))}`;
269
260
  }
270
261
  result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
271
262
  return result;
272
- };
273
- return JSONDocumentSymbols;
274
- }());
275
- export { JSONDocumentSymbols };
263
+ }
264
+ }
276
265
  function getRange(document, node) {
277
266
  return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
278
267
  }
@@ -5,31 +5,31 @@
5
5
  import { createScanner } from 'jsonc-parser';
6
6
  import { FoldingRangeKind, Position } from '../jsonLanguageTypes';
7
7
  export function getFoldingRanges(document, context) {
8
- var ranges = [];
9
- var nestingLevels = [];
10
- var stack = [];
11
- var prevStart = -1;
12
- var scanner = createScanner(document.getText(), false);
13
- var token = scanner.scan();
8
+ const ranges = [];
9
+ const nestingLevels = [];
10
+ const stack = [];
11
+ let prevStart = -1;
12
+ const scanner = createScanner(document.getText(), false);
13
+ let token = scanner.scan();
14
14
  function addRange(range) {
15
15
  ranges.push(range);
16
16
  nestingLevels.push(stack.length);
17
17
  }
18
- while (token !== 17 /* EOF */) {
18
+ while (token !== 17 /* SyntaxKind.EOF */) {
19
19
  switch (token) {
20
- case 1 /* OpenBraceToken */:
21
- case 3 /* OpenBracketToken */: {
22
- var startLine = document.positionAt(scanner.getTokenOffset()).line;
23
- var range = { startLine: startLine, endLine: startLine, kind: token === 1 /* OpenBraceToken */ ? 'object' : 'array' };
20
+ case 1 /* SyntaxKind.OpenBraceToken */:
21
+ case 3 /* SyntaxKind.OpenBracketToken */: {
22
+ const startLine = document.positionAt(scanner.getTokenOffset()).line;
23
+ const range = { startLine, endLine: startLine, kind: token === 1 /* SyntaxKind.OpenBraceToken */ ? 'object' : 'array' };
24
24
  stack.push(range);
25
25
  break;
26
26
  }
27
- case 2 /* CloseBraceToken */:
28
- case 4 /* CloseBracketToken */: {
29
- var kind = token === 2 /* CloseBraceToken */ ? 'object' : 'array';
27
+ case 2 /* SyntaxKind.CloseBraceToken */:
28
+ case 4 /* SyntaxKind.CloseBracketToken */: {
29
+ const kind = token === 2 /* SyntaxKind.CloseBraceToken */ ? 'object' : 'array';
30
30
  if (stack.length > 0 && stack[stack.length - 1].kind === kind) {
31
- var range = stack.pop();
32
- var line = document.positionAt(scanner.getTokenOffset()).line;
31
+ const range = stack.pop();
32
+ const line = document.positionAt(scanner.getTokenOffset()).line;
33
33
  if (range && line > range.startLine + 1 && prevStart !== range.startLine) {
34
34
  range.endLine = line - 1;
35
35
  addRange(range);
@@ -38,36 +38,36 @@ export function getFoldingRanges(document, context) {
38
38
  }
39
39
  break;
40
40
  }
41
- case 13 /* BlockCommentTrivia */: {
42
- var startLine = document.positionAt(scanner.getTokenOffset()).line;
43
- var endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line;
44
- if (scanner.getTokenError() === 1 /* UnexpectedEndOfComment */ && startLine + 1 < document.lineCount) {
41
+ case 13 /* SyntaxKind.BlockCommentTrivia */: {
42
+ const startLine = document.positionAt(scanner.getTokenOffset()).line;
43
+ const endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line;
44
+ if (scanner.getTokenError() === 1 /* ScanError.UnexpectedEndOfComment */ && startLine + 1 < document.lineCount) {
45
45
  scanner.setPosition(document.offsetAt(Position.create(startLine + 1, 0)));
46
46
  }
47
47
  else {
48
48
  if (startLine < endLine) {
49
- addRange({ startLine: startLine, endLine: endLine, kind: FoldingRangeKind.Comment });
49
+ addRange({ startLine, endLine, kind: FoldingRangeKind.Comment });
50
50
  prevStart = startLine;
51
51
  }
52
52
  }
53
53
  break;
54
54
  }
55
- case 12 /* LineCommentTrivia */: {
56
- var text = document.getText().substr(scanner.getTokenOffset(), scanner.getTokenLength());
57
- var m = text.match(/^\/\/\s*#(region\b)|(endregion\b)/);
55
+ case 12 /* SyntaxKind.LineCommentTrivia */: {
56
+ const text = document.getText().substr(scanner.getTokenOffset(), scanner.getTokenLength());
57
+ const m = text.match(/^\/\/\s*#(region\b)|(endregion\b)/);
58
58
  if (m) {
59
- var line = document.positionAt(scanner.getTokenOffset()).line;
59
+ const line = document.positionAt(scanner.getTokenOffset()).line;
60
60
  if (m[1]) { // start pattern match
61
- var range = { startLine: line, endLine: line, kind: FoldingRangeKind.Region };
61
+ const range = { startLine: line, endLine: line, kind: FoldingRangeKind.Region };
62
62
  stack.push(range);
63
63
  }
64
64
  else {
65
- var i = stack.length - 1;
65
+ let i = stack.length - 1;
66
66
  while (i >= 0 && stack[i].kind !== FoldingRangeKind.Region) {
67
67
  i--;
68
68
  }
69
69
  if (i >= 0) {
70
- var range = stack[i];
70
+ const range = stack[i];
71
71
  stack.length = i;
72
72
  if (line > range.startLine && prevStart !== range.startLine) {
73
73
  range.endLine = line;
@@ -82,24 +82,23 @@ export function getFoldingRanges(document, context) {
82
82
  }
83
83
  token = scanner.scan();
84
84
  }
85
- var rangeLimit = context && context.rangeLimit;
85
+ const rangeLimit = context && context.rangeLimit;
86
86
  if (typeof rangeLimit !== 'number' || ranges.length <= rangeLimit) {
87
87
  return ranges;
88
88
  }
89
89
  if (context && context.onRangeLimitExceeded) {
90
90
  context.onRangeLimitExceeded(document.uri);
91
91
  }
92
- var counts = [];
93
- for (var _i = 0, nestingLevels_1 = nestingLevels; _i < nestingLevels_1.length; _i++) {
94
- var level = nestingLevels_1[_i];
92
+ const counts = [];
93
+ for (let level of nestingLevels) {
95
94
  if (level < 30) {
96
95
  counts[level] = (counts[level] || 0) + 1;
97
96
  }
98
97
  }
99
- var entries = 0;
100
- var maxLevel = 0;
101
- for (var i = 0; i < counts.length; i++) {
102
- var n = counts[i];
98
+ let entries = 0;
99
+ let maxLevel = 0;
100
+ for (let i = 0; i < counts.length; i++) {
101
+ const n = counts[i];
103
102
  if (n) {
104
103
  if (n + entries > rangeLimit) {
105
104
  maxLevel = i;
@@ -108,9 +107,9 @@ export function getFoldingRanges(document, context) {
108
107
  entries += n;
109
108
  }
110
109
  }
111
- var result = [];
112
- for (var i = 0; i < ranges.length; i++) {
113
- var level = nestingLevels[i];
110
+ const result = [];
111
+ for (let i = 0; i < ranges.length; i++) {
112
+ const level = nestingLevels[i];
114
113
  if (typeof level === 'number') {
115
114
  if (level < maxLevel || (level === maxLevel && entries++ < rangeLimit)) {
116
115
  result.push(ranges[i]);
@@ -4,23 +4,22 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import * as Parser from '../parser/jsonParser';
6
6
  import { Range } from '../jsonLanguageTypes';
7
- var JSONHover = /** @class */ (function () {
8
- function JSONHover(schemaService, contributions, promiseConstructor) {
9
- if (contributions === void 0) { contributions = []; }
7
+ export class JSONHover {
8
+ constructor(schemaService, contributions = [], promiseConstructor) {
10
9
  this.schemaService = schemaService;
11
10
  this.contributions = contributions;
12
11
  this.promise = promiseConstructor || Promise;
13
12
  }
14
- JSONHover.prototype.doHover = function (document, position, doc) {
15
- var offset = document.offsetAt(position);
16
- var node = doc.getNodeFromOffset(offset);
13
+ doHover(document, position, doc) {
14
+ const offset = document.offsetAt(position);
15
+ let node = doc.getNodeFromOffset(offset);
17
16
  if (!node || (node.type === 'object' || node.type === 'array') && offset > node.offset + 1 && offset < node.offset + node.length - 1) {
18
17
  return this.promise.resolve(null);
19
18
  }
20
- var hoverRangeNode = node;
19
+ const hoverRangeNode = node;
21
20
  // use the property description when hovering over an object key
22
21
  if (node.type === 'string') {
23
- var parent = node.parent;
22
+ const parent = node.parent;
24
23
  if (parent && parent.type === 'property' && parent.keyNode === node) {
25
24
  node = parent.valueNode;
26
25
  if (!node) {
@@ -28,77 +27,75 @@ var JSONHover = /** @class */ (function () {
28
27
  }
29
28
  }
30
29
  }
31
- var hoverRange = Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length));
32
- var createHover = function (contents) {
33
- var result = {
30
+ const hoverRange = Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length));
31
+ var createHover = (contents) => {
32
+ const result = {
34
33
  contents: contents,
35
34
  range: hoverRange
36
35
  };
37
36
  return result;
38
37
  };
39
- var location = Parser.getNodePath(node);
40
- for (var i = this.contributions.length - 1; i >= 0; i--) {
41
- var contribution = this.contributions[i];
42
- var promise = contribution.getInfoContribution(document.uri, location);
38
+ const location = Parser.getNodePath(node);
39
+ for (let i = this.contributions.length - 1; i >= 0; i--) {
40
+ const contribution = this.contributions[i];
41
+ const promise = contribution.getInfoContribution(document.uri, location);
43
42
  if (promise) {
44
- return promise.then(function (htmlContent) { return createHover(htmlContent); });
43
+ return promise.then(htmlContent => createHover(htmlContent));
45
44
  }
46
45
  }
47
- return this.schemaService.getSchemaForResource(document.uri, doc).then(function (schema) {
46
+ return this.schemaService.getSchemaForResource(document.uri, doc).then((schema) => {
48
47
  if (schema && node) {
49
- var matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset);
50
- var title_1 = undefined;
51
- var markdownDescription_1 = undefined;
52
- var markdownEnumValueDescription_1 = undefined, enumValue_1 = undefined;
53
- matchingSchemas.every(function (s) {
48
+ const matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset);
49
+ let title = undefined;
50
+ let markdownDescription = undefined;
51
+ let markdownEnumValueDescription = undefined, enumValue = undefined;
52
+ matchingSchemas.every((s) => {
54
53
  if (s.node === node && !s.inverted && s.schema) {
55
- title_1 = title_1 || s.schema.title;
56
- markdownDescription_1 = markdownDescription_1 || s.schema.markdownDescription || toMarkdown(s.schema.description);
54
+ title = title || s.schema.title;
55
+ markdownDescription = markdownDescription || s.schema.markdownDescription || toMarkdown(s.schema.description);
57
56
  if (s.schema.enum) {
58
- var idx = s.schema.enum.indexOf(Parser.getNodeValue(node));
57
+ const idx = s.schema.enum.indexOf(Parser.getNodeValue(node));
59
58
  if (s.schema.markdownEnumDescriptions) {
60
- markdownEnumValueDescription_1 = s.schema.markdownEnumDescriptions[idx];
59
+ markdownEnumValueDescription = s.schema.markdownEnumDescriptions[idx];
61
60
  }
62
61
  else if (s.schema.enumDescriptions) {
63
- markdownEnumValueDescription_1 = toMarkdown(s.schema.enumDescriptions[idx]);
62
+ markdownEnumValueDescription = toMarkdown(s.schema.enumDescriptions[idx]);
64
63
  }
65
- if (markdownEnumValueDescription_1) {
66
- enumValue_1 = s.schema.enum[idx];
67
- if (typeof enumValue_1 !== 'string') {
68
- enumValue_1 = JSON.stringify(enumValue_1);
64
+ if (markdownEnumValueDescription) {
65
+ enumValue = s.schema.enum[idx];
66
+ if (typeof enumValue !== 'string') {
67
+ enumValue = JSON.stringify(enumValue);
69
68
  }
70
69
  }
71
70
  }
72
71
  }
73
72
  return true;
74
73
  });
75
- var result = '';
76
- if (title_1) {
77
- result = toMarkdown(title_1);
74
+ let result = '';
75
+ if (title) {
76
+ result = toMarkdown(title);
78
77
  }
79
- if (markdownDescription_1) {
78
+ if (markdownDescription) {
80
79
  if (result.length > 0) {
81
80
  result += "\n\n";
82
81
  }
83
- result += markdownDescription_1;
82
+ result += markdownDescription;
84
83
  }
85
- if (markdownEnumValueDescription_1) {
84
+ if (markdownEnumValueDescription) {
86
85
  if (result.length > 0) {
87
86
  result += "\n\n";
88
87
  }
89
- result += "`".concat(toMarkdownCodeBlock(enumValue_1), "`: ").concat(markdownEnumValueDescription_1);
88
+ result += `\`${toMarkdownCodeBlock(enumValue)}\`: ${markdownEnumValueDescription}`;
90
89
  }
91
90
  return createHover([result]);
92
91
  }
93
92
  return null;
94
93
  });
95
- };
96
- return JSONHover;
97
- }());
98
- export { JSONHover };
94
+ }
95
+ }
99
96
  function toMarkdown(plain) {
100
97
  if (plain) {
101
- var res = plain.replace(/([^\n\r])(\r?\n)([^\n\r])/gm, '$1\n\n$3'); // single new lines to \n\n (Markdown paragraph)
98
+ const res = plain.replace(/([^\n\r])(\r?\n)([^\n\r])/gm, '$1\n\n$3'); // single new lines to \n\n (Markdown paragraph)
102
99
  return res.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&"); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
103
100
  }
104
101
  return undefined;