vscode-json-languageservice 3.4.12 → 3.7.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.
- package/.nyc_output/0abe3076-16a9-4975-87da-4ecfc24d9226.json +1 -0
- package/.nyc_output/5a0d1463-368f-4136-8a80-4c7fda7ca33b.json +1 -0
- package/.nyc_output/65e3530f-ee58-4bcb-8484-70eb1822427e.json +1 -0
- package/.nyc_output/a37c9066-0aa4-4d91-a56b-17754005a42d.json +1 -0
- package/.nyc_output/b7eb272f-3bf3-48c4-9a42-90600332b363.json +1 -0
- package/.nyc_output/cabc6994-64f7-4258-bb45-9bb5529b388e.json +1 -0
- package/.nyc_output/processinfo/0abe3076-16a9-4975-87da-4ecfc24d9226.json +1 -0
- package/.nyc_output/processinfo/5a0d1463-368f-4136-8a80-4c7fda7ca33b.json +1 -0
- package/.nyc_output/processinfo/65e3530f-ee58-4bcb-8484-70eb1822427e.json +1 -0
- package/.nyc_output/processinfo/a37c9066-0aa4-4d91-a56b-17754005a42d.json +1 -0
- package/.nyc_output/processinfo/b7eb272f-3bf3-48c4-9a42-90600332b363.json +1 -0
- package/.nyc_output/processinfo/cabc6994-64f7-4258-bb45-9bb5529b388e.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/CHANGELOG.md +13 -1
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +156 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/index.html +126 -0
- package/coverage/lcov-report/src/jsonLanguageService.ts.html +383 -0
- package/coverage/lcov-report/src/jsonLanguageTypes.ts.html +968 -0
- package/coverage/lcov-report/src/parser/index.html +111 -0
- package/coverage/lcov-report/src/parser/jsonParser.ts.html +3860 -0
- package/coverage/lcov-report/src/services/configuration.ts.html +1679 -0
- package/coverage/lcov-report/src/services/index.html +216 -0
- package/coverage/lcov-report/src/services/jsonCompletion.ts.html +2843 -0
- package/coverage/lcov-report/src/services/jsonDocumentSymbols.ts.html +911 -0
- package/coverage/lcov-report/src/services/jsonFolding.ts.html +455 -0
- package/coverage/lcov-report/src/services/jsonHover.ts.html +461 -0
- package/coverage/lcov-report/src/services/jsonSchemaService.ts.html +1895 -0
- package/coverage/lcov-report/src/services/jsonSelectionRanges.ts.html +311 -0
- package/coverage/lcov-report/src/services/jsonValidation.ts.html +560 -0
- package/coverage/lcov-report/src/utils/colors.ts.html +299 -0
- package/coverage/lcov-report/src/utils/index.html +156 -0
- package/coverage/lcov-report/src/utils/json.ts.html +206 -0
- package/coverage/lcov-report/src/utils/objects.ts.html +296 -0
- package/coverage/lcov-report/src/utils/strings.ts.html +224 -0
- package/coverage/lcov.info +4219 -0
- package/lib/esm/jsonLanguageService.d.ts +2 -1
- package/lib/esm/jsonLanguageService.js +3 -1
- package/lib/esm/jsonLanguageTypes.d.ts +4 -2
- package/lib/esm/jsonSchema.d.ts +1 -0
- package/lib/esm/parser/jsonParser.js +31 -30
- package/lib/esm/services/configuration.js +2 -2
- package/lib/esm/services/jsonCompletion.js +39 -33
- package/lib/esm/services/jsonDefinition.js +83 -0
- package/lib/esm/services/jsonDocumentSymbols.js +4 -4
- package/lib/esm/services/jsonHover.js +5 -5
- package/lib/esm/services/jsonSchemaService.js +90 -79
- package/lib/esm/services/jsonValidation.js +9 -8
- package/lib/esm/utils/colors.js +2 -2
- package/lib/umd/jsonLanguageService.d.ts +2 -1
- package/lib/umd/jsonLanguageService.js +4 -2
- package/lib/umd/jsonLanguageTypes.d.ts +4 -2
- package/lib/umd/jsonSchema.d.ts +1 -0
- package/lib/umd/parser/jsonParser.js +31 -30
- package/lib/umd/services/configuration.js +2 -2
- package/lib/umd/services/jsonCompletion.js +39 -33
- package/lib/umd/services/jsonDefinition.js +96 -0
- package/lib/umd/services/jsonDocumentSymbols.js +4 -4
- package/lib/umd/services/jsonHover.js +5 -5
- package/lib/umd/services/jsonSchemaService.js +90 -79
- package/lib/umd/services/jsonValidation.js +9 -8
- package/lib/umd/utils/colors.js +2 -2
- package/package.json +19 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol } from './jsonLanguageTypes';
|
|
1
|
+
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink } from './jsonLanguageTypes';
|
|
2
2
|
export declare type JSONDocument = {};
|
|
3
3
|
export * from './jsonLanguageTypes';
|
|
4
4
|
export interface LanguageService {
|
|
@@ -19,5 +19,6 @@ export interface LanguageService {
|
|
|
19
19
|
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
|
|
20
20
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
21
21
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
22
|
+
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
22
23
|
}
|
|
23
24
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -13,6 +13,7 @@ import { getFoldingRanges } from './services/jsonFolding';
|
|
|
13
13
|
import { getSelectionRanges } from './services/jsonSelectionRanges';
|
|
14
14
|
import { format as formatJSON } from 'jsonc-parser';
|
|
15
15
|
import { Range, TextEdit } from './jsonLanguageTypes';
|
|
16
|
+
import { findDefinition } from './services/jsonDefinition';
|
|
16
17
|
export * from './jsonLanguageTypes';
|
|
17
18
|
export function getLanguageService(params) {
|
|
18
19
|
var promise = params.promiseConstructor || Promise;
|
|
@@ -46,8 +47,9 @@ export function getLanguageService(params) {
|
|
|
46
47
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
47
48
|
getFoldingRanges: getFoldingRanges,
|
|
48
49
|
getSelectionRanges: getSelectionRanges,
|
|
50
|
+
findDefinition: findDefinition,
|
|
49
51
|
format: function (d, r, o) {
|
|
50
|
-
var range =
|
|
52
|
+
var range = undefined;
|
|
51
53
|
if (r) {
|
|
52
54
|
var offset = d.offsetAt(r.start);
|
|
53
55
|
var length = d.offsetAt(r.end) - offset;
|
|
@@ -88,7 +88,7 @@ export interface LanguageSettings {
|
|
|
88
88
|
export declare type SeverityLevel = 'error' | 'warning' | 'ignore';
|
|
89
89
|
export interface DocumentLanguageSettings {
|
|
90
90
|
/**
|
|
91
|
-
* The severity of reported comments. If not set, 'LanguageSettings.allowComments' defines
|
|
91
|
+
* The severity of reported comments. If not set, 'LanguageSettings.allowComments' defines whether comments are ignored or reported as errors.
|
|
92
92
|
*/
|
|
93
93
|
comments?: SeverityLevel;
|
|
94
94
|
/**
|
|
@@ -102,7 +102,9 @@ export interface SchemaConfiguration {
|
|
|
102
102
|
*/
|
|
103
103
|
uri: string;
|
|
104
104
|
/**
|
|
105
|
-
* A list of file
|
|
105
|
+
* A list of file path patterns that are associated to the schema. The '*' wildcard can be used. Exclusion patterns starting with '!'.
|
|
106
|
+
* For example '*.schema.json', 'package.json', '!foo*.schema.json'.
|
|
107
|
+
* A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
|
|
106
108
|
*/
|
|
107
109
|
fileMatch?: string[];
|
|
108
110
|
/**
|
package/lib/esm/jsonSchema.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ var formats = {
|
|
|
29
29
|
};
|
|
30
30
|
var ASTNodeImpl = /** @class */ (function () {
|
|
31
31
|
function ASTNodeImpl(parent, offset, length) {
|
|
32
|
+
if (length === void 0) { length = 0; }
|
|
32
33
|
this.offset = offset;
|
|
33
34
|
this.length = length;
|
|
34
35
|
this.parent = parent;
|
|
@@ -111,10 +112,11 @@ var StringASTNodeImpl = /** @class */ (function (_super) {
|
|
|
111
112
|
export { StringASTNodeImpl };
|
|
112
113
|
var PropertyASTNodeImpl = /** @class */ (function (_super) {
|
|
113
114
|
__extends(PropertyASTNodeImpl, _super);
|
|
114
|
-
function PropertyASTNodeImpl(parent, offset) {
|
|
115
|
+
function PropertyASTNodeImpl(parent, offset, keyNode) {
|
|
115
116
|
var _this = _super.call(this, parent, offset) || this;
|
|
116
117
|
_this.type = 'property';
|
|
117
118
|
_this.colonOffset = -1;
|
|
119
|
+
_this.keyNode = keyNode;
|
|
118
120
|
return _this;
|
|
119
121
|
}
|
|
120
122
|
Object.defineProperty(PropertyASTNodeImpl.prototype, "children", {
|
|
@@ -159,7 +161,6 @@ export var EnumMatch;
|
|
|
159
161
|
var SchemaCollector = /** @class */ (function () {
|
|
160
162
|
function SchemaCollector(focusOffset, exclude) {
|
|
161
163
|
if (focusOffset === void 0) { focusOffset = -1; }
|
|
162
|
-
if (exclude === void 0) { exclude = null; }
|
|
163
164
|
this.focusOffset = focusOffset;
|
|
164
165
|
this.exclude = exclude;
|
|
165
166
|
this.schemas = [];
|
|
@@ -168,8 +169,7 @@ var SchemaCollector = /** @class */ (function () {
|
|
|
168
169
|
this.schemas.push(schema);
|
|
169
170
|
};
|
|
170
171
|
SchemaCollector.prototype.merge = function (other) {
|
|
171
|
-
|
|
172
|
-
(_a = this.schemas).push.apply(_a, other.schemas);
|
|
172
|
+
Array.prototype.push.apply(this.schemas, other.schemas);
|
|
173
173
|
};
|
|
174
174
|
SchemaCollector.prototype.include = function (node) {
|
|
175
175
|
return (this.focusOffset === -1 || contains(node, this.focusOffset)) && (node !== this.exclude);
|
|
@@ -201,7 +201,7 @@ var ValidationResult = /** @class */ (function () {
|
|
|
201
201
|
this.propertiesValueMatches = 0;
|
|
202
202
|
this.primaryValueMatches = 0;
|
|
203
203
|
this.enumValueMatch = false;
|
|
204
|
-
this.enumValues =
|
|
204
|
+
this.enumValues = undefined;
|
|
205
205
|
}
|
|
206
206
|
ValidationResult.prototype.hasProblems = function () {
|
|
207
207
|
return !!this.problems.length;
|
|
@@ -282,7 +282,7 @@ var JSONDocument = /** @class */ (function () {
|
|
|
282
282
|
if (this.root) {
|
|
283
283
|
return Json.findNodeAtOffset(this.root, offset, includeRightBound);
|
|
284
284
|
}
|
|
285
|
-
return
|
|
285
|
+
return undefined;
|
|
286
286
|
};
|
|
287
287
|
JSONDocument.prototype.visit = function (visitor) {
|
|
288
288
|
if (this.root) {
|
|
@@ -308,11 +308,10 @@ var JSONDocument = /** @class */ (function () {
|
|
|
308
308
|
return Diagnostic.create(range, p.message, p.severity, p.code);
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
|
-
return
|
|
311
|
+
return undefined;
|
|
312
312
|
};
|
|
313
313
|
JSONDocument.prototype.getMatchingSchemas = function (schema, focusOffset, exclude) {
|
|
314
314
|
if (focusOffset === void 0) { focusOffset = -1; }
|
|
315
|
-
if (exclude === void 0) { exclude = null; }
|
|
316
315
|
var matchingSchemas = new SchemaCollector(focusOffset, exclude);
|
|
317
316
|
if (this.root && schema) {
|
|
318
317
|
validate(this.root, schema, new ValidationResult(), matchingSchemas);
|
|
@@ -322,10 +321,11 @@ var JSONDocument = /** @class */ (function () {
|
|
|
322
321
|
return JSONDocument;
|
|
323
322
|
}());
|
|
324
323
|
export { JSONDocument };
|
|
325
|
-
function validate(
|
|
326
|
-
if (!
|
|
324
|
+
function validate(n, schema, validationResult, matchingSchemas) {
|
|
325
|
+
if (!n || !matchingSchemas.include(n)) {
|
|
327
326
|
return;
|
|
328
327
|
}
|
|
328
|
+
var node = n;
|
|
329
329
|
switch (node.type) {
|
|
330
330
|
case 'object':
|
|
331
331
|
_validateObjectNode(node, schema, validationResult, matchingSchemas);
|
|
@@ -393,7 +393,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
393
393
|
var testAlternatives = function (alternatives, maxOneMatch) {
|
|
394
394
|
var matches = [];
|
|
395
395
|
// remember the best match that is used for error messages
|
|
396
|
-
var bestMatch =
|
|
396
|
+
var bestMatch = undefined;
|
|
397
397
|
for (var _i = 0, alternatives_1 = alternatives; _i < alternatives_1.length; _i++) {
|
|
398
398
|
var subSchemaRef = alternatives_1[_i];
|
|
399
399
|
var subSchema = asSchema(subSchemaRef);
|
|
@@ -434,7 +434,7 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
434
434
|
message: localize('oneOfWarning', "Matches multiple schemas when only one must validate.")
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
|
-
if (bestMatch
|
|
437
|
+
if (bestMatch) {
|
|
438
438
|
validationResult.merge(bestMatch.validationResult);
|
|
439
439
|
validationResult.propertiesMatches += bestMatch.validationResult.propertiesMatches;
|
|
440
440
|
validationResult.propertiesValueMatches += bestMatch.validationResult.propertiesValueMatches;
|
|
@@ -539,13 +539,13 @@ function validate(node, schema, validationResult, matchingSchemas) {
|
|
|
539
539
|
if (isBoolean(exclusive) && exclusive) {
|
|
540
540
|
return limit;
|
|
541
541
|
}
|
|
542
|
-
return
|
|
542
|
+
return undefined;
|
|
543
543
|
}
|
|
544
544
|
function getLimit(limit, exclusive) {
|
|
545
545
|
if (!isBoolean(exclusive) || !exclusive) {
|
|
546
546
|
return limit;
|
|
547
547
|
}
|
|
548
|
-
return
|
|
548
|
+
return undefined;
|
|
549
549
|
}
|
|
550
550
|
var exclusiveMinimum = getExclusiveLimit(schema.minimum, schema.exclusiveMinimum);
|
|
551
551
|
if (isNumber(exclusiveMinimum) && val <= exclusiveMinimum) {
|
|
@@ -924,7 +924,7 @@ export function parse(textDocument, config) {
|
|
|
924
924
|
var lastProblemOffset = -1;
|
|
925
925
|
var text = textDocument.getText();
|
|
926
926
|
var scanner = Json.createScanner(text, false);
|
|
927
|
-
var commentRanges = config && config.collectComments ? [] :
|
|
927
|
+
var commentRanges = config && config.collectComments ? [] : undefined;
|
|
928
928
|
function _scanNext() {
|
|
929
929
|
while (true) {
|
|
930
930
|
var token_1 = scanner.scan();
|
|
@@ -960,7 +960,7 @@ export function parse(textDocument, config) {
|
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
962
|
function _error(message, code, node, skipUntilAfter, skipUntil) {
|
|
963
|
-
if (node === void 0) { node =
|
|
963
|
+
if (node === void 0) { node = undefined; }
|
|
964
964
|
if (skipUntilAfter === void 0) { skipUntilAfter = []; }
|
|
965
965
|
if (skipUntil === void 0) { skipUntil = []; }
|
|
966
966
|
var start = scanner.getTokenOffset();
|
|
@@ -1023,7 +1023,7 @@ export function parse(textDocument, config) {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
function _parseArray(parent) {
|
|
1025
1025
|
if (scanner.getToken() !== 3 /* OpenBracketToken */) {
|
|
1026
|
-
return
|
|
1026
|
+
return undefined;
|
|
1027
1027
|
}
|
|
1028
1028
|
var node = new ArrayASTNodeImpl(parent, scanner.getTokenOffset());
|
|
1029
1029
|
_scanNext(); // consume OpenBracketToken
|
|
@@ -1046,9 +1046,9 @@ export function parse(textDocument, config) {
|
|
|
1046
1046
|
else if (needsComma) {
|
|
1047
1047
|
_error(localize('ExpectedComma', 'Expected comma'), ErrorCode.CommaExpected);
|
|
1048
1048
|
}
|
|
1049
|
-
var item = _parseValue(node
|
|
1049
|
+
var item = _parseValue(node);
|
|
1050
1050
|
if (!item) {
|
|
1051
|
-
_error(localize('PropertyExpected', 'Value expected'), ErrorCode.ValueExpected,
|
|
1051
|
+
_error(localize('PropertyExpected', 'Value expected'), ErrorCode.ValueExpected, undefined, [], [4 /* CloseBracketToken */, 5 /* CommaToken */]);
|
|
1052
1052
|
}
|
|
1053
1053
|
else {
|
|
1054
1054
|
node.items.push(item);
|
|
@@ -1060,8 +1060,9 @@ export function parse(textDocument, config) {
|
|
|
1060
1060
|
}
|
|
1061
1061
|
return _finalize(node, true);
|
|
1062
1062
|
}
|
|
1063
|
+
var keyPlaceholder = new StringASTNodeImpl(undefined, 0, 0);
|
|
1063
1064
|
function _parseProperty(parent, keysSeen) {
|
|
1064
|
-
var node = new PropertyASTNodeImpl(parent, scanner.getTokenOffset());
|
|
1065
|
+
var node = new PropertyASTNodeImpl(parent, scanner.getTokenOffset(), keyPlaceholder);
|
|
1065
1066
|
var key = _parseString(node);
|
|
1066
1067
|
if (!key) {
|
|
1067
1068
|
if (scanner.getToken() === 16 /* Unknown */) {
|
|
@@ -1073,7 +1074,7 @@ export function parse(textDocument, config) {
|
|
|
1073
1074
|
_scanNext(); // consume Unknown
|
|
1074
1075
|
}
|
|
1075
1076
|
else {
|
|
1076
|
-
return
|
|
1077
|
+
return undefined;
|
|
1077
1078
|
}
|
|
1078
1079
|
}
|
|
1079
1080
|
node.keyNode = key;
|
|
@@ -1099,7 +1100,7 @@ export function parse(textDocument, config) {
|
|
|
1099
1100
|
return node;
|
|
1100
1101
|
}
|
|
1101
1102
|
}
|
|
1102
|
-
var value = _parseValue(node
|
|
1103
|
+
var value = _parseValue(node);
|
|
1103
1104
|
if (!value) {
|
|
1104
1105
|
return _error(localize('ValueExpected', 'Value expected'), ErrorCode.ValueExpected, node, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1105
1106
|
}
|
|
@@ -1109,7 +1110,7 @@ export function parse(textDocument, config) {
|
|
|
1109
1110
|
}
|
|
1110
1111
|
function _parseObject(parent) {
|
|
1111
1112
|
if (scanner.getToken() !== 1 /* OpenBraceToken */) {
|
|
1112
|
-
return
|
|
1113
|
+
return undefined;
|
|
1113
1114
|
}
|
|
1114
1115
|
var node = new ObjectASTNodeImpl(parent, scanner.getTokenOffset());
|
|
1115
1116
|
var keysSeen = Object.create(null);
|
|
@@ -1134,7 +1135,7 @@ export function parse(textDocument, config) {
|
|
|
1134
1135
|
}
|
|
1135
1136
|
var property = _parseProperty(node, keysSeen);
|
|
1136
1137
|
if (!property) {
|
|
1137
|
-
_error(localize('PropertyExpected', 'Property expected'), ErrorCode.PropertyExpected,
|
|
1138
|
+
_error(localize('PropertyExpected', 'Property expected'), ErrorCode.PropertyExpected, undefined, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1138
1139
|
}
|
|
1139
1140
|
else {
|
|
1140
1141
|
node.properties.push(property);
|
|
@@ -1148,7 +1149,7 @@ export function parse(textDocument, config) {
|
|
|
1148
1149
|
}
|
|
1149
1150
|
function _parseString(parent) {
|
|
1150
1151
|
if (scanner.getToken() !== 10 /* StringLiteral */) {
|
|
1151
|
-
return
|
|
1152
|
+
return undefined;
|
|
1152
1153
|
}
|
|
1153
1154
|
var node = new StringASTNodeImpl(parent, scanner.getTokenOffset());
|
|
1154
1155
|
node.value = scanner.getTokenValue();
|
|
@@ -1156,7 +1157,7 @@ export function parse(textDocument, config) {
|
|
|
1156
1157
|
}
|
|
1157
1158
|
function _parseNumber(parent) {
|
|
1158
1159
|
if (scanner.getToken() !== 11 /* NumericLiteral */) {
|
|
1159
|
-
return
|
|
1160
|
+
return undefined;
|
|
1160
1161
|
}
|
|
1161
1162
|
var node = new NumberASTNodeImpl(parent, scanner.getTokenOffset());
|
|
1162
1163
|
if (scanner.getTokenError() === 0 /* None */) {
|
|
@@ -1185,16 +1186,16 @@ export function parse(textDocument, config) {
|
|
|
1185
1186
|
case 9 /* FalseKeyword */:
|
|
1186
1187
|
return _finalize(new BooleanASTNodeImpl(parent, false, scanner.getTokenOffset()), true);
|
|
1187
1188
|
default:
|
|
1188
|
-
return
|
|
1189
|
+
return undefined;
|
|
1189
1190
|
}
|
|
1190
1191
|
}
|
|
1191
|
-
function _parseValue(parent
|
|
1192
|
+
function _parseValue(parent) {
|
|
1192
1193
|
return _parseArray(parent) || _parseObject(parent) || _parseString(parent) || _parseNumber(parent) || _parseLiteral(parent);
|
|
1193
1194
|
}
|
|
1194
|
-
var _root =
|
|
1195
|
+
var _root = undefined;
|
|
1195
1196
|
var token = _scanNext();
|
|
1196
1197
|
if (token !== 17 /* EOF */) {
|
|
1197
|
-
_root = _parseValue(
|
|
1198
|
+
_root = _parseValue(_root);
|
|
1198
1199
|
if (!_root) {
|
|
1199
1200
|
_error(localize('Invalid symbol', 'Expected a JSON object, array or literal.'), ErrorCode.Undefined);
|
|
1200
1201
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as nls from 'vscode-nls';
|
|
6
6
|
var localize = nls.loadMessageBundle();
|
|
7
7
|
export var schemaContributions = {
|
|
8
|
-
schemaAssociations:
|
|
8
|
+
schemaAssociations: [],
|
|
9
9
|
schemas: {
|
|
10
10
|
// refer to the latest schema
|
|
11
11
|
'http://json-schema.org/schema#': {
|
|
@@ -516,7 +516,7 @@ for (var schemaName in schemaContributions.schemas) {
|
|
|
516
516
|
var schema = schemaContributions.schemas[schemaName];
|
|
517
517
|
for (var property in schema.properties) {
|
|
518
518
|
var propertyObject = schema.properties[property];
|
|
519
|
-
if (propertyObject ===
|
|
519
|
+
if (typeof propertyObject === 'boolean') {
|
|
520
520
|
propertyObject = schema.properties[property] = {};
|
|
521
521
|
}
|
|
522
522
|
var description = descriptions[property];
|
|
@@ -21,12 +21,12 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
21
21
|
this.contributions = contributions;
|
|
22
22
|
this.promiseConstructor = promiseConstructor;
|
|
23
23
|
this.clientCapabilities = clientCapabilities;
|
|
24
|
-
this.templateVarIdCounter = 0;
|
|
25
24
|
}
|
|
26
25
|
JSONCompletion.prototype.doResolve = function (item) {
|
|
27
26
|
for (var i = this.contributions.length - 1; i >= 0; i--) {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
var resolveCompletion = this.contributions[i].resolveCompletion;
|
|
28
|
+
if (resolveCompletion) {
|
|
29
|
+
var resolver = resolveCompletion(item);
|
|
30
30
|
if (resolver) {
|
|
31
31
|
return resolver;
|
|
32
32
|
}
|
|
@@ -54,7 +54,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
var currentWord = this.getCurrentWord(document, offset);
|
|
57
|
-
var overwriteRange
|
|
57
|
+
var overwriteRange;
|
|
58
58
|
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
|
59
59
|
overwriteRange = Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
60
60
|
}
|
|
@@ -79,7 +79,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
79
79
|
label = shortendedLabel;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (overwriteRange) {
|
|
82
|
+
if (overwriteRange && suggestion.insertText !== undefined) {
|
|
83
83
|
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
|
|
84
84
|
}
|
|
85
85
|
if (supportsCommitCharacters) {
|
|
@@ -110,7 +110,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
110
110
|
var collectionPromises = [];
|
|
111
111
|
var addValue = true;
|
|
112
112
|
var currentKey = '';
|
|
113
|
-
var currentProperty =
|
|
113
|
+
var currentProperty = undefined;
|
|
114
114
|
if (node) {
|
|
115
115
|
if (node.type === 'string') {
|
|
116
116
|
var parent = node.parent;
|
|
@@ -160,7 +160,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
160
160
|
collector.add({
|
|
161
161
|
kind: CompletionItemKind.Property,
|
|
162
162
|
label: _this.getLabelForValue(currentWord),
|
|
163
|
-
insertText: _this.getInsertTextForProperty(currentWord,
|
|
163
|
+
insertText: _this.getInsertTextForProperty(currentWord, undefined, false, separatorAfter_1),
|
|
164
164
|
insertTextFormat: InsertTextFormat.Snippet, documentation: '',
|
|
165
165
|
});
|
|
166
166
|
collector.setAsIncomplete();
|
|
@@ -210,7 +210,10 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
210
210
|
filterText: _this.getFilterTextForValue(key),
|
|
211
211
|
documentation: _this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
|
|
212
212
|
};
|
|
213
|
-
if (
|
|
213
|
+
if (propertySchema.suggestSortText !== undefined) {
|
|
214
|
+
proposal.sortText = propertySchema.suggestSortText;
|
|
215
|
+
}
|
|
216
|
+
if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
|
|
214
217
|
proposal.command = {
|
|
215
218
|
title: 'Suggest',
|
|
216
219
|
command: 'editor.action.triggerSuggest'
|
|
@@ -262,7 +265,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
262
265
|
collector.add({
|
|
263
266
|
kind: CompletionItemKind.Property,
|
|
264
267
|
label: '$schema',
|
|
265
|
-
insertText: this.getInsertTextForProperty('$schema',
|
|
268
|
+
insertText: this.getInsertTextForProperty('$schema', undefined, true, ''),
|
|
266
269
|
insertTextFormat: InsertTextFormat.Snippet, documentation: '',
|
|
267
270
|
filterText: this.getFilterTextForValue("$schema")
|
|
268
271
|
});
|
|
@@ -294,7 +297,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
294
297
|
}
|
|
295
298
|
var separatorAfter = this.evaluateSeparatorAfter(document, offsetForSeparator);
|
|
296
299
|
var collectSuggestionsForValues = function (value) {
|
|
297
|
-
if (!Parser.contains(value.parent, offset, true)) {
|
|
300
|
+
if (value.parent && !Parser.contains(value.parent, offset, true)) {
|
|
298
301
|
collector.add({
|
|
299
302
|
kind: _this.getSuggestionKind(value.type),
|
|
300
303
|
label: _this.getLabelTextForMatchingNode(value, document),
|
|
@@ -307,7 +310,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
307
310
|
}
|
|
308
311
|
};
|
|
309
312
|
if (node.type === 'property') {
|
|
310
|
-
if (offset > node.colonOffset) {
|
|
313
|
+
if (offset > (node.colonOffset || 0)) {
|
|
311
314
|
var valueNode = node.valueNode;
|
|
312
315
|
if (valueNode && (offset > (valueNode.offset + valueNode.length) || valueNode.type === 'object' || valueNode.type === 'array')) {
|
|
313
316
|
return;
|
|
@@ -343,10 +346,9 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
343
346
|
}
|
|
344
347
|
};
|
|
345
348
|
JSONCompletion.prototype.getValueCompletions = function (schema, doc, node, offset, document, collector, types) {
|
|
346
|
-
var _this = this;
|
|
347
349
|
var offsetForSeparator = offset;
|
|
348
|
-
var parentKey =
|
|
349
|
-
var valueNode =
|
|
350
|
+
var parentKey = undefined;
|
|
351
|
+
var valueNode = undefined;
|
|
350
352
|
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
|
351
353
|
offsetForSeparator = node.offset + node.length;
|
|
352
354
|
valueNode = node;
|
|
@@ -356,7 +358,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
356
358
|
this.addSchemaValueCompletions(schema.schema, '', collector, types);
|
|
357
359
|
return;
|
|
358
360
|
}
|
|
359
|
-
if ((node.type === 'property') && offset > node.colonOffset) {
|
|
361
|
+
if ((node.type === 'property') && offset > (node.colonOffset || 0)) {
|
|
360
362
|
var valueNode_1 = node.valueNode;
|
|
361
363
|
if (valueNode_1 && offset > (valueNode_1.offset + valueNode_1.length)) {
|
|
362
364
|
return; // we are past the value node
|
|
@@ -364,39 +366,40 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
364
366
|
parentKey = node.keyNode.value;
|
|
365
367
|
node = node.parent;
|
|
366
368
|
}
|
|
367
|
-
if (node && (parentKey !==
|
|
368
|
-
var
|
|
369
|
+
if (node && (parentKey !== undefined || node.type === 'array')) {
|
|
370
|
+
var separatorAfter = this.evaluateSeparatorAfter(document, offsetForSeparator);
|
|
369
371
|
var matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset, valueNode);
|
|
370
|
-
matchingSchemas.
|
|
372
|
+
for (var _i = 0, matchingSchemas_1 = matchingSchemas; _i < matchingSchemas_1.length; _i++) {
|
|
373
|
+
var s = matchingSchemas_1[_i];
|
|
371
374
|
if (s.node === node && !s.inverted && s.schema) {
|
|
372
375
|
if (node.type === 'array' && s.schema.items) {
|
|
373
376
|
if (Array.isArray(s.schema.items)) {
|
|
374
|
-
var index =
|
|
377
|
+
var index = this.findItemAtOffset(node, document, offset);
|
|
375
378
|
if (index < s.schema.items.length) {
|
|
376
|
-
|
|
379
|
+
this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, collector, types);
|
|
377
380
|
}
|
|
378
381
|
}
|
|
379
382
|
else {
|
|
380
|
-
|
|
383
|
+
this.addSchemaValueCompletions(s.schema.items, separatorAfter, collector, types);
|
|
381
384
|
}
|
|
382
385
|
}
|
|
383
|
-
if (s.schema.properties) {
|
|
386
|
+
if (s.schema.properties && parentKey !== undefined) {
|
|
384
387
|
var propertySchema = s.schema.properties[parentKey];
|
|
385
388
|
if (propertySchema) {
|
|
386
|
-
|
|
389
|
+
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
|
|
387
390
|
}
|
|
388
391
|
}
|
|
389
392
|
}
|
|
390
|
-
}
|
|
393
|
+
}
|
|
391
394
|
if (parentKey === '$schema' && !node.parent) {
|
|
392
|
-
this.addDollarSchemaCompletions(
|
|
395
|
+
this.addDollarSchemaCompletions(separatorAfter, collector);
|
|
393
396
|
}
|
|
394
397
|
if (types['boolean']) {
|
|
395
|
-
this.addBooleanValueCompletion(true,
|
|
396
|
-
this.addBooleanValueCompletion(false,
|
|
398
|
+
this.addBooleanValueCompletion(true, separatorAfter, collector);
|
|
399
|
+
this.addBooleanValueCompletion(false, separatorAfter, collector);
|
|
397
400
|
}
|
|
398
401
|
if (types['null']) {
|
|
399
|
-
this.addNullValueCompletion(
|
|
402
|
+
this.addNullValueCompletion(separatorAfter, collector);
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
};
|
|
@@ -413,10 +416,10 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
413
416
|
if (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null') {
|
|
414
417
|
node = node.parent;
|
|
415
418
|
}
|
|
416
|
-
if ((node.type === 'property') && offset > node.colonOffset) {
|
|
419
|
+
if (node && (node.type === 'property') && offset > (node.colonOffset || 0)) {
|
|
417
420
|
var parentKey_4 = node.keyNode.value;
|
|
418
421
|
var valueNode = node.valueNode;
|
|
419
|
-
if (!valueNode || offset <= (valueNode.offset + valueNode.length)) {
|
|
422
|
+
if ((!valueNode || offset <= (valueNode.offset + valueNode.length)) && node.parent) {
|
|
420
423
|
var location_2 = Parser.getNodePath(node.parent);
|
|
421
424
|
this.contributions.forEach(function (contribution) {
|
|
422
425
|
var collectPromise = contribution.collectValueCompletions(document.uri, location_2, parentKey_4, collector);
|
|
@@ -511,6 +514,9 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
511
514
|
label = label || insertText,
|
|
512
515
|
filterText = insertText.replace(/[\n]/g, ''); // remove new lines
|
|
513
516
|
}
|
|
517
|
+
else {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
514
520
|
collector.add({
|
|
515
521
|
kind: _this.getSuggestionKind(type),
|
|
516
522
|
label: label,
|
|
@@ -522,7 +528,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
522
528
|
hasProposals = true;
|
|
523
529
|
});
|
|
524
530
|
}
|
|
525
|
-
if (!hasProposals && typeof schema.items === 'object' && !Array.isArray(schema.items)) {
|
|
531
|
+
if (!hasProposals && typeof schema.items === 'object' && !Array.isArray(schema.items) && arrayDepth < 5 /* beware of recursion */) {
|
|
526
532
|
this.addDefaultValueCompletions(schema.items, separatorAfter, collector, arrayDepth + 1);
|
|
527
533
|
}
|
|
528
534
|
};
|
|
@@ -564,7 +570,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
564
570
|
if (Array.isArray(type)) {
|
|
565
571
|
type.forEach(function (t) { return types[t] = true; });
|
|
566
572
|
}
|
|
567
|
-
else {
|
|
573
|
+
else if (type) {
|
|
568
574
|
types[type] = true;
|
|
569
575
|
}
|
|
570
576
|
};
|
|
@@ -677,7 +683,7 @@ var JSONCompletion = /** @class */ (function () {
|
|
|
677
683
|
JSONCompletion.prototype.getSuggestionKind = function (type) {
|
|
678
684
|
if (Array.isArray(type)) {
|
|
679
685
|
var array = type;
|
|
680
|
-
type = array.length > 0 ? array[0] :
|
|
686
|
+
type = array.length > 0 ? array[0] : undefined;
|
|
681
687
|
}
|
|
682
688
|
if (!type) {
|
|
683
689
|
return CompletionItemKind.Value;
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { Range } from '../jsonLanguageTypes';
|
|
6
|
+
export function findDefinition(document, position, doc) {
|
|
7
|
+
var offset = document.offsetAt(position);
|
|
8
|
+
var node = doc.getNodeFromOffset(offset, true);
|
|
9
|
+
if (!node || !isRef(node)) {
|
|
10
|
+
return Promise.resolve([]);
|
|
11
|
+
}
|
|
12
|
+
var propertyNode = node.parent;
|
|
13
|
+
var valueNode = propertyNode.valueNode;
|
|
14
|
+
var path = valueNode.value;
|
|
15
|
+
var targetNode = findTargetNode(doc, path);
|
|
16
|
+
if (!targetNode) {
|
|
17
|
+
return Promise.resolve([]);
|
|
18
|
+
}
|
|
19
|
+
var definition = {
|
|
20
|
+
targetUri: document.uri,
|
|
21
|
+
originSelectionRange: createRange(document, valueNode),
|
|
22
|
+
targetRange: createRange(document, targetNode),
|
|
23
|
+
targetSelectionRange: createRange(document, targetNode)
|
|
24
|
+
};
|
|
25
|
+
return Promise.resolve([definition]);
|
|
26
|
+
}
|
|
27
|
+
function createRange(document, node) {
|
|
28
|
+
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
29
|
+
}
|
|
30
|
+
function isRef(node) {
|
|
31
|
+
return node.type === 'string' &&
|
|
32
|
+
node.parent &&
|
|
33
|
+
node.parent.type === 'property' &&
|
|
34
|
+
node.parent.valueNode === node &&
|
|
35
|
+
node.parent.keyNode.value === "$ref" ||
|
|
36
|
+
false;
|
|
37
|
+
}
|
|
38
|
+
function findTargetNode(doc, path) {
|
|
39
|
+
var tokens = parseJSONPointer(path);
|
|
40
|
+
if (!tokens) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return findNode(tokens, doc.root);
|
|
44
|
+
}
|
|
45
|
+
function findNode(pointer, node) {
|
|
46
|
+
if (!node) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (pointer.length === 0) {
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
var token = pointer.shift();
|
|
53
|
+
if (node && node.type === 'object') {
|
|
54
|
+
var propertyNode = node.properties.find(function (propertyNode) { return propertyNode.keyNode.value === token; });
|
|
55
|
+
if (!propertyNode) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return findNode(pointer, propertyNode.valueNode);
|
|
59
|
+
}
|
|
60
|
+
else if (node && node.type === 'array') {
|
|
61
|
+
if (token.match(/^(0|[1-9][0-9]*)$/)) {
|
|
62
|
+
var index = Number.parseInt(token);
|
|
63
|
+
var arrayItem = node.items[index];
|
|
64
|
+
if (!arrayItem) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return findNode(pointer, arrayItem);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function parseJSONPointer(path) {
|
|
73
|
+
if (path === "#") {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
if (path[0] !== '#' || path[1] !== '/') {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return path.substring(2).split(/\//).map(unescape);
|
|
80
|
+
}
|
|
81
|
+
function unescape(str) {
|
|
82
|
+
return str.replace(/~1/g, '/').replace(/~0/g, '~');
|
|
83
|
+
}
|
|
@@ -15,9 +15,9 @@ var JSONDocumentSymbols = /** @class */ (function () {
|
|
|
15
15
|
if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
|
|
16
16
|
var root = doc.root;
|
|
17
17
|
if (!root) {
|
|
18
|
-
return
|
|
18
|
+
return [];
|
|
19
19
|
}
|
|
20
|
-
var limit = context.resultLimit;
|
|
20
|
+
var limit = context.resultLimit || Number.MAX_VALUE;
|
|
21
21
|
// special handling for key bindings
|
|
22
22
|
var resourceString = document.uri;
|
|
23
23
|
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
|
@@ -92,9 +92,9 @@ var JSONDocumentSymbols = /** @class */ (function () {
|
|
|
92
92
|
if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
|
|
93
93
|
var root = doc.root;
|
|
94
94
|
if (!root) {
|
|
95
|
-
return
|
|
95
|
+
return [];
|
|
96
96
|
}
|
|
97
|
-
var limit = context.resultLimit;
|
|
97
|
+
var limit = context.resultLimit || Number.MAX_VALUE;
|
|
98
98
|
// special handling for key bindings
|
|
99
99
|
var resourceString = document.uri;
|
|
100
100
|
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|