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