This commit is contained in:
528
node_modules/vscode-json-languageservice/lib/esm/services/configuration.js
generated
vendored
Normal file
528
node_modules/vscode-json-languageservice/lib/esm/services/configuration.js
generated
vendored
Normal file
@@ -0,0 +1,528 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as nls from 'vscode-nls';
|
||||
var localize = nls.loadMessageBundle();
|
||||
export var schemaContributions = {
|
||||
schemaAssociations: [],
|
||||
schemas: {
|
||||
// refer to the latest schema
|
||||
'http://json-schema.org/schema#': {
|
||||
$ref: 'http://json-schema.org/draft-07/schema#'
|
||||
},
|
||||
// bundle the schema-schema to include (localized) descriptions
|
||||
'http://json-schema.org/draft-04/schema#': {
|
||||
'$schema': 'http://json-schema.org/draft-04/schema#',
|
||||
'definitions': {
|
||||
'schemaArray': {
|
||||
'type': 'array',
|
||||
'minItems': 1,
|
||||
'items': {
|
||||
'$ref': '#'
|
||||
}
|
||||
},
|
||||
'positiveInteger': {
|
||||
'type': 'integer',
|
||||
'minimum': 0
|
||||
},
|
||||
'positiveIntegerDefault0': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveInteger'
|
||||
},
|
||||
{
|
||||
'default': 0
|
||||
}
|
||||
]
|
||||
},
|
||||
'simpleTypes': {
|
||||
'type': 'string',
|
||||
'enum': [
|
||||
'array',
|
||||
'boolean',
|
||||
'integer',
|
||||
'null',
|
||||
'number',
|
||||
'object',
|
||||
'string'
|
||||
]
|
||||
},
|
||||
'stringArray': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'string'
|
||||
},
|
||||
'minItems': 1,
|
||||
'uniqueItems': true
|
||||
}
|
||||
},
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'id': {
|
||||
'type': 'string',
|
||||
'format': 'uri'
|
||||
},
|
||||
'$schema': {
|
||||
'type': 'string',
|
||||
'format': 'uri'
|
||||
},
|
||||
'title': {
|
||||
'type': 'string'
|
||||
},
|
||||
'description': {
|
||||
'type': 'string'
|
||||
},
|
||||
'default': {},
|
||||
'multipleOf': {
|
||||
'type': 'number',
|
||||
'minimum': 0,
|
||||
'exclusiveMinimum': true
|
||||
},
|
||||
'maximum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'exclusiveMaximum': {
|
||||
'type': 'boolean',
|
||||
'default': false
|
||||
},
|
||||
'minimum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'exclusiveMinimum': {
|
||||
'type': 'boolean',
|
||||
'default': false
|
||||
},
|
||||
'maxLength': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveInteger'
|
||||
}
|
||||
]
|
||||
},
|
||||
'minLength': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveIntegerDefault0'
|
||||
}
|
||||
]
|
||||
},
|
||||
'pattern': {
|
||||
'type': 'string',
|
||||
'format': 'regex'
|
||||
},
|
||||
'additionalItems': {
|
||||
'anyOf': [
|
||||
{
|
||||
'type': 'boolean'
|
||||
},
|
||||
{
|
||||
'$ref': '#'
|
||||
}
|
||||
],
|
||||
'default': {}
|
||||
},
|
||||
'items': {
|
||||
'anyOf': [
|
||||
{
|
||||
'$ref': '#'
|
||||
},
|
||||
{
|
||||
'$ref': '#/definitions/schemaArray'
|
||||
}
|
||||
],
|
||||
'default': {}
|
||||
},
|
||||
'maxItems': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveInteger'
|
||||
}
|
||||
]
|
||||
},
|
||||
'minItems': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveIntegerDefault0'
|
||||
}
|
||||
]
|
||||
},
|
||||
'uniqueItems': {
|
||||
'type': 'boolean',
|
||||
'default': false
|
||||
},
|
||||
'maxProperties': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveInteger'
|
||||
}
|
||||
]
|
||||
},
|
||||
'minProperties': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/positiveIntegerDefault0'
|
||||
}
|
||||
]
|
||||
},
|
||||
'required': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/stringArray'
|
||||
}
|
||||
]
|
||||
},
|
||||
'additionalProperties': {
|
||||
'anyOf': [
|
||||
{
|
||||
'type': 'boolean'
|
||||
},
|
||||
{
|
||||
'$ref': '#'
|
||||
}
|
||||
],
|
||||
'default': {}
|
||||
},
|
||||
'definitions': {
|
||||
'type': 'object',
|
||||
'additionalProperties': {
|
||||
'$ref': '#'
|
||||
},
|
||||
'default': {}
|
||||
},
|
||||
'properties': {
|
||||
'type': 'object',
|
||||
'additionalProperties': {
|
||||
'$ref': '#'
|
||||
},
|
||||
'default': {}
|
||||
},
|
||||
'patternProperties': {
|
||||
'type': 'object',
|
||||
'additionalProperties': {
|
||||
'$ref': '#'
|
||||
},
|
||||
'default': {}
|
||||
},
|
||||
'dependencies': {
|
||||
'type': 'object',
|
||||
'additionalProperties': {
|
||||
'anyOf': [
|
||||
{
|
||||
'$ref': '#'
|
||||
},
|
||||
{
|
||||
'$ref': '#/definitions/stringArray'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'enum': {
|
||||
'type': 'array',
|
||||
'minItems': 1,
|
||||
'uniqueItems': true
|
||||
},
|
||||
'type': {
|
||||
'anyOf': [
|
||||
{
|
||||
'$ref': '#/definitions/simpleTypes'
|
||||
},
|
||||
{
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'$ref': '#/definitions/simpleTypes'
|
||||
},
|
||||
'minItems': 1,
|
||||
'uniqueItems': true
|
||||
}
|
||||
]
|
||||
},
|
||||
'format': {
|
||||
'anyOf': [
|
||||
{
|
||||
'type': 'string',
|
||||
'enum': [
|
||||
'date-time',
|
||||
'uri',
|
||||
'email',
|
||||
'hostname',
|
||||
'ipv4',
|
||||
'ipv6',
|
||||
'regex'
|
||||
]
|
||||
},
|
||||
{
|
||||
'type': 'string'
|
||||
}
|
||||
]
|
||||
},
|
||||
'allOf': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/schemaArray'
|
||||
}
|
||||
]
|
||||
},
|
||||
'anyOf': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/schemaArray'
|
||||
}
|
||||
]
|
||||
},
|
||||
'oneOf': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#/definitions/schemaArray'
|
||||
}
|
||||
]
|
||||
},
|
||||
'not': {
|
||||
'allOf': [
|
||||
{
|
||||
'$ref': '#'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'dependencies': {
|
||||
'exclusiveMaximum': [
|
||||
'maximum'
|
||||
],
|
||||
'exclusiveMinimum': [
|
||||
'minimum'
|
||||
]
|
||||
},
|
||||
'default': {}
|
||||
},
|
||||
'http://json-schema.org/draft-07/schema#': {
|
||||
'definitions': {
|
||||
'schemaArray': {
|
||||
'type': 'array',
|
||||
'minItems': 1,
|
||||
'items': { '$ref': '#' }
|
||||
},
|
||||
'nonNegativeInteger': {
|
||||
'type': 'integer',
|
||||
'minimum': 0
|
||||
},
|
||||
'nonNegativeIntegerDefault0': {
|
||||
'allOf': [
|
||||
{ '$ref': '#/definitions/nonNegativeInteger' },
|
||||
{ 'default': 0 }
|
||||
]
|
||||
},
|
||||
'simpleTypes': {
|
||||
'enum': [
|
||||
'array',
|
||||
'boolean',
|
||||
'integer',
|
||||
'null',
|
||||
'number',
|
||||
'object',
|
||||
'string'
|
||||
]
|
||||
},
|
||||
'stringArray': {
|
||||
'type': 'array',
|
||||
'items': { 'type': 'string' },
|
||||
'uniqueItems': true,
|
||||
'default': []
|
||||
}
|
||||
},
|
||||
'type': ['object', 'boolean'],
|
||||
'properties': {
|
||||
'$id': {
|
||||
'type': 'string',
|
||||
'format': 'uri-reference'
|
||||
},
|
||||
'$schema': {
|
||||
'type': 'string',
|
||||
'format': 'uri'
|
||||
},
|
||||
'$ref': {
|
||||
'type': 'string',
|
||||
'format': 'uri-reference'
|
||||
},
|
||||
'$comment': {
|
||||
'type': 'string'
|
||||
},
|
||||
'title': {
|
||||
'type': 'string'
|
||||
},
|
||||
'description': {
|
||||
'type': 'string'
|
||||
},
|
||||
'default': true,
|
||||
'readOnly': {
|
||||
'type': 'boolean',
|
||||
'default': false
|
||||
},
|
||||
'examples': {
|
||||
'type': 'array',
|
||||
'items': true
|
||||
},
|
||||
'multipleOf': {
|
||||
'type': 'number',
|
||||
'exclusiveMinimum': 0
|
||||
},
|
||||
'maximum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'exclusiveMaximum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'minimum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'exclusiveMinimum': {
|
||||
'type': 'number'
|
||||
},
|
||||
'maxLength': { '$ref': '#/definitions/nonNegativeInteger' },
|
||||
'minLength': { '$ref': '#/definitions/nonNegativeIntegerDefault0' },
|
||||
'pattern': {
|
||||
'type': 'string',
|
||||
'format': 'regex'
|
||||
},
|
||||
'additionalItems': { '$ref': '#' },
|
||||
'items': {
|
||||
'anyOf': [
|
||||
{ '$ref': '#' },
|
||||
{ '$ref': '#/definitions/schemaArray' }
|
||||
],
|
||||
'default': true
|
||||
},
|
||||
'maxItems': { '$ref': '#/definitions/nonNegativeInteger' },
|
||||
'minItems': { '$ref': '#/definitions/nonNegativeIntegerDefault0' },
|
||||
'uniqueItems': {
|
||||
'type': 'boolean',
|
||||
'default': false
|
||||
},
|
||||
'contains': { '$ref': '#' },
|
||||
'maxProperties': { '$ref': '#/definitions/nonNegativeInteger' },
|
||||
'minProperties': { '$ref': '#/definitions/nonNegativeIntegerDefault0' },
|
||||
'required': { '$ref': '#/definitions/stringArray' },
|
||||
'additionalProperties': { '$ref': '#' },
|
||||
'definitions': {
|
||||
'type': 'object',
|
||||
'additionalProperties': { '$ref': '#' },
|
||||
'default': {}
|
||||
},
|
||||
'properties': {
|
||||
'type': 'object',
|
||||
'additionalProperties': { '$ref': '#' },
|
||||
'default': {}
|
||||
},
|
||||
'patternProperties': {
|
||||
'type': 'object',
|
||||
'additionalProperties': { '$ref': '#' },
|
||||
'propertyNames': { 'format': 'regex' },
|
||||
'default': {}
|
||||
},
|
||||
'dependencies': {
|
||||
'type': 'object',
|
||||
'additionalProperties': {
|
||||
'anyOf': [
|
||||
{ '$ref': '#' },
|
||||
{ '$ref': '#/definitions/stringArray' }
|
||||
]
|
||||
}
|
||||
},
|
||||
'propertyNames': { '$ref': '#' },
|
||||
'const': true,
|
||||
'enum': {
|
||||
'type': 'array',
|
||||
'items': true,
|
||||
'minItems': 1,
|
||||
'uniqueItems': true
|
||||
},
|
||||
'type': {
|
||||
'anyOf': [
|
||||
{ '$ref': '#/definitions/simpleTypes' },
|
||||
{
|
||||
'type': 'array',
|
||||
'items': { '$ref': '#/definitions/simpleTypes' },
|
||||
'minItems': 1,
|
||||
'uniqueItems': true
|
||||
}
|
||||
]
|
||||
},
|
||||
'format': { 'type': 'string' },
|
||||
'contentMediaType': { 'type': 'string' },
|
||||
'contentEncoding': { 'type': 'string' },
|
||||
'if': { '$ref': '#' },
|
||||
'then': { '$ref': '#' },
|
||||
'else': { '$ref': '#' },
|
||||
'allOf': { '$ref': '#/definitions/schemaArray' },
|
||||
'anyOf': { '$ref': '#/definitions/schemaArray' },
|
||||
'oneOf': { '$ref': '#/definitions/schemaArray' },
|
||||
'not': { '$ref': '#' }
|
||||
},
|
||||
'default': true
|
||||
}
|
||||
}
|
||||
};
|
||||
var descriptions = {
|
||||
id: localize('schema.json.id', "A unique identifier for the schema."),
|
||||
$schema: localize('schema.json.$schema', "The schema to verify this document against."),
|
||||
title: localize('schema.json.title', "A descriptive title of the element."),
|
||||
description: localize('schema.json.description', "A long description of the element. Used in hover menus and suggestions."),
|
||||
default: localize('schema.json.default', "A default value. Used by suggestions."),
|
||||
multipleOf: localize('schema.json.multipleOf', "A number that should cleanly divide the current value (i.e. have no remainder)."),
|
||||
maximum: localize('schema.json.maximum', "The maximum numerical value, inclusive by default."),
|
||||
exclusiveMaximum: localize('schema.json.exclusiveMaximum', "Makes the maximum property exclusive."),
|
||||
minimum: localize('schema.json.minimum', "The minimum numerical value, inclusive by default."),
|
||||
exclusiveMinimum: localize('schema.json.exclusiveMininum', "Makes the minimum property exclusive."),
|
||||
maxLength: localize('schema.json.maxLength', "The maximum length of a string."),
|
||||
minLength: localize('schema.json.minLength', "The minimum length of a string."),
|
||||
pattern: localize('schema.json.pattern', "A regular expression to match the string against. It is not implicitly anchored."),
|
||||
additionalItems: localize('schema.json.additionalItems', "For arrays, only when items is set as an array. If it is a schema, then this schema validates items after the ones specified by the items array. If it is false, then additional items will cause validation to fail."),
|
||||
items: localize('schema.json.items', "For arrays. Can either be a schema to validate every element against or an array of schemas to validate each item against in order (the first schema will validate the first element, the second schema will validate the second element, and so on."),
|
||||
maxItems: localize('schema.json.maxItems', "The maximum number of items that can be inside an array. Inclusive."),
|
||||
minItems: localize('schema.json.minItems', "The minimum number of items that can be inside an array. Inclusive."),
|
||||
uniqueItems: localize('schema.json.uniqueItems', "If all of the items in the array must be unique. Defaults to false."),
|
||||
maxProperties: localize('schema.json.maxProperties', "The maximum number of properties an object can have. Inclusive."),
|
||||
minProperties: localize('schema.json.minProperties', "The minimum number of properties an object can have. Inclusive."),
|
||||
required: localize('schema.json.required', "An array of strings that lists the names of all properties required on this object."),
|
||||
additionalProperties: localize('schema.json.additionalProperties', "Either a schema or a boolean. If a schema, then used to validate all properties not matched by 'properties' or 'patternProperties'. If false, then any properties not matched by either will cause this schema to fail."),
|
||||
definitions: localize('schema.json.definitions', "Not used for validation. Place subschemas here that you wish to reference inline with $ref."),
|
||||
properties: localize('schema.json.properties', "A map of property names to schemas for each property."),
|
||||
patternProperties: localize('schema.json.patternProperties', "A map of regular expressions on property names to schemas for matching properties."),
|
||||
dependencies: localize('schema.json.dependencies', "A map of property names to either an array of property names or a schema. An array of property names means the property named in the key depends on the properties in the array being present in the object in order to be valid. If the value is a schema, then the schema is only applied to the object if the property in the key exists on the object."),
|
||||
enum: localize('schema.json.enum', "The set of literal values that are valid."),
|
||||
type: localize('schema.json.type', "Either a string of one of the basic schema types (number, integer, null, array, object, boolean, string) or an array of strings specifying a subset of those types."),
|
||||
format: localize('schema.json.format', "Describes the format expected for the value."),
|
||||
allOf: localize('schema.json.allOf', "An array of schemas, all of which must match."),
|
||||
anyOf: localize('schema.json.anyOf', "An array of schemas, where at least one must match."),
|
||||
oneOf: localize('schema.json.oneOf', "An array of schemas, exactly one of which must match."),
|
||||
not: localize('schema.json.not', "A schema which must not match."),
|
||||
$id: localize('schema.json.$id', "A unique identifier for the schema."),
|
||||
$ref: localize('schema.json.$ref', "Reference a definition hosted on any location."),
|
||||
$comment: localize('schema.json.$comment', "Comments from schema authors to readers or maintainers of the schema."),
|
||||
readOnly: localize('schema.json.readOnly', "Indicates that the value of the instance is managed exclusively by the owning authority."),
|
||||
examples: localize('schema.json.examples', "Sample JSON values associated with a particular schema, for the purpose of illustrating usage."),
|
||||
contains: localize('schema.json.contains', "An array instance is valid against \"contains\" if at least one of its elements is valid against the given schema."),
|
||||
propertyNames: localize('schema.json.propertyNames', "If the instance is an object, this keyword validates if every property name in the instance validates against the provided schema."),
|
||||
const: localize('schema.json.const', "An instance validates successfully against this keyword if its value is equal to the value of the keyword."),
|
||||
contentMediaType: localize('schema.json.contentMediaType', "Describes the media type of a string property."),
|
||||
contentEncoding: localize('schema.json.contentEncoding', "Describes the content encoding of a string property."),
|
||||
if: localize('schema.json.if', "The validation outcome of the \"if\" subschema controls which of the \"then\" or \"else\" keywords are evaluated."),
|
||||
then: localize('schema.json.then', "The \"if\" subschema is used for validation when the \"if\" subschema succeeds."),
|
||||
else: localize('schema.json.else', "The \"else\" subschema is used for validation when the \"if\" subschema fails.")
|
||||
};
|
||||
for (var schemaName in schemaContributions.schemas) {
|
||||
var schema = schemaContributions.schemas[schemaName];
|
||||
for (var property in schema.properties) {
|
||||
var propertyObject = schema.properties[property];
|
||||
if (typeof propertyObject === 'boolean') {
|
||||
propertyObject = schema.properties[property] = {};
|
||||
}
|
||||
var description = descriptions[property];
|
||||
if (description) {
|
||||
propertyObject['description'] = description;
|
||||
}
|
||||
else {
|
||||
console.log(property + ": localize('schema.json." + property + "', \"\")");
|
||||
}
|
||||
}
|
||||
}
|
||||
934
node_modules/vscode-json-languageservice/lib/esm/services/jsonCompletion.js
generated
vendored
Normal file
934
node_modules/vscode-json-languageservice/lib/esm/services/jsonCompletion.js
generated
vendored
Normal file
@@ -0,0 +1,934 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as Parser from '../parser/jsonParser';
|
||||
import * as Json from 'jsonc-parser';
|
||||
import { stringifyObject } from '../utils/json';
|
||||
import { endsWith, extendedRegExp } from '../utils/strings';
|
||||
import { isDefined } from '../utils/objects';
|
||||
import { CompletionItem, CompletionItemKind, Range, TextEdit, InsertTextFormat, MarkupKind } from '../jsonLanguageTypes';
|
||||
import * as nls from 'vscode-nls';
|
||||
var localize = nls.loadMessageBundle();
|
||||
var valueCommitCharacters = [',', '}', ']'];
|
||||
var propertyCommitCharacters = [':'];
|
||||
var JSONCompletion = /** @class */ (function () {
|
||||
function JSONCompletion(schemaService, contributions, promiseConstructor, clientCapabilities) {
|
||||
if (contributions === void 0) { contributions = []; }
|
||||
if (promiseConstructor === void 0) { promiseConstructor = Promise; }
|
||||
if (clientCapabilities === void 0) { clientCapabilities = {}; }
|
||||
this.schemaService = schemaService;
|
||||
this.contributions = contributions;
|
||||
this.promiseConstructor = promiseConstructor;
|
||||
this.clientCapabilities = clientCapabilities;
|
||||
}
|
||||
JSONCompletion.prototype.doResolve = function (item) {
|
||||
for (var i = this.contributions.length - 1; i >= 0; i--) {
|
||||
var resolveCompletion = this.contributions[i].resolveCompletion;
|
||||
if (resolveCompletion) {
|
||||
var resolver = resolveCompletion(item);
|
||||
if (resolver) {
|
||||
return resolver;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.promiseConstructor.resolve(item);
|
||||
};
|
||||
JSONCompletion.prototype.doComplete = function (document, position, doc) {
|
||||
var _this = this;
|
||||
var result = {
|
||||
items: [],
|
||||
isIncomplete: false
|
||||
};
|
||||
var text = document.getText();
|
||||
var offset = document.offsetAt(position);
|
||||
var node = doc.getNodeFromOffset(offset, true);
|
||||
if (this.isInComment(document, node ? node.offset : 0, offset)) {
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
if (node && (offset === node.offset + node.length) && offset > 0) {
|
||||
var ch = text[offset - 1];
|
||||
if (node.type === 'object' && ch === '}' || node.type === 'array' && ch === ']') {
|
||||
// after ] or }
|
||||
node = node.parent;
|
||||
}
|
||||
}
|
||||
var currentWord = this.getCurrentWord(document, offset);
|
||||
var overwriteRange;
|
||||
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
||||
overwriteRange = Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
||||
}
|
||||
else {
|
||||
var overwriteStart = offset - currentWord.length;
|
||||
if (overwriteStart > 0 && text[overwriteStart - 1] === '"') {
|
||||
overwriteStart--;
|
||||
}
|
||||
overwriteRange = Range.create(document.positionAt(overwriteStart), position);
|
||||
}
|
||||
var supportsCommitCharacters = false; //this.doesSupportsCommitCharacters(); disabled for now, waiting for new API: https://github.com/microsoft/vscode/issues/42544
|
||||
var proposed = {};
|
||||
var collector = {
|
||||
add: function (suggestion) {
|
||||
var label = suggestion.label;
|
||||
var existing = proposed[label];
|
||||
if (!existing) {
|
||||
label = label.replace(/[\n]/g, '↵');
|
||||
if (label.length > 60) {
|
||||
var shortendedLabel = label.substr(0, 57).trim() + '...';
|
||||
if (!proposed[shortendedLabel]) {
|
||||
label = shortendedLabel;
|
||||
}
|
||||
}
|
||||
if (overwriteRange && suggestion.insertText !== undefined) {
|
||||
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
|
||||
}
|
||||
if (supportsCommitCharacters) {
|
||||
suggestion.commitCharacters = suggestion.kind === CompletionItemKind.Property ? propertyCommitCharacters : valueCommitCharacters;
|
||||
}
|
||||
suggestion.label = label;
|
||||
proposed[label] = suggestion;
|
||||
result.items.push(suggestion);
|
||||
}
|
||||
else {
|
||||
if (!existing.documentation) {
|
||||
existing.documentation = suggestion.documentation;
|
||||
}
|
||||
if (!existing.detail) {
|
||||
existing.detail = suggestion.detail;
|
||||
}
|
||||
}
|
||||
},
|
||||
setAsIncomplete: function () {
|
||||
result.isIncomplete = true;
|
||||
},
|
||||
error: function (message) {
|
||||
console.error(message);
|
||||
},
|
||||
log: function (message) {
|
||||
console.log(message);
|
||||
},
|
||||
getNumberOfProposals: function () {
|
||||
return result.items.length;
|
||||
}
|
||||
};
|
||||
return this.schemaService.getSchemaForResource(document.uri, doc).then(function (schema) {
|
||||
var collectionPromises = [];
|
||||
var addValue = true;
|
||||
var currentKey = '';
|
||||
var currentProperty = undefined;
|
||||
if (node) {
|
||||
if (node.type === 'string') {
|
||||
var parent = node.parent;
|
||||
if (parent && parent.type === 'property' && parent.keyNode === node) {
|
||||
addValue = !parent.valueNode;
|
||||
currentProperty = parent;
|
||||
currentKey = text.substr(node.offset + 1, node.length - 2);
|
||||
if (parent) {
|
||||
node = parent.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// proposals for properties
|
||||
if (node && node.type === 'object') {
|
||||
// don't suggest keys when the cursor is just before the opening curly brace
|
||||
if (node.offset === offset) {
|
||||
return result;
|
||||
}
|
||||
// don't suggest properties that are already present
|
||||
var properties = node.properties;
|
||||
properties.forEach(function (p) {
|
||||
if (!currentProperty || currentProperty !== p) {
|
||||
proposed[p.keyNode.value] = CompletionItem.create('__');
|
||||
}
|
||||
});
|
||||
var separatorAfter_1 = '';
|
||||
if (addValue) {
|
||||
separatorAfter_1 = _this.evaluateSeparatorAfter(document, document.offsetAt(overwriteRange.end));
|
||||
}
|
||||
if (schema) {
|
||||
// property proposals with schema
|
||||
_this.getPropertyCompletions(schema, doc, node, addValue, separatorAfter_1, collector);
|
||||
}
|
||||
else {
|
||||
// property proposals without schema
|
||||
_this.getSchemaLessPropertyCompletions(doc, node, currentKey, collector);
|
||||
}
|
||||
var location_1 = Parser.getNodePath(node);
|
||||
_this.contributions.forEach(function (contribution) {
|
||||
var collectPromise = contribution.collectPropertyCompletions(document.uri, location_1, currentWord, addValue, separatorAfter_1 === '', collector);
|
||||
if (collectPromise) {
|
||||
collectionPromises.push(collectPromise);
|
||||
}
|
||||
});
|
||||
if ((!schema && currentWord.length > 0 && text.charAt(offset - currentWord.length - 1) !== '"')) {
|
||||
collector.add({
|
||||
kind: CompletionItemKind.Property,
|
||||
label: _this.getLabelForValue(currentWord),
|
||||
insertText: _this.getInsertTextForProperty(currentWord, undefined, false, separatorAfter_1),
|
||||
insertTextFormat: InsertTextFormat.Snippet, documentation: '',
|
||||
});
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
// proposals for values
|
||||
var types = {};
|
||||
if (schema) {
|
||||
// value proposals with schema
|
||||
_this.getValueCompletions(schema, doc, node, offset, document, collector, types);
|
||||
}
|
||||
else {
|
||||
// value proposals without schema
|
||||
_this.getSchemaLessValueCompletions(doc, node, offset, document, collector);
|
||||
}
|
||||
if (_this.contributions.length > 0) {
|
||||
_this.getContributedValueCompletions(doc, node, offset, document, collector, collectionPromises);
|
||||
}
|
||||
return _this.promiseConstructor.all(collectionPromises).then(function () {
|
||||
if (collector.getNumberOfProposals() === 0) {
|
||||
var offsetForSeparator = offset;
|
||||
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
||||
offsetForSeparator = node.offset + node.length;
|
||||
}
|
||||
var separatorAfter = _this.evaluateSeparatorAfter(document, offsetForSeparator);
|
||||
_this.addFillerValueCompletions(types, separatorAfter, collector);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
});
|
||||
};
|
||||
JSONCompletion.prototype.getPropertyCompletions = function (schema, doc, node, addValue, separatorAfter, collector) {
|
||||
var _this = this;
|
||||
var matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset);
|
||||
matchingSchemas.forEach(function (s) {
|
||||
if (s.node === node && !s.inverted) {
|
||||
var schemaProperties_1 = s.schema.properties;
|
||||
if (schemaProperties_1) {
|
||||
Object.keys(schemaProperties_1).forEach(function (key) {
|
||||
var propertySchema = schemaProperties_1[key];
|
||||
if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema.doNotSuggest) {
|
||||
var proposal = {
|
||||
kind: CompletionItemKind.Property,
|
||||
label: key,
|
||||
insertText: _this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
filterText: _this.getFilterTextForValue(key),
|
||||
documentation: _this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
|
||||
};
|
||||
if (propertySchema.suggestSortText !== undefined) {
|
||||
proposal.sortText = propertySchema.suggestSortText;
|
||||
}
|
||||
if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
|
||||
proposal.command = {
|
||||
title: 'Suggest',
|
||||
command: 'editor.action.triggerSuggest'
|
||||
};
|
||||
}
|
||||
collector.add(proposal);
|
||||
}
|
||||
});
|
||||
}
|
||||
var schemaPropertyNames_1 = s.schema.propertyNames;
|
||||
if (typeof schemaPropertyNames_1 === 'object' && !schemaPropertyNames_1.deprecationMessage && !schemaPropertyNames_1.doNotSuggest) {
|
||||
var propertyNameCompletionItem = function (name, enumDescription) {
|
||||
if (enumDescription === void 0) { enumDescription = undefined; }
|
||||
var proposal = {
|
||||
kind: CompletionItemKind.Property,
|
||||
label: name,
|
||||
insertText: _this.getInsertTextForProperty(name, undefined, addValue, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
filterText: _this.getFilterTextForValue(name),
|
||||
documentation: enumDescription || _this.fromMarkup(schemaPropertyNames_1.markdownDescription) || schemaPropertyNames_1.description || '',
|
||||
};
|
||||
if (schemaPropertyNames_1.suggestSortText !== undefined) {
|
||||
proposal.sortText = schemaPropertyNames_1.suggestSortText;
|
||||
}
|
||||
if (proposal.insertText && endsWith(proposal.insertText, "$1" + separatorAfter)) {
|
||||
proposal.command = {
|
||||
title: 'Suggest',
|
||||
command: 'editor.action.triggerSuggest'
|
||||
};
|
||||
}
|
||||
collector.add(proposal);
|
||||
};
|
||||
if (schemaPropertyNames_1.enum) {
|
||||
for (var i = 0; i < schemaPropertyNames_1.enum.length; i++) {
|
||||
var enumDescription = undefined;
|
||||
if (schemaPropertyNames_1.markdownEnumDescriptions && i < schemaPropertyNames_1.markdownEnumDescriptions.length) {
|
||||
enumDescription = _this.fromMarkup(schemaPropertyNames_1.markdownEnumDescriptions[i]);
|
||||
}
|
||||
else if (schemaPropertyNames_1.enumDescriptions && i < schemaPropertyNames_1.enumDescriptions.length) {
|
||||
enumDescription = schemaPropertyNames_1.enumDescriptions[i];
|
||||
}
|
||||
propertyNameCompletionItem(schemaPropertyNames_1.enum[i], enumDescription);
|
||||
}
|
||||
}
|
||||
if (schemaPropertyNames_1.const) {
|
||||
propertyNameCompletionItem(schemaPropertyNames_1.const);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
JSONCompletion.prototype.getSchemaLessPropertyCompletions = function (doc, node, currentKey, collector) {
|
||||
var _this = this;
|
||||
var collectCompletionsForSimilarObject = function (obj) {
|
||||
obj.properties.forEach(function (p) {
|
||||
var key = p.keyNode.value;
|
||||
collector.add({
|
||||
kind: CompletionItemKind.Property,
|
||||
label: key,
|
||||
insertText: _this.getInsertTextForValue(key, ''),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
filterText: _this.getFilterTextForValue(key),
|
||||
documentation: ''
|
||||
});
|
||||
});
|
||||
};
|
||||
if (node.parent) {
|
||||
if (node.parent.type === 'property') {
|
||||
// if the object is a property value, check the tree for other objects that hang under a property of the same name
|
||||
var parentKey_1 = node.parent.keyNode.value;
|
||||
doc.visit(function (n) {
|
||||
if (n.type === 'property' && n !== node.parent && n.keyNode.value === parentKey_1 && n.valueNode && n.valueNode.type === 'object') {
|
||||
collectCompletionsForSimilarObject(n.valueNode);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
else if (node.parent.type === 'array') {
|
||||
// if the object is in an array, use all other array elements as similar objects
|
||||
node.parent.items.forEach(function (n) {
|
||||
if (n.type === 'object' && n !== node) {
|
||||
collectCompletionsForSimilarObject(n);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (node.type === 'object') {
|
||||
collector.add({
|
||||
kind: CompletionItemKind.Property,
|
||||
label: '$schema',
|
||||
insertText: this.getInsertTextForProperty('$schema', undefined, true, ''),
|
||||
insertTextFormat: InsertTextFormat.Snippet, documentation: '',
|
||||
filterText: this.getFilterTextForValue("$schema")
|
||||
});
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getSchemaLessValueCompletions = function (doc, node, offset, document, collector) {
|
||||
var _this = this;
|
||||
var offsetForSeparator = offset;
|
||||
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
||||
offsetForSeparator = node.offset + node.length;
|
||||
node = node.parent;
|
||||
}
|
||||
if (!node) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('object'),
|
||||
label: 'Empty object',
|
||||
insertText: this.getInsertTextForValue({}, ''),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: ''
|
||||
});
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('array'),
|
||||
label: 'Empty array',
|
||||
insertText: this.getInsertTextForValue([], ''),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: ''
|
||||
});
|
||||
return;
|
||||
}
|
||||
var separatorAfter = this.evaluateSeparatorAfter(document, offsetForSeparator);
|
||||
var collectSuggestionsForValues = function (value) {
|
||||
if (value.parent && !Parser.contains(value.parent, offset, true)) {
|
||||
collector.add({
|
||||
kind: _this.getSuggestionKind(value.type),
|
||||
label: _this.getLabelTextForMatchingNode(value, document),
|
||||
insertText: _this.getInsertTextForMatchingNode(value, document, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet, documentation: ''
|
||||
});
|
||||
}
|
||||
if (value.type === 'boolean') {
|
||||
_this.addBooleanValueCompletion(!value.value, separatorAfter, collector);
|
||||
}
|
||||
};
|
||||
if (node.type === 'property') {
|
||||
if (offset > (node.colonOffset || 0)) {
|
||||
var valueNode = node.valueNode;
|
||||
if (valueNode && (offset > (valueNode.offset + valueNode.length) || valueNode.type === 'object' || valueNode.type === 'array')) {
|
||||
return;
|
||||
}
|
||||
// suggest values at the same key
|
||||
var parentKey_2 = node.keyNode.value;
|
||||
doc.visit(function (n) {
|
||||
if (n.type === 'property' && n.keyNode.value === parentKey_2 && n.valueNode) {
|
||||
collectSuggestionsForValues(n.valueNode);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (parentKey_2 === '$schema' && node.parent && !node.parent.parent) {
|
||||
this.addDollarSchemaCompletions(separatorAfter, collector);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.type === 'array') {
|
||||
if (node.parent && node.parent.type === 'property') {
|
||||
// suggest items of an array at the same key
|
||||
var parentKey_3 = node.parent.keyNode.value;
|
||||
doc.visit(function (n) {
|
||||
if (n.type === 'property' && n.keyNode.value === parentKey_3 && n.valueNode && n.valueNode.type === 'array') {
|
||||
n.valueNode.items.forEach(collectSuggestionsForValues);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
else {
|
||||
// suggest items in the same array
|
||||
node.items.forEach(collectSuggestionsForValues);
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getValueCompletions = function (schema, doc, node, offset, document, collector, types) {
|
||||
var offsetForSeparator = offset;
|
||||
var parentKey = undefined;
|
||||
var valueNode = undefined;
|
||||
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
|
||||
offsetForSeparator = node.offset + node.length;
|
||||
valueNode = node;
|
||||
node = node.parent;
|
||||
}
|
||||
if (!node) {
|
||||
this.addSchemaValueCompletions(schema.schema, '', collector, types);
|
||||
return;
|
||||
}
|
||||
if ((node.type === 'property') && offset > (node.colonOffset || 0)) {
|
||||
var valueNode_1 = node.valueNode;
|
||||
if (valueNode_1 && offset > (valueNode_1.offset + valueNode_1.length)) {
|
||||
return; // we are past the value node
|
||||
}
|
||||
parentKey = node.keyNode.value;
|
||||
node = node.parent;
|
||||
}
|
||||
if (node && (parentKey !== undefined || node.type === 'array')) {
|
||||
var separatorAfter = this.evaluateSeparatorAfter(document, offsetForSeparator);
|
||||
var matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset, valueNode);
|
||||
for (var _i = 0, matchingSchemas_1 = matchingSchemas; _i < matchingSchemas_1.length; _i++) {
|
||||
var s = matchingSchemas_1[_i];
|
||||
if (s.node === node && !s.inverted && s.schema) {
|
||||
if (node.type === 'array' && s.schema.items) {
|
||||
if (Array.isArray(s.schema.items)) {
|
||||
var index = this.findItemAtOffset(node, document, offset);
|
||||
if (index < s.schema.items.length) {
|
||||
this.addSchemaValueCompletions(s.schema.items[index], separatorAfter, collector, types);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.addSchemaValueCompletions(s.schema.items, separatorAfter, collector, types);
|
||||
}
|
||||
}
|
||||
if (parentKey !== undefined) {
|
||||
var propertyMatched = false;
|
||||
if (s.schema.properties) {
|
||||
var propertySchema = s.schema.properties[parentKey];
|
||||
if (propertySchema) {
|
||||
propertyMatched = true;
|
||||
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
|
||||
}
|
||||
}
|
||||
if (s.schema.patternProperties && !propertyMatched) {
|
||||
for (var _a = 0, _b = Object.keys(s.schema.patternProperties); _a < _b.length; _a++) {
|
||||
var pattern = _b[_a];
|
||||
var regex = extendedRegExp(pattern);
|
||||
if (regex.test(parentKey)) {
|
||||
propertyMatched = true;
|
||||
var propertySchema = s.schema.patternProperties[pattern];
|
||||
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (s.schema.additionalProperties && !propertyMatched) {
|
||||
var propertySchema = s.schema.additionalProperties;
|
||||
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parentKey === '$schema' && !node.parent) {
|
||||
this.addDollarSchemaCompletions(separatorAfter, collector);
|
||||
}
|
||||
if (types['boolean']) {
|
||||
this.addBooleanValueCompletion(true, separatorAfter, collector);
|
||||
this.addBooleanValueCompletion(false, separatorAfter, collector);
|
||||
}
|
||||
if (types['null']) {
|
||||
this.addNullValueCompletion(separatorAfter, collector);
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getContributedValueCompletions = function (doc, node, offset, document, collector, collectionPromises) {
|
||||
if (!node) {
|
||||
this.contributions.forEach(function (contribution) {
|
||||
var collectPromise = contribution.collectDefaultCompletions(document.uri, collector);
|
||||
if (collectPromise) {
|
||||
collectionPromises.push(collectPromise);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null') {
|
||||
node = node.parent;
|
||||
}
|
||||
if (node && (node.type === 'property') && offset > (node.colonOffset || 0)) {
|
||||
var parentKey_4 = node.keyNode.value;
|
||||
var valueNode = node.valueNode;
|
||||
if ((!valueNode || offset <= (valueNode.offset + valueNode.length)) && node.parent) {
|
||||
var location_2 = Parser.getNodePath(node.parent);
|
||||
this.contributions.forEach(function (contribution) {
|
||||
var collectPromise = contribution.collectValueCompletions(document.uri, location_2, parentKey_4, collector);
|
||||
if (collectPromise) {
|
||||
collectionPromises.push(collectPromise);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.addSchemaValueCompletions = function (schema, separatorAfter, collector, types) {
|
||||
var _this = this;
|
||||
if (typeof schema === 'object') {
|
||||
this.addEnumValueCompletions(schema, separatorAfter, collector);
|
||||
this.addDefaultValueCompletions(schema, separatorAfter, collector);
|
||||
this.collectTypes(schema, types);
|
||||
if (Array.isArray(schema.allOf)) {
|
||||
schema.allOf.forEach(function (s) { return _this.addSchemaValueCompletions(s, separatorAfter, collector, types); });
|
||||
}
|
||||
if (Array.isArray(schema.anyOf)) {
|
||||
schema.anyOf.forEach(function (s) { return _this.addSchemaValueCompletions(s, separatorAfter, collector, types); });
|
||||
}
|
||||
if (Array.isArray(schema.oneOf)) {
|
||||
schema.oneOf.forEach(function (s) { return _this.addSchemaValueCompletions(s, separatorAfter, collector, types); });
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.addDefaultValueCompletions = function (schema, separatorAfter, collector, arrayDepth) {
|
||||
var _this = this;
|
||||
if (arrayDepth === void 0) { arrayDepth = 0; }
|
||||
var hasProposals = false;
|
||||
if (isDefined(schema.default)) {
|
||||
var type = schema.type;
|
||||
var value = schema.default;
|
||||
for (var i = arrayDepth; i > 0; i--) {
|
||||
value = [value];
|
||||
type = 'array';
|
||||
}
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind(type),
|
||||
label: this.getLabelForValue(value),
|
||||
insertText: this.getInsertTextForValue(value, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
detail: localize('json.suggest.default', 'Default value')
|
||||
});
|
||||
hasProposals = true;
|
||||
}
|
||||
if (Array.isArray(schema.examples)) {
|
||||
schema.examples.forEach(function (example) {
|
||||
var type = schema.type;
|
||||
var value = example;
|
||||
for (var i = arrayDepth; i > 0; i--) {
|
||||
value = [value];
|
||||
type = 'array';
|
||||
}
|
||||
collector.add({
|
||||
kind: _this.getSuggestionKind(type),
|
||||
label: _this.getLabelForValue(value),
|
||||
insertText: _this.getInsertTextForValue(value, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet
|
||||
});
|
||||
hasProposals = true;
|
||||
});
|
||||
}
|
||||
if (Array.isArray(schema.defaultSnippets)) {
|
||||
schema.defaultSnippets.forEach(function (s) {
|
||||
var type = schema.type;
|
||||
var value = s.body;
|
||||
var label = s.label;
|
||||
var insertText;
|
||||
var filterText;
|
||||
if (isDefined(value)) {
|
||||
var type_1 = schema.type;
|
||||
for (var i = arrayDepth; i > 0; i--) {
|
||||
value = [value];
|
||||
type_1 = 'array';
|
||||
}
|
||||
insertText = _this.getInsertTextForSnippetValue(value, separatorAfter);
|
||||
filterText = _this.getFilterTextForSnippetValue(value);
|
||||
label = label || _this.getLabelForSnippetValue(value);
|
||||
}
|
||||
else if (typeof s.bodyText === 'string') {
|
||||
var prefix = '', suffix = '', indent = '';
|
||||
for (var i = arrayDepth; i > 0; i--) {
|
||||
prefix = prefix + indent + '[\n';
|
||||
suffix = suffix + '\n' + indent + ']';
|
||||
indent += '\t';
|
||||
type = 'array';
|
||||
}
|
||||
insertText = prefix + indent + s.bodyText.split('\n').join('\n' + indent) + suffix + separatorAfter;
|
||||
label = label || insertText,
|
||||
filterText = insertText.replace(/[\n]/g, ''); // remove new lines
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
collector.add({
|
||||
kind: _this.getSuggestionKind(type),
|
||||
label: label,
|
||||
documentation: _this.fromMarkup(s.markdownDescription) || s.description,
|
||||
insertText: insertText,
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
filterText: filterText
|
||||
});
|
||||
hasProposals = true;
|
||||
});
|
||||
}
|
||||
if (!hasProposals && typeof schema.items === 'object' && !Array.isArray(schema.items) && arrayDepth < 5 /* beware of recursion */) {
|
||||
this.addDefaultValueCompletions(schema.items, separatorAfter, collector, arrayDepth + 1);
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.addEnumValueCompletions = function (schema, separatorAfter, collector) {
|
||||
if (isDefined(schema.const)) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind(schema.type),
|
||||
label: this.getLabelForValue(schema.const),
|
||||
insertText: this.getInsertTextForValue(schema.const, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: this.fromMarkup(schema.markdownDescription) || schema.description
|
||||
});
|
||||
}
|
||||
if (Array.isArray(schema.enum)) {
|
||||
for (var i = 0, length = schema.enum.length; i < length; i++) {
|
||||
var enm = schema.enum[i];
|
||||
var documentation = this.fromMarkup(schema.markdownDescription) || schema.description;
|
||||
if (schema.markdownEnumDescriptions && i < schema.markdownEnumDescriptions.length && this.doesSupportMarkdown()) {
|
||||
documentation = this.fromMarkup(schema.markdownEnumDescriptions[i]);
|
||||
}
|
||||
else if (schema.enumDescriptions && i < schema.enumDescriptions.length) {
|
||||
documentation = schema.enumDescriptions[i];
|
||||
}
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind(schema.type),
|
||||
label: this.getLabelForValue(enm),
|
||||
insertText: this.getInsertTextForValue(enm, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: documentation
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.collectTypes = function (schema, types) {
|
||||
if (Array.isArray(schema.enum) || isDefined(schema.const)) {
|
||||
return;
|
||||
}
|
||||
var type = schema.type;
|
||||
if (Array.isArray(type)) {
|
||||
type.forEach(function (t) { return types[t] = true; });
|
||||
}
|
||||
else if (type) {
|
||||
types[type] = true;
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.addFillerValueCompletions = function (types, separatorAfter, collector) {
|
||||
if (types['object']) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('object'),
|
||||
label: '{}',
|
||||
insertText: this.getInsertTextForGuessedValue({}, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
detail: localize('defaults.object', 'New object'),
|
||||
documentation: ''
|
||||
});
|
||||
}
|
||||
if (types['array']) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('array'),
|
||||
label: '[]',
|
||||
insertText: this.getInsertTextForGuessedValue([], separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
detail: localize('defaults.array', 'New array'),
|
||||
documentation: ''
|
||||
});
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.addBooleanValueCompletion = function (value, separatorAfter, collector) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('boolean'),
|
||||
label: value ? 'true' : 'false',
|
||||
insertText: this.getInsertTextForValue(value, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: ''
|
||||
});
|
||||
};
|
||||
JSONCompletion.prototype.addNullValueCompletion = function (separatorAfter, collector) {
|
||||
collector.add({
|
||||
kind: this.getSuggestionKind('null'),
|
||||
label: 'null',
|
||||
insertText: 'null' + separatorAfter,
|
||||
insertTextFormat: InsertTextFormat.Snippet,
|
||||
documentation: ''
|
||||
});
|
||||
};
|
||||
JSONCompletion.prototype.addDollarSchemaCompletions = function (separatorAfter, collector) {
|
||||
var _this = this;
|
||||
var schemaIds = this.schemaService.getRegisteredSchemaIds(function (schema) { return schema === 'http' || schema === 'https'; });
|
||||
schemaIds.forEach(function (schemaId) { return collector.add({
|
||||
kind: CompletionItemKind.Module,
|
||||
label: _this.getLabelForValue(schemaId),
|
||||
filterText: _this.getFilterTextForValue(schemaId),
|
||||
insertText: _this.getInsertTextForValue(schemaId, separatorAfter),
|
||||
insertTextFormat: InsertTextFormat.Snippet, documentation: ''
|
||||
}); });
|
||||
};
|
||||
JSONCompletion.prototype.getLabelForValue = function (value) {
|
||||
return JSON.stringify(value);
|
||||
};
|
||||
JSONCompletion.prototype.getFilterTextForValue = function (value) {
|
||||
return JSON.stringify(value);
|
||||
};
|
||||
JSONCompletion.prototype.getFilterTextForSnippetValue = function (value) {
|
||||
return JSON.stringify(value).replace(/\$\{\d+:([^}]+)\}|\$\d+/g, '$1');
|
||||
};
|
||||
JSONCompletion.prototype.getLabelForSnippetValue = function (value) {
|
||||
var label = JSON.stringify(value);
|
||||
return label.replace(/\$\{\d+:([^}]+)\}|\$\d+/g, '$1');
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForPlainText = function (text) {
|
||||
return text.replace(/[\\\$\}]/g, '\\$&'); // escape $, \ and }
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForValue = function (value, separatorAfter) {
|
||||
var text = JSON.stringify(value, null, '\t');
|
||||
if (text === '{}') {
|
||||
return '{$1}' + separatorAfter;
|
||||
}
|
||||
else if (text === '[]') {
|
||||
return '[$1]' + separatorAfter;
|
||||
}
|
||||
return this.getInsertTextForPlainText(text + separatorAfter);
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForSnippetValue = function (value, separatorAfter) {
|
||||
var replacer = function (value) {
|
||||
if (typeof value === 'string') {
|
||||
if (value[0] === '^') {
|
||||
return value.substr(1);
|
||||
}
|
||||
}
|
||||
return JSON.stringify(value);
|
||||
};
|
||||
return stringifyObject(value, '', replacer) + separatorAfter;
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForGuessedValue = function (value, separatorAfter) {
|
||||
switch (typeof value) {
|
||||
case 'object':
|
||||
if (value === null) {
|
||||
return '${1:null}' + separatorAfter;
|
||||
}
|
||||
return this.getInsertTextForValue(value, separatorAfter);
|
||||
case 'string':
|
||||
var snippetValue = JSON.stringify(value);
|
||||
snippetValue = snippetValue.substr(1, snippetValue.length - 2); // remove quotes
|
||||
snippetValue = this.getInsertTextForPlainText(snippetValue); // escape \ and }
|
||||
return '"${1:' + snippetValue + '}"' + separatorAfter;
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
return '${1:' + JSON.stringify(value) + '}' + separatorAfter;
|
||||
}
|
||||
return this.getInsertTextForValue(value, separatorAfter);
|
||||
};
|
||||
JSONCompletion.prototype.getSuggestionKind = function (type) {
|
||||
if (Array.isArray(type)) {
|
||||
var array = type;
|
||||
type = array.length > 0 ? array[0] : undefined;
|
||||
}
|
||||
if (!type) {
|
||||
return CompletionItemKind.Value;
|
||||
}
|
||||
switch (type) {
|
||||
case 'string': return CompletionItemKind.Value;
|
||||
case 'object': return CompletionItemKind.Module;
|
||||
case 'property': return CompletionItemKind.Property;
|
||||
default: return CompletionItemKind.Value;
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getLabelTextForMatchingNode = function (node, document) {
|
||||
switch (node.type) {
|
||||
case 'array':
|
||||
return '[]';
|
||||
case 'object':
|
||||
return '{}';
|
||||
default:
|
||||
var content = document.getText().substr(node.offset, node.length);
|
||||
return content;
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForMatchingNode = function (node, document, separatorAfter) {
|
||||
switch (node.type) {
|
||||
case 'array':
|
||||
return this.getInsertTextForValue([], separatorAfter);
|
||||
case 'object':
|
||||
return this.getInsertTextForValue({}, separatorAfter);
|
||||
default:
|
||||
var content = document.getText().substr(node.offset, node.length) + separatorAfter;
|
||||
return this.getInsertTextForPlainText(content);
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.getInsertTextForProperty = function (key, propertySchema, addValue, separatorAfter) {
|
||||
var propertyText = this.getInsertTextForValue(key, '');
|
||||
if (!addValue) {
|
||||
return propertyText;
|
||||
}
|
||||
var resultText = propertyText + ': ';
|
||||
var value;
|
||||
var nValueProposals = 0;
|
||||
if (propertySchema) {
|
||||
if (Array.isArray(propertySchema.defaultSnippets)) {
|
||||
if (propertySchema.defaultSnippets.length === 1) {
|
||||
var body = propertySchema.defaultSnippets[0].body;
|
||||
if (isDefined(body)) {
|
||||
value = this.getInsertTextForSnippetValue(body, '');
|
||||
}
|
||||
}
|
||||
nValueProposals += propertySchema.defaultSnippets.length;
|
||||
}
|
||||
if (propertySchema.enum) {
|
||||
if (!value && propertySchema.enum.length === 1) {
|
||||
value = this.getInsertTextForGuessedValue(propertySchema.enum[0], '');
|
||||
}
|
||||
nValueProposals += propertySchema.enum.length;
|
||||
}
|
||||
if (isDefined(propertySchema.default)) {
|
||||
if (!value) {
|
||||
value = this.getInsertTextForGuessedValue(propertySchema.default, '');
|
||||
}
|
||||
nValueProposals++;
|
||||
}
|
||||
if (Array.isArray(propertySchema.examples) && propertySchema.examples.length) {
|
||||
if (!value) {
|
||||
value = this.getInsertTextForGuessedValue(propertySchema.examples[0], '');
|
||||
}
|
||||
nValueProposals += propertySchema.examples.length;
|
||||
}
|
||||
if (nValueProposals === 0) {
|
||||
var type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type;
|
||||
if (!type) {
|
||||
if (propertySchema.properties) {
|
||||
type = 'object';
|
||||
}
|
||||
else if (propertySchema.items) {
|
||||
type = 'array';
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case 'boolean':
|
||||
value = '$1';
|
||||
break;
|
||||
case 'string':
|
||||
value = '"$1"';
|
||||
break;
|
||||
case 'object':
|
||||
value = '{$1}';
|
||||
break;
|
||||
case 'array':
|
||||
value = '[$1]';
|
||||
break;
|
||||
case 'number':
|
||||
case 'integer':
|
||||
value = '${1:0}';
|
||||
break;
|
||||
case 'null':
|
||||
value = '${1:null}';
|
||||
break;
|
||||
default:
|
||||
return propertyText;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!value || nValueProposals > 1) {
|
||||
value = '$1';
|
||||
}
|
||||
return resultText + value + separatorAfter;
|
||||
};
|
||||
JSONCompletion.prototype.getCurrentWord = function (document, offset) {
|
||||
var i = offset - 1;
|
||||
var text = document.getText();
|
||||
while (i >= 0 && ' \t\n\r\v":{[,]}'.indexOf(text.charAt(i)) === -1) {
|
||||
i--;
|
||||
}
|
||||
return text.substring(i + 1, offset);
|
||||
};
|
||||
JSONCompletion.prototype.evaluateSeparatorAfter = function (document, offset) {
|
||||
var scanner = Json.createScanner(document.getText(), true);
|
||||
scanner.setPosition(offset);
|
||||
var token = scanner.scan();
|
||||
switch (token) {
|
||||
case 5 /* CommaToken */:
|
||||
case 2 /* CloseBraceToken */:
|
||||
case 4 /* CloseBracketToken */:
|
||||
case 17 /* EOF */:
|
||||
return '';
|
||||
default:
|
||||
return ',';
|
||||
}
|
||||
};
|
||||
JSONCompletion.prototype.findItemAtOffset = function (node, document, offset) {
|
||||
var scanner = Json.createScanner(document.getText(), true);
|
||||
var children = node.items;
|
||||
for (var i = children.length - 1; i >= 0; i--) {
|
||||
var child = children[i];
|
||||
if (offset > child.offset + child.length) {
|
||||
scanner.setPosition(child.offset + child.length);
|
||||
var token = scanner.scan();
|
||||
if (token === 5 /* CommaToken */ && offset >= scanner.getTokenOffset() + scanner.getTokenLength()) {
|
||||
return i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
else if (offset >= child.offset) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
JSONCompletion.prototype.isInComment = function (document, start, offset) {
|
||||
var scanner = Json.createScanner(document.getText(), false);
|
||||
scanner.setPosition(start);
|
||||
var token = scanner.scan();
|
||||
while (token !== 17 /* EOF */ && (scanner.getTokenOffset() + scanner.getTokenLength() < offset)) {
|
||||
token = scanner.scan();
|
||||
}
|
||||
return (token === 12 /* LineCommentTrivia */ || token === 13 /* BlockCommentTrivia */) && scanner.getTokenOffset() <= offset;
|
||||
};
|
||||
JSONCompletion.prototype.fromMarkup = function (markupString) {
|
||||
if (markupString && this.doesSupportMarkdown()) {
|
||||
return {
|
||||
kind: MarkupKind.Markdown,
|
||||
value: markupString
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
JSONCompletion.prototype.doesSupportMarkdown = function () {
|
||||
if (!isDefined(this.supportsMarkdown)) {
|
||||
var completion = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.completion;
|
||||
this.supportsMarkdown = completion && completion.completionItem && Array.isArray(completion.completionItem.documentationFormat) && completion.completionItem.documentationFormat.indexOf(MarkupKind.Markdown) !== -1;
|
||||
}
|
||||
return this.supportsMarkdown;
|
||||
};
|
||||
JSONCompletion.prototype.doesSupportsCommitCharacters = function () {
|
||||
if (!isDefined(this.supportsCommitCharacters)) {
|
||||
var completion = this.clientCapabilities.textDocument && this.clientCapabilities.textDocument.completion;
|
||||
this.supportsCommitCharacters = completion && completion.completionItem && !!completion.completionItem.commitCharactersSupport;
|
||||
}
|
||||
return this.supportsCommitCharacters;
|
||||
};
|
||||
return JSONCompletion;
|
||||
}());
|
||||
export { JSONCompletion };
|
||||
278
node_modules/vscode-json-languageservice/lib/esm/services/jsonDocumentSymbols.js
generated
vendored
Normal file
278
node_modules/vscode-json-languageservice/lib/esm/services/jsonDocumentSymbols.js
generated
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as Parser from '../parser/jsonParser';
|
||||
import * as Strings from '../utils/strings';
|
||||
import { colorFromHex } from '../utils/colors';
|
||||
import { Range, TextEdit, SymbolKind, Location } from "../jsonLanguageTypes";
|
||||
var JSONDocumentSymbols = /** @class */ (function () {
|
||||
function JSONDocumentSymbols(schemaService) {
|
||||
this.schemaService = schemaService;
|
||||
}
|
||||
JSONDocumentSymbols.prototype.findDocumentSymbols = function (document, doc, context) {
|
||||
var _this = this;
|
||||
if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
|
||||
var root = doc.root;
|
||||
if (!root) {
|
||||
return [];
|
||||
}
|
||||
var limit = context.resultLimit || Number.MAX_VALUE;
|
||||
// special handling for key bindings
|
||||
var resourceString = document.uri;
|
||||
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
||||
if (root.type === 'array') {
|
||||
var result_1 = [];
|
||||
for (var _i = 0, _a = root.items; _i < _a.length; _i++) {
|
||||
var item = _a[_i];
|
||||
if (item.type === 'object') {
|
||||
for (var _b = 0, _c = item.properties; _b < _c.length; _b++) {
|
||||
var property = _c[_b];
|
||||
if (property.keyNode.value === 'key' && property.valueNode) {
|
||||
var location = Location.create(document.uri, getRange(document, item));
|
||||
result_1.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, location: location });
|
||||
limit--;
|
||||
if (limit <= 0) {
|
||||
if (context && context.onResultLimitExceeded) {
|
||||
context.onResultLimitExceeded(resourceString);
|
||||
}
|
||||
return result_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result_1;
|
||||
}
|
||||
}
|
||||
var toVisit = [
|
||||
{ node: root, containerName: '' }
|
||||
];
|
||||
var nextToVisit = 0;
|
||||
var limitExceeded = false;
|
||||
var result = [];
|
||||
var collectOutlineEntries = function (node, containerName) {
|
||||
if (node.type === 'array') {
|
||||
node.items.forEach(function (node) {
|
||||
if (node) {
|
||||
toVisit.push({ node: node, containerName: containerName });
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (node.type === 'object') {
|
||||
node.properties.forEach(function (property) {
|
||||
var valueNode = property.valueNode;
|
||||
if (valueNode) {
|
||||
if (limit > 0) {
|
||||
limit--;
|
||||
var location = Location.create(document.uri, getRange(document, property));
|
||||
var childContainerName = containerName ? containerName + '.' + property.keyNode.value : property.keyNode.value;
|
||||
result.push({ name: _this.getKeyLabel(property), kind: _this.getSymbolKind(valueNode.type), location: location, containerName: containerName });
|
||||
toVisit.push({ node: valueNode, containerName: childContainerName });
|
||||
}
|
||||
else {
|
||||
limitExceeded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
// breath first traversal
|
||||
while (nextToVisit < toVisit.length) {
|
||||
var next = toVisit[nextToVisit++];
|
||||
collectOutlineEntries(next.node, next.containerName);
|
||||
}
|
||||
if (limitExceeded && context && context.onResultLimitExceeded) {
|
||||
context.onResultLimitExceeded(resourceString);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
JSONDocumentSymbols.prototype.findDocumentSymbols2 = function (document, doc, context) {
|
||||
var _this = this;
|
||||
if (context === void 0) { context = { resultLimit: Number.MAX_VALUE }; }
|
||||
var root = doc.root;
|
||||
if (!root) {
|
||||
return [];
|
||||
}
|
||||
var limit = context.resultLimit || Number.MAX_VALUE;
|
||||
// special handling for key bindings
|
||||
var resourceString = document.uri;
|
||||
if ((resourceString === 'vscode://defaultsettings/keybindings.json') || Strings.endsWith(resourceString.toLowerCase(), '/user/keybindings.json')) {
|
||||
if (root.type === 'array') {
|
||||
var result_2 = [];
|
||||
for (var _i = 0, _a = root.items; _i < _a.length; _i++) {
|
||||
var item = _a[_i];
|
||||
if (item.type === 'object') {
|
||||
for (var _b = 0, _c = item.properties; _b < _c.length; _b++) {
|
||||
var property = _c[_b];
|
||||
if (property.keyNode.value === 'key' && property.valueNode) {
|
||||
var range = getRange(document, item);
|
||||
var selectionRange = getRange(document, property.keyNode);
|
||||
result_2.push({ name: Parser.getNodeValue(property.valueNode), kind: SymbolKind.Function, range: range, selectionRange: selectionRange });
|
||||
limit--;
|
||||
if (limit <= 0) {
|
||||
if (context && context.onResultLimitExceeded) {
|
||||
context.onResultLimitExceeded(resourceString);
|
||||
}
|
||||
return result_2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result_2;
|
||||
}
|
||||
}
|
||||
var result = [];
|
||||
var toVisit = [
|
||||
{ node: root, result: result }
|
||||
];
|
||||
var nextToVisit = 0;
|
||||
var limitExceeded = false;
|
||||
var collectOutlineEntries = function (node, result) {
|
||||
if (node.type === 'array') {
|
||||
node.items.forEach(function (node, index) {
|
||||
if (node) {
|
||||
if (limit > 0) {
|
||||
limit--;
|
||||
var range = getRange(document, node);
|
||||
var selectionRange = range;
|
||||
var name = String(index);
|
||||
var symbol = { name: name, kind: _this.getSymbolKind(node.type), range: range, selectionRange: selectionRange, children: [] };
|
||||
result.push(symbol);
|
||||
toVisit.push({ result: symbol.children, node: node });
|
||||
}
|
||||
else {
|
||||
limitExceeded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (node.type === 'object') {
|
||||
node.properties.forEach(function (property) {
|
||||
var valueNode = property.valueNode;
|
||||
if (valueNode) {
|
||||
if (limit > 0) {
|
||||
limit--;
|
||||
var range = getRange(document, property);
|
||||
var selectionRange = getRange(document, property.keyNode);
|
||||
var children = [];
|
||||
var symbol = { name: _this.getKeyLabel(property), kind: _this.getSymbolKind(valueNode.type), range: range, selectionRange: selectionRange, children: children, detail: _this.getDetail(valueNode) };
|
||||
result.push(symbol);
|
||||
toVisit.push({ result: children, node: valueNode });
|
||||
}
|
||||
else {
|
||||
limitExceeded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
// breath first traversal
|
||||
while (nextToVisit < toVisit.length) {
|
||||
var next = toVisit[nextToVisit++];
|
||||
collectOutlineEntries(next.node, next.result);
|
||||
}
|
||||
if (limitExceeded && context && context.onResultLimitExceeded) {
|
||||
context.onResultLimitExceeded(resourceString);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
JSONDocumentSymbols.prototype.getSymbolKind = function (nodeType) {
|
||||
switch (nodeType) {
|
||||
case 'object':
|
||||
return SymbolKind.Module;
|
||||
case 'string':
|
||||
return SymbolKind.String;
|
||||
case 'number':
|
||||
return SymbolKind.Number;
|
||||
case 'array':
|
||||
return SymbolKind.Array;
|
||||
case 'boolean':
|
||||
return SymbolKind.Boolean;
|
||||
default: // 'null'
|
||||
return SymbolKind.Variable;
|
||||
}
|
||||
};
|
||||
JSONDocumentSymbols.prototype.getKeyLabel = function (property) {
|
||||
var name = property.keyNode.value;
|
||||
if (name) {
|
||||
name = name.replace(/[\n]/g, '↵');
|
||||
}
|
||||
if (name && name.trim()) {
|
||||
return name;
|
||||
}
|
||||
return "\"" + name + "\"";
|
||||
};
|
||||
JSONDocumentSymbols.prototype.getDetail = function (node) {
|
||||
if (!node) {
|
||||
return undefined;
|
||||
}
|
||||
if (node.type === 'boolean' || node.type === 'number' || node.type === 'null' || node.type === 'string') {
|
||||
return String(node.value);
|
||||
}
|
||||
else {
|
||||
if (node.type === 'array') {
|
||||
return node.children.length ? undefined : '[]';
|
||||
}
|
||||
else if (node.type === 'object') {
|
||||
return node.children.length ? undefined : '{}';
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
JSONDocumentSymbols.prototype.findDocumentColors = function (document, doc, context) {
|
||||
return this.schemaService.getSchemaForResource(document.uri, doc).then(function (schema) {
|
||||
var result = [];
|
||||
if (schema) {
|
||||
var limit = context && typeof context.resultLimit === 'number' ? context.resultLimit : Number.MAX_VALUE;
|
||||
var matchingSchemas = doc.getMatchingSchemas(schema.schema);
|
||||
var visitedNode = {};
|
||||
for (var _i = 0, matchingSchemas_1 = matchingSchemas; _i < matchingSchemas_1.length; _i++) {
|
||||
var s = matchingSchemas_1[_i];
|
||||
if (!s.inverted && s.schema && (s.schema.format === 'color' || s.schema.format === 'color-hex') && s.node && s.node.type === 'string') {
|
||||
var nodeId = String(s.node.offset);
|
||||
if (!visitedNode[nodeId]) {
|
||||
var color = colorFromHex(Parser.getNodeValue(s.node));
|
||||
if (color) {
|
||||
var range = getRange(document, s.node);
|
||||
result.push({ color: color, range: range });
|
||||
}
|
||||
visitedNode[nodeId] = true;
|
||||
limit--;
|
||||
if (limit <= 0) {
|
||||
if (context && context.onResultLimitExceeded) {
|
||||
context.onResultLimitExceeded(document.uri);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
};
|
||||
JSONDocumentSymbols.prototype.getColorPresentations = function (document, doc, color, range) {
|
||||
var result = [];
|
||||
var red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
|
||||
function toTwoDigitHex(n) {
|
||||
var r = n.toString(16);
|
||||
return r.length !== 2 ? '0' + r : r;
|
||||
}
|
||||
var label;
|
||||
if (color.alpha === 1) {
|
||||
label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256);
|
||||
}
|
||||
else {
|
||||
label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256) + toTwoDigitHex(Math.round(color.alpha * 255));
|
||||
}
|
||||
result.push({ label: label, textEdit: TextEdit.replace(range, JSON.stringify(label)) });
|
||||
return result;
|
||||
};
|
||||
return JSONDocumentSymbols;
|
||||
}());
|
||||
export { JSONDocumentSymbols };
|
||||
function getRange(document, node) {
|
||||
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
||||
}
|
||||
121
node_modules/vscode-json-languageservice/lib/esm/services/jsonFolding.js
generated
vendored
Normal file
121
node_modules/vscode-json-languageservice/lib/esm/services/jsonFolding.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { createScanner } from 'jsonc-parser';
|
||||
import { FoldingRangeKind, Position } from '../jsonLanguageTypes';
|
||||
export function getFoldingRanges(document, context) {
|
||||
var ranges = [];
|
||||
var nestingLevels = [];
|
||||
var stack = [];
|
||||
var prevStart = -1;
|
||||
var scanner = createScanner(document.getText(), false);
|
||||
var token = scanner.scan();
|
||||
function addRange(range) {
|
||||
ranges.push(range);
|
||||
nestingLevels.push(stack.length);
|
||||
}
|
||||
while (token !== 17 /* EOF */) {
|
||||
switch (token) {
|
||||
case 1 /* OpenBraceToken */:
|
||||
case 3 /* OpenBracketToken */: {
|
||||
var startLine = document.positionAt(scanner.getTokenOffset()).line;
|
||||
var range = { startLine: startLine, endLine: startLine, kind: token === 1 /* OpenBraceToken */ ? 'object' : 'array' };
|
||||
stack.push(range);
|
||||
break;
|
||||
}
|
||||
case 2 /* CloseBraceToken */:
|
||||
case 4 /* CloseBracketToken */: {
|
||||
var kind = token === 2 /* CloseBraceToken */ ? 'object' : 'array';
|
||||
if (stack.length > 0 && stack[stack.length - 1].kind === kind) {
|
||||
var range = stack.pop();
|
||||
var line = document.positionAt(scanner.getTokenOffset()).line;
|
||||
if (range && line > range.startLine + 1 && prevStart !== range.startLine) {
|
||||
range.endLine = line - 1;
|
||||
addRange(range);
|
||||
prevStart = range.startLine;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 13 /* BlockCommentTrivia */: {
|
||||
var startLine = document.positionAt(scanner.getTokenOffset()).line;
|
||||
var endLine = document.positionAt(scanner.getTokenOffset() + scanner.getTokenLength()).line;
|
||||
if (scanner.getTokenError() === 1 /* UnexpectedEndOfComment */ && startLine + 1 < document.lineCount) {
|
||||
scanner.setPosition(document.offsetAt(Position.create(startLine + 1, 0)));
|
||||
}
|
||||
else {
|
||||
if (startLine < endLine) {
|
||||
addRange({ startLine: startLine, endLine: endLine, kind: FoldingRangeKind.Comment });
|
||||
prevStart = startLine;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 12 /* LineCommentTrivia */: {
|
||||
var text = document.getText().substr(scanner.getTokenOffset(), scanner.getTokenLength());
|
||||
var m = text.match(/^\/\/\s*#(region\b)|(endregion\b)/);
|
||||
if (m) {
|
||||
var line = document.positionAt(scanner.getTokenOffset()).line;
|
||||
if (m[1]) { // start pattern match
|
||||
var range = { startLine: line, endLine: line, kind: FoldingRangeKind.Region };
|
||||
stack.push(range);
|
||||
}
|
||||
else {
|
||||
var i = stack.length - 1;
|
||||
while (i >= 0 && stack[i].kind !== FoldingRangeKind.Region) {
|
||||
i--;
|
||||
}
|
||||
if (i >= 0) {
|
||||
var range = stack[i];
|
||||
stack.length = i;
|
||||
if (line > range.startLine && prevStart !== range.startLine) {
|
||||
range.endLine = line;
|
||||
addRange(range);
|
||||
prevStart = range.startLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
token = scanner.scan();
|
||||
}
|
||||
var rangeLimit = context && context.rangeLimit;
|
||||
if (typeof rangeLimit !== 'number' || ranges.length <= rangeLimit) {
|
||||
return ranges;
|
||||
}
|
||||
if (context && context.onRangeLimitExceeded) {
|
||||
context.onRangeLimitExceeded(document.uri);
|
||||
}
|
||||
var counts = [];
|
||||
for (var _i = 0, nestingLevels_1 = nestingLevels; _i < nestingLevels_1.length; _i++) {
|
||||
var level = nestingLevels_1[_i];
|
||||
if (level < 30) {
|
||||
counts[level] = (counts[level] || 0) + 1;
|
||||
}
|
||||
}
|
||||
var entries = 0;
|
||||
var maxLevel = 0;
|
||||
for (var i = 0; i < counts.length; i++) {
|
||||
var n = counts[i];
|
||||
if (n) {
|
||||
if (n + entries > rangeLimit) {
|
||||
maxLevel = i;
|
||||
break;
|
||||
}
|
||||
entries += n;
|
||||
}
|
||||
}
|
||||
var result = [];
|
||||
for (var i = 0; i < ranges.length; i++) {
|
||||
var level = nestingLevels[i];
|
||||
if (typeof level === 'number') {
|
||||
if (level < maxLevel || (level === maxLevel && entries++ < rangeLimit)) {
|
||||
result.push(ranges[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
112
node_modules/vscode-json-languageservice/lib/esm/services/jsonHover.js
generated
vendored
Normal file
112
node_modules/vscode-json-languageservice/lib/esm/services/jsonHover.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as Parser from '../parser/jsonParser';
|
||||
import { Range } from '../jsonLanguageTypes';
|
||||
var JSONHover = /** @class */ (function () {
|
||||
function JSONHover(schemaService, contributions, promiseConstructor) {
|
||||
if (contributions === void 0) { contributions = []; }
|
||||
this.schemaService = schemaService;
|
||||
this.contributions = contributions;
|
||||
this.promise = promiseConstructor || Promise;
|
||||
}
|
||||
JSONHover.prototype.doHover = function (document, position, doc) {
|
||||
var offset = document.offsetAt(position);
|
||||
var node = doc.getNodeFromOffset(offset);
|
||||
if (!node || (node.type === 'object' || node.type === 'array') && offset > node.offset + 1 && offset < node.offset + node.length - 1) {
|
||||
return this.promise.resolve(null);
|
||||
}
|
||||
var hoverRangeNode = node;
|
||||
// use the property description when hovering over an object key
|
||||
if (node.type === 'string') {
|
||||
var parent = node.parent;
|
||||
if (parent && parent.type === 'property' && parent.keyNode === node) {
|
||||
node = parent.valueNode;
|
||||
if (!node) {
|
||||
return this.promise.resolve(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
var hoverRange = Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length));
|
||||
var createHover = function (contents) {
|
||||
var result = {
|
||||
contents: contents,
|
||||
range: hoverRange
|
||||
};
|
||||
return result;
|
||||
};
|
||||
var location = Parser.getNodePath(node);
|
||||
for (var i = this.contributions.length - 1; i >= 0; i--) {
|
||||
var contribution = this.contributions[i];
|
||||
var promise = contribution.getInfoContribution(document.uri, location);
|
||||
if (promise) {
|
||||
return promise.then(function (htmlContent) { return createHover(htmlContent); });
|
||||
}
|
||||
}
|
||||
return this.schemaService.getSchemaForResource(document.uri, doc).then(function (schema) {
|
||||
if (schema && node) {
|
||||
var matchingSchemas = doc.getMatchingSchemas(schema.schema, node.offset);
|
||||
var title_1 = undefined;
|
||||
var markdownDescription_1 = undefined;
|
||||
var markdownEnumValueDescription_1 = undefined, enumValue_1 = undefined;
|
||||
matchingSchemas.every(function (s) {
|
||||
if (s.node === node && !s.inverted && s.schema) {
|
||||
title_1 = title_1 || s.schema.title;
|
||||
markdownDescription_1 = markdownDescription_1 || s.schema.markdownDescription || toMarkdown(s.schema.description);
|
||||
if (s.schema.enum) {
|
||||
var idx = s.schema.enum.indexOf(Parser.getNodeValue(node));
|
||||
if (s.schema.markdownEnumDescriptions) {
|
||||
markdownEnumValueDescription_1 = s.schema.markdownEnumDescriptions[idx];
|
||||
}
|
||||
else if (s.schema.enumDescriptions) {
|
||||
markdownEnumValueDescription_1 = toMarkdown(s.schema.enumDescriptions[idx]);
|
||||
}
|
||||
if (markdownEnumValueDescription_1) {
|
||||
enumValue_1 = s.schema.enum[idx];
|
||||
if (typeof enumValue_1 !== 'string') {
|
||||
enumValue_1 = JSON.stringify(enumValue_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
var result = '';
|
||||
if (title_1) {
|
||||
result = toMarkdown(title_1);
|
||||
}
|
||||
if (markdownDescription_1) {
|
||||
if (result.length > 0) {
|
||||
result += "\n\n";
|
||||
}
|
||||
result += markdownDescription_1;
|
||||
}
|
||||
if (markdownEnumValueDescription_1) {
|
||||
if (result.length > 0) {
|
||||
result += "\n\n";
|
||||
}
|
||||
result += "`" + toMarkdownCodeBlock(enumValue_1) + "`: " + markdownEnumValueDescription_1;
|
||||
}
|
||||
return createHover([result]);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
};
|
||||
return JSONHover;
|
||||
}());
|
||||
export { JSONHover };
|
||||
function toMarkdown(plain) {
|
||||
if (plain) {
|
||||
var res = plain.replace(/([^\n\r])(\r?\n)([^\n\r])/gm, '$1\n\n$3'); // single new lines to \n\n (Markdown paragraph)
|
||||
return res.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&"); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function toMarkdownCodeBlock(content) {
|
||||
// see https://daringfireball.net/projects/markdown/syntax#precode
|
||||
if (content.indexOf('`') !== -1) {
|
||||
return '`` ' + content + ' ``';
|
||||
}
|
||||
return content;
|
||||
}
|
||||
73
node_modules/vscode-json-languageservice/lib/esm/services/jsonLinks.js
generated
vendored
Normal file
73
node_modules/vscode-json-languageservice/lib/esm/services/jsonLinks.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Range } from '../jsonLanguageTypes';
|
||||
export function findLinks(document, doc) {
|
||||
var links = [];
|
||||
doc.visit(function (node) {
|
||||
var _a;
|
||||
if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
|
||||
var path = node.valueNode.value;
|
||||
var targetNode = findTargetNode(doc, path);
|
||||
if (targetNode) {
|
||||
var targetPos = document.positionAt(targetNode.offset);
|
||||
links.push({
|
||||
target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
|
||||
range: createRange(document, node.valueNode)
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return Promise.resolve(links);
|
||||
}
|
||||
function createRange(document, node) {
|
||||
return Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
|
||||
}
|
||||
function findTargetNode(doc, path) {
|
||||
var tokens = parseJSONPointer(path);
|
||||
if (!tokens) {
|
||||
return null;
|
||||
}
|
||||
return findNode(tokens, doc.root);
|
||||
}
|
||||
function findNode(pointer, node) {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
if (pointer.length === 0) {
|
||||
return node;
|
||||
}
|
||||
var token = pointer.shift();
|
||||
if (node && node.type === 'object') {
|
||||
var propertyNode = node.properties.find(function (propertyNode) { return propertyNode.keyNode.value === token; });
|
||||
if (!propertyNode) {
|
||||
return null;
|
||||
}
|
||||
return findNode(pointer, propertyNode.valueNode);
|
||||
}
|
||||
else if (node && node.type === 'array') {
|
||||
if (token.match(/^(0|[1-9][0-9]*)$/)) {
|
||||
var index = Number.parseInt(token);
|
||||
var arrayItem = node.items[index];
|
||||
if (!arrayItem) {
|
||||
return null;
|
||||
}
|
||||
return findNode(pointer, arrayItem);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function parseJSONPointer(path) {
|
||||
if (path === "#") {
|
||||
return [];
|
||||
}
|
||||
if (path[0] !== '#' || path[1] !== '/') {
|
||||
return null;
|
||||
}
|
||||
return path.substring(2).split(/\//).map(unescape);
|
||||
}
|
||||
function unescape(str) {
|
||||
return str.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
}
|
||||
535
node_modules/vscode-json-languageservice/lib/esm/services/jsonSchemaService.js
generated
vendored
Normal file
535
node_modules/vscode-json-languageservice/lib/esm/services/jsonSchemaService.js
generated
vendored
Normal file
@@ -0,0 +1,535 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as Json from 'jsonc-parser';
|
||||
import { URI } from 'vscode-uri';
|
||||
import * as Strings from '../utils/strings';
|
||||
import * as Parser from '../parser/jsonParser';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { createRegex } from '../utils/glob';
|
||||
var localize = nls.loadMessageBundle();
|
||||
var BANG = '!';
|
||||
var PATH_SEP = '/';
|
||||
var FilePatternAssociation = /** @class */ (function () {
|
||||
function FilePatternAssociation(pattern, uris) {
|
||||
this.globWrappers = [];
|
||||
try {
|
||||
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
|
||||
var patternString = pattern_1[_i];
|
||||
var include = patternString[0] !== BANG;
|
||||
if (!include) {
|
||||
patternString = patternString.substring(1);
|
||||
}
|
||||
if (patternString.length > 0) {
|
||||
if (patternString[0] === PATH_SEP) {
|
||||
patternString = patternString.substring(1);
|
||||
}
|
||||
this.globWrappers.push({
|
||||
regexp: createRegex('**/' + patternString, { extended: true, globstar: true }),
|
||||
include: include,
|
||||
});
|
||||
}
|
||||
}
|
||||
;
|
||||
this.uris = uris;
|
||||
}
|
||||
catch (e) {
|
||||
this.globWrappers.length = 0;
|
||||
this.uris = [];
|
||||
}
|
||||
}
|
||||
FilePatternAssociation.prototype.matchesPattern = function (fileName) {
|
||||
var match = false;
|
||||
for (var _i = 0, _a = this.globWrappers; _i < _a.length; _i++) {
|
||||
var _b = _a[_i], regexp = _b.regexp, include = _b.include;
|
||||
if (regexp.test(fileName)) {
|
||||
match = include;
|
||||
}
|
||||
}
|
||||
return match;
|
||||
};
|
||||
FilePatternAssociation.prototype.getURIs = function () {
|
||||
return this.uris;
|
||||
};
|
||||
return FilePatternAssociation;
|
||||
}());
|
||||
var SchemaHandle = /** @class */ (function () {
|
||||
function SchemaHandle(service, url, unresolvedSchemaContent) {
|
||||
this.service = service;
|
||||
this.url = url;
|
||||
this.dependencies = {};
|
||||
if (unresolvedSchemaContent) {
|
||||
this.unresolvedSchema = this.service.promise.resolve(new UnresolvedSchema(unresolvedSchemaContent));
|
||||
}
|
||||
}
|
||||
SchemaHandle.prototype.getUnresolvedSchema = function () {
|
||||
if (!this.unresolvedSchema) {
|
||||
this.unresolvedSchema = this.service.loadSchema(this.url);
|
||||
}
|
||||
return this.unresolvedSchema;
|
||||
};
|
||||
SchemaHandle.prototype.getResolvedSchema = function () {
|
||||
var _this = this;
|
||||
if (!this.resolvedSchema) {
|
||||
this.resolvedSchema = this.getUnresolvedSchema().then(function (unresolved) {
|
||||
return _this.service.resolveSchemaContent(unresolved, _this.url, _this.dependencies);
|
||||
});
|
||||
}
|
||||
return this.resolvedSchema;
|
||||
};
|
||||
SchemaHandle.prototype.clearSchema = function () {
|
||||
this.resolvedSchema = undefined;
|
||||
this.unresolvedSchema = undefined;
|
||||
this.dependencies = {};
|
||||
};
|
||||
return SchemaHandle;
|
||||
}());
|
||||
var UnresolvedSchema = /** @class */ (function () {
|
||||
function UnresolvedSchema(schema, errors) {
|
||||
if (errors === void 0) { errors = []; }
|
||||
this.schema = schema;
|
||||
this.errors = errors;
|
||||
}
|
||||
return UnresolvedSchema;
|
||||
}());
|
||||
export { UnresolvedSchema };
|
||||
var ResolvedSchema = /** @class */ (function () {
|
||||
function ResolvedSchema(schema, errors) {
|
||||
if (errors === void 0) { errors = []; }
|
||||
this.schema = schema;
|
||||
this.errors = errors;
|
||||
}
|
||||
ResolvedSchema.prototype.getSection = function (path) {
|
||||
var schemaRef = this.getSectionRecursive(path, this.schema);
|
||||
if (schemaRef) {
|
||||
return Parser.asSchema(schemaRef);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
ResolvedSchema.prototype.getSectionRecursive = function (path, schema) {
|
||||
if (!schema || typeof schema === 'boolean' || path.length === 0) {
|
||||
return schema;
|
||||
}
|
||||
var next = path.shift();
|
||||
if (schema.properties && typeof schema.properties[next]) {
|
||||
return this.getSectionRecursive(path, schema.properties[next]);
|
||||
}
|
||||
else if (schema.patternProperties) {
|
||||
for (var _i = 0, _a = Object.keys(schema.patternProperties); _i < _a.length; _i++) {
|
||||
var pattern = _a[_i];
|
||||
var regex = Strings.extendedRegExp(pattern);
|
||||
if (regex.test(next)) {
|
||||
return this.getSectionRecursive(path, schema.patternProperties[pattern]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof schema.additionalProperties === 'object') {
|
||||
return this.getSectionRecursive(path, schema.additionalProperties);
|
||||
}
|
||||
else if (next.match('[0-9]+')) {
|
||||
if (Array.isArray(schema.items)) {
|
||||
var index = parseInt(next, 10);
|
||||
if (!isNaN(index) && schema.items[index]) {
|
||||
return this.getSectionRecursive(path, schema.items[index]);
|
||||
}
|
||||
}
|
||||
else if (schema.items) {
|
||||
return this.getSectionRecursive(path, schema.items);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
return ResolvedSchema;
|
||||
}());
|
||||
export { ResolvedSchema };
|
||||
var JSONSchemaService = /** @class */ (function () {
|
||||
function JSONSchemaService(requestService, contextService, promiseConstructor) {
|
||||
this.contextService = contextService;
|
||||
this.requestService = requestService;
|
||||
this.promiseConstructor = promiseConstructor || Promise;
|
||||
this.callOnDispose = [];
|
||||
this.contributionSchemas = {};
|
||||
this.contributionAssociations = [];
|
||||
this.schemasById = {};
|
||||
this.filePatternAssociations = [];
|
||||
this.registeredSchemasIds = {};
|
||||
}
|
||||
JSONSchemaService.prototype.getRegisteredSchemaIds = function (filter) {
|
||||
return Object.keys(this.registeredSchemasIds).filter(function (id) {
|
||||
var scheme = URI.parse(id).scheme;
|
||||
return scheme !== 'schemaservice' && (!filter || filter(scheme));
|
||||
});
|
||||
};
|
||||
Object.defineProperty(JSONSchemaService.prototype, "promise", {
|
||||
get: function () {
|
||||
return this.promiseConstructor;
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
JSONSchemaService.prototype.dispose = function () {
|
||||
while (this.callOnDispose.length > 0) {
|
||||
this.callOnDispose.pop()();
|
||||
}
|
||||
};
|
||||
JSONSchemaService.prototype.onResourceChange = function (uri) {
|
||||
var _this = this;
|
||||
// always clear this local cache when a resource changes
|
||||
this.cachedSchemaForResource = undefined;
|
||||
var hasChanges = false;
|
||||
uri = normalizeId(uri);
|
||||
var toWalk = [uri];
|
||||
var all = Object.keys(this.schemasById).map(function (key) { return _this.schemasById[key]; });
|
||||
while (toWalk.length) {
|
||||
var curr = toWalk.pop();
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
var handle = all[i];
|
||||
if (handle && (handle.url === curr || handle.dependencies[curr])) {
|
||||
if (handle.url !== curr) {
|
||||
toWalk.push(handle.url);
|
||||
}
|
||||
handle.clearSchema();
|
||||
all[i] = undefined;
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasChanges;
|
||||
};
|
||||
JSONSchemaService.prototype.setSchemaContributions = function (schemaContributions) {
|
||||
if (schemaContributions.schemas) {
|
||||
var schemas = schemaContributions.schemas;
|
||||
for (var id in schemas) {
|
||||
var normalizedId = normalizeId(id);
|
||||
this.contributionSchemas[normalizedId] = this.addSchemaHandle(normalizedId, schemas[id]);
|
||||
}
|
||||
}
|
||||
if (Array.isArray(schemaContributions.schemaAssociations)) {
|
||||
var schemaAssociations = schemaContributions.schemaAssociations;
|
||||
for (var _i = 0, schemaAssociations_1 = schemaAssociations; _i < schemaAssociations_1.length; _i++) {
|
||||
var schemaAssociation = schemaAssociations_1[_i];
|
||||
var uris = schemaAssociation.uris.map(normalizeId);
|
||||
var association = this.addFilePatternAssociation(schemaAssociation.pattern, uris);
|
||||
this.contributionAssociations.push(association);
|
||||
}
|
||||
}
|
||||
};
|
||||
JSONSchemaService.prototype.addSchemaHandle = function (id, unresolvedSchemaContent) {
|
||||
var schemaHandle = new SchemaHandle(this, id, unresolvedSchemaContent);
|
||||
this.schemasById[id] = schemaHandle;
|
||||
return schemaHandle;
|
||||
};
|
||||
JSONSchemaService.prototype.getOrAddSchemaHandle = function (id, unresolvedSchemaContent) {
|
||||
return this.schemasById[id] || this.addSchemaHandle(id, unresolvedSchemaContent);
|
||||
};
|
||||
JSONSchemaService.prototype.addFilePatternAssociation = function (pattern, uris) {
|
||||
var fpa = new FilePatternAssociation(pattern, uris);
|
||||
this.filePatternAssociations.push(fpa);
|
||||
return fpa;
|
||||
};
|
||||
JSONSchemaService.prototype.registerExternalSchema = function (uri, filePatterns, unresolvedSchemaContent) {
|
||||
var id = normalizeId(uri);
|
||||
this.registeredSchemasIds[id] = true;
|
||||
this.cachedSchemaForResource = undefined;
|
||||
if (filePatterns) {
|
||||
this.addFilePatternAssociation(filePatterns, [uri]);
|
||||
}
|
||||
return unresolvedSchemaContent ? this.addSchemaHandle(id, unresolvedSchemaContent) : this.getOrAddSchemaHandle(id);
|
||||
};
|
||||
JSONSchemaService.prototype.clearExternalSchemas = function () {
|
||||
this.schemasById = {};
|
||||
this.filePatternAssociations = [];
|
||||
this.registeredSchemasIds = {};
|
||||
this.cachedSchemaForResource = undefined;
|
||||
for (var id in this.contributionSchemas) {
|
||||
this.schemasById[id] = this.contributionSchemas[id];
|
||||
this.registeredSchemasIds[id] = true;
|
||||
}
|
||||
for (var _i = 0, _a = this.contributionAssociations; _i < _a.length; _i++) {
|
||||
var contributionAssociation = _a[_i];
|
||||
this.filePatternAssociations.push(contributionAssociation);
|
||||
}
|
||||
};
|
||||
JSONSchemaService.prototype.getResolvedSchema = function (schemaId) {
|
||||
var id = normalizeId(schemaId);
|
||||
var schemaHandle = this.schemasById[id];
|
||||
if (schemaHandle) {
|
||||
return schemaHandle.getResolvedSchema();
|
||||
}
|
||||
return this.promise.resolve(undefined);
|
||||
};
|
||||
JSONSchemaService.prototype.loadSchema = function (url) {
|
||||
if (!this.requestService) {
|
||||
var errorMessage = localize('json.schema.norequestservice', 'Unable to load schema from \'{0}\'. No schema request service available', toDisplayString(url));
|
||||
return this.promise.resolve(new UnresolvedSchema({}, [errorMessage]));
|
||||
}
|
||||
return this.requestService(url).then(function (content) {
|
||||
if (!content) {
|
||||
var errorMessage = localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': No content.', toDisplayString(url));
|
||||
return new UnresolvedSchema({}, [errorMessage]);
|
||||
}
|
||||
var schemaContent = {};
|
||||
var jsonErrors = [];
|
||||
schemaContent = Json.parse(content, jsonErrors);
|
||||
var errors = jsonErrors.length ? [localize('json.schema.invalidFormat', 'Unable to parse content from \'{0}\': Parse error at offset {1}.', toDisplayString(url), jsonErrors[0].offset)] : [];
|
||||
return new UnresolvedSchema(schemaContent, errors);
|
||||
}, function (error) {
|
||||
var errorMessage = error.toString();
|
||||
var errorSplit = error.toString().split('Error: ');
|
||||
if (errorSplit.length > 1) {
|
||||
// more concise error message, URL and context are attached by caller anyways
|
||||
errorMessage = errorSplit[1];
|
||||
}
|
||||
if (Strings.endsWith(errorMessage, '.')) {
|
||||
errorMessage = errorMessage.substr(0, errorMessage.length - 1);
|
||||
}
|
||||
return new UnresolvedSchema({}, [localize('json.schema.nocontent', 'Unable to load schema from \'{0}\': {1}.', toDisplayString(url), errorMessage)]);
|
||||
});
|
||||
};
|
||||
JSONSchemaService.prototype.resolveSchemaContent = function (schemaToResolve, schemaURL, dependencies) {
|
||||
var _this = this;
|
||||
var resolveErrors = schemaToResolve.errors.slice(0);
|
||||
var schema = schemaToResolve.schema;
|
||||
if (schema.$schema) {
|
||||
var id = normalizeId(schema.$schema);
|
||||
if (id === 'http://json-schema.org/draft-03/schema') {
|
||||
return this.promise.resolve(new ResolvedSchema({}, [localize('json.schema.draft03.notsupported', "Draft-03 schemas are not supported.")]));
|
||||
}
|
||||
else if (id === 'https://json-schema.org/draft/2019-09/schema') {
|
||||
resolveErrors.push(localize('json.schema.draft201909.notsupported', "Draft 2019-09 schemas are not yet fully supported."));
|
||||
}
|
||||
}
|
||||
var contextService = this.contextService;
|
||||
var findSection = function (schema, path) {
|
||||
if (!path) {
|
||||
return schema;
|
||||
}
|
||||
var current = schema;
|
||||
if (path[0] === '/') {
|
||||
path = path.substr(1);
|
||||
}
|
||||
path.split('/').some(function (part) {
|
||||
part = part.replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
current = current[part];
|
||||
return !current;
|
||||
});
|
||||
return current;
|
||||
};
|
||||
var merge = function (target, sourceRoot, sourceURI, refSegment) {
|
||||
var path = refSegment ? decodeURIComponent(refSegment) : undefined;
|
||||
var section = findSection(sourceRoot, path);
|
||||
if (section) {
|
||||
for (var key in section) {
|
||||
if (section.hasOwnProperty(key) && !target.hasOwnProperty(key)) {
|
||||
target[key] = section[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
resolveErrors.push(localize('json.schema.invalidref', '$ref \'{0}\' in \'{1}\' can not be resolved.', path, sourceURI));
|
||||
}
|
||||
};
|
||||
var resolveExternalLink = function (node, uri, refSegment, parentSchemaURL, parentSchemaDependencies) {
|
||||
if (contextService && !/^[A-Za-z][A-Za-z0-9+\-.+]*:\/\/.*/.test(uri)) {
|
||||
uri = contextService.resolveRelativePath(uri, parentSchemaURL);
|
||||
}
|
||||
uri = normalizeId(uri);
|
||||
var referencedHandle = _this.getOrAddSchemaHandle(uri);
|
||||
return referencedHandle.getUnresolvedSchema().then(function (unresolvedSchema) {
|
||||
parentSchemaDependencies[uri] = true;
|
||||
if (unresolvedSchema.errors.length) {
|
||||
var loc = refSegment ? uri + '#' + refSegment : uri;
|
||||
resolveErrors.push(localize('json.schema.problemloadingref', 'Problems loading reference \'{0}\': {1}', loc, unresolvedSchema.errors[0]));
|
||||
}
|
||||
merge(node, unresolvedSchema.schema, uri, refSegment);
|
||||
return resolveRefs(node, unresolvedSchema.schema, uri, referencedHandle.dependencies);
|
||||
});
|
||||
};
|
||||
var resolveRefs = function (node, parentSchema, parentSchemaURL, parentSchemaDependencies) {
|
||||
if (!node || typeof node !== 'object') {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
var toWalk = [node];
|
||||
var seen = [];
|
||||
var openPromises = [];
|
||||
var collectEntries = function () {
|
||||
var entries = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
entries[_i] = arguments[_i];
|
||||
}
|
||||
for (var _a = 0, entries_1 = entries; _a < entries_1.length; _a++) {
|
||||
var entry = entries_1[_a];
|
||||
if (typeof entry === 'object') {
|
||||
toWalk.push(entry);
|
||||
}
|
||||
}
|
||||
};
|
||||
var collectMapEntries = function () {
|
||||
var maps = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
maps[_i] = arguments[_i];
|
||||
}
|
||||
for (var _a = 0, maps_1 = maps; _a < maps_1.length; _a++) {
|
||||
var map = maps_1[_a];
|
||||
if (typeof map === 'object') {
|
||||
for (var k in map) {
|
||||
var key = k;
|
||||
var entry = map[key];
|
||||
if (typeof entry === 'object') {
|
||||
toWalk.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var collectArrayEntries = function () {
|
||||
var arrays = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
arrays[_i] = arguments[_i];
|
||||
}
|
||||
for (var _a = 0, arrays_1 = arrays; _a < arrays_1.length; _a++) {
|
||||
var array = arrays_1[_a];
|
||||
if (Array.isArray(array)) {
|
||||
for (var _b = 0, array_1 = array; _b < array_1.length; _b++) {
|
||||
var entry = array_1[_b];
|
||||
if (typeof entry === 'object') {
|
||||
toWalk.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var handleRef = function (next) {
|
||||
var seenRefs = [];
|
||||
while (next.$ref) {
|
||||
var ref = next.$ref;
|
||||
var segments = ref.split('#', 2);
|
||||
delete next.$ref;
|
||||
if (segments[0].length > 0) {
|
||||
openPromises.push(resolveExternalLink(next, segments[0], segments[1], parentSchemaURL, parentSchemaDependencies));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (seenRefs.indexOf(ref) === -1) {
|
||||
merge(next, parentSchema, parentSchemaURL, segments[1]); // can set next.$ref again, use seenRefs to avoid circle
|
||||
seenRefs.push(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
collectEntries(next.items, next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else);
|
||||
collectMapEntries(next.definitions, next.properties, next.patternProperties, next.dependencies);
|
||||
collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.items);
|
||||
};
|
||||
while (toWalk.length) {
|
||||
var next = toWalk.pop();
|
||||
if (seen.indexOf(next) >= 0) {
|
||||
continue;
|
||||
}
|
||||
seen.push(next);
|
||||
handleRef(next);
|
||||
}
|
||||
return _this.promise.all(openPromises);
|
||||
};
|
||||
return resolveRefs(schema, schema, schemaURL, dependencies).then(function (_) { return new ResolvedSchema(schema, resolveErrors); });
|
||||
};
|
||||
JSONSchemaService.prototype.getSchemaForResource = function (resource, document) {
|
||||
// first use $schema if present
|
||||
if (document && document.root && document.root.type === 'object') {
|
||||
var schemaProperties = document.root.properties.filter(function (p) { return (p.keyNode.value === '$schema') && p.valueNode && p.valueNode.type === 'string'; });
|
||||
if (schemaProperties.length > 0) {
|
||||
var valueNode = schemaProperties[0].valueNode;
|
||||
if (valueNode && valueNode.type === 'string') {
|
||||
var schemeId = Parser.getNodeValue(valueNode);
|
||||
if (schemeId && Strings.startsWith(schemeId, '.') && this.contextService) {
|
||||
schemeId = this.contextService.resolveRelativePath(schemeId, resource);
|
||||
}
|
||||
if (schemeId) {
|
||||
var id = normalizeId(schemeId);
|
||||
return this.getOrAddSchemaHandle(id).getResolvedSchema();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.cachedSchemaForResource && this.cachedSchemaForResource.resource === resource) {
|
||||
return this.cachedSchemaForResource.resolvedSchema;
|
||||
}
|
||||
var seen = Object.create(null);
|
||||
var schemas = [];
|
||||
var normalizedResource = normalizeResourceForMatching(resource);
|
||||
for (var _i = 0, _a = this.filePatternAssociations; _i < _a.length; _i++) {
|
||||
var entry = _a[_i];
|
||||
if (entry.matchesPattern(normalizedResource)) {
|
||||
for (var _b = 0, _c = entry.getURIs(); _b < _c.length; _b++) {
|
||||
var schemaId = _c[_b];
|
||||
if (!seen[schemaId]) {
|
||||
schemas.push(schemaId);
|
||||
seen[schemaId] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var resolvedSchema = schemas.length > 0 ? this.createCombinedSchema(resource, schemas).getResolvedSchema() : this.promise.resolve(undefined);
|
||||
this.cachedSchemaForResource = { resource: resource, resolvedSchema: resolvedSchema };
|
||||
return resolvedSchema;
|
||||
};
|
||||
JSONSchemaService.prototype.createCombinedSchema = function (resource, schemaIds) {
|
||||
if (schemaIds.length === 1) {
|
||||
return this.getOrAddSchemaHandle(schemaIds[0]);
|
||||
}
|
||||
else {
|
||||
var combinedSchemaId = 'schemaservice://combinedSchema/' + encodeURIComponent(resource);
|
||||
var combinedSchema = {
|
||||
allOf: schemaIds.map(function (schemaId) { return ({ $ref: schemaId }); })
|
||||
};
|
||||
return this.addSchemaHandle(combinedSchemaId, combinedSchema);
|
||||
}
|
||||
};
|
||||
JSONSchemaService.prototype.getMatchingSchemas = function (document, jsonDocument, schema) {
|
||||
if (schema) {
|
||||
var id = schema.id || ('schemaservice://untitled/matchingSchemas/' + idCounter++);
|
||||
return this.resolveSchemaContent(new UnresolvedSchema(schema), id, {}).then(function (resolvedSchema) {
|
||||
return jsonDocument.getMatchingSchemas(resolvedSchema.schema).filter(function (s) { return !s.inverted; });
|
||||
});
|
||||
}
|
||||
return this.getSchemaForResource(document.uri, jsonDocument).then(function (schema) {
|
||||
if (schema) {
|
||||
return jsonDocument.getMatchingSchemas(schema.schema).filter(function (s) { return !s.inverted; });
|
||||
}
|
||||
return [];
|
||||
});
|
||||
};
|
||||
return JSONSchemaService;
|
||||
}());
|
||||
export { JSONSchemaService };
|
||||
var idCounter = 0;
|
||||
function normalizeId(id) {
|
||||
// remove trailing '#', normalize drive capitalization
|
||||
try {
|
||||
return URI.parse(id).toString();
|
||||
}
|
||||
catch (e) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
function normalizeResourceForMatching(resource) {
|
||||
// remove queries and fragments, normalize drive capitalization
|
||||
try {
|
||||
return URI.parse(resource).with({ fragment: null, query: null }).toString();
|
||||
}
|
||||
catch (e) {
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
function toDisplayString(url) {
|
||||
try {
|
||||
var uri = URI.parse(url);
|
||||
if (uri.scheme === 'file') {
|
||||
return uri.fsPath;
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// ignore
|
||||
}
|
||||
return url;
|
||||
}
|
||||
61
node_modules/vscode-json-languageservice/lib/esm/services/jsonSelectionRanges.js
generated
vendored
Normal file
61
node_modules/vscode-json-languageservice/lib/esm/services/jsonSelectionRanges.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Range, SelectionRange } from '../jsonLanguageTypes';
|
||||
import { createScanner } from 'jsonc-parser';
|
||||
export function getSelectionRanges(document, positions, doc) {
|
||||
function getSelectionRange(position) {
|
||||
var offset = document.offsetAt(position);
|
||||
var node = doc.getNodeFromOffset(offset, true);
|
||||
var result = [];
|
||||
while (node) {
|
||||
switch (node.type) {
|
||||
case 'string':
|
||||
case 'object':
|
||||
case 'array':
|
||||
// range without ", [ or {
|
||||
var cStart = node.offset + 1, cEnd = node.offset + node.length - 1;
|
||||
if (cStart < cEnd && offset >= cStart && offset <= cEnd) {
|
||||
result.push(newRange(cStart, cEnd));
|
||||
}
|
||||
result.push(newRange(node.offset, node.offset + node.length));
|
||||
break;
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
case 'property':
|
||||
result.push(newRange(node.offset, node.offset + node.length));
|
||||
break;
|
||||
}
|
||||
if (node.type === 'property' || node.parent && node.parent.type === 'array') {
|
||||
var afterCommaOffset = getOffsetAfterNextToken(node.offset + node.length, 5 /* CommaToken */);
|
||||
if (afterCommaOffset !== -1) {
|
||||
result.push(newRange(node.offset, afterCommaOffset));
|
||||
}
|
||||
}
|
||||
node = node.parent;
|
||||
}
|
||||
var current = undefined;
|
||||
for (var index = result.length - 1; index >= 0; index--) {
|
||||
current = SelectionRange.create(result[index], current);
|
||||
}
|
||||
if (!current) {
|
||||
current = SelectionRange.create(Range.create(position, position));
|
||||
}
|
||||
return current;
|
||||
}
|
||||
function newRange(start, end) {
|
||||
return Range.create(document.positionAt(start), document.positionAt(end));
|
||||
}
|
||||
var scanner = createScanner(document.getText(), true);
|
||||
function getOffsetAfterNextToken(offset, expectedToken) {
|
||||
scanner.setPosition(offset);
|
||||
var token = scanner.scan();
|
||||
if (token === expectedToken) {
|
||||
return scanner.getTokenOffset() + scanner.getTokenLength();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return positions.map(getSelectionRange);
|
||||
}
|
||||
146
node_modules/vscode-json-languageservice/lib/esm/services/jsonValidation.js
generated
vendored
Normal file
146
node_modules/vscode-json-languageservice/lib/esm/services/jsonValidation.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { UnresolvedSchema } from './jsonSchemaService';
|
||||
import { ErrorCode, Diagnostic, DiagnosticSeverity, Range } from '../jsonLanguageTypes';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { isBoolean } from '../utils/objects';
|
||||
var localize = nls.loadMessageBundle();
|
||||
var JSONValidation = /** @class */ (function () {
|
||||
function JSONValidation(jsonSchemaService, promiseConstructor) {
|
||||
this.jsonSchemaService = jsonSchemaService;
|
||||
this.promise = promiseConstructor;
|
||||
this.validationEnabled = true;
|
||||
}
|
||||
JSONValidation.prototype.configure = function (raw) {
|
||||
if (raw) {
|
||||
this.validationEnabled = raw.validate !== false;
|
||||
this.commentSeverity = raw.allowComments ? undefined : DiagnosticSeverity.Error;
|
||||
}
|
||||
};
|
||||
JSONValidation.prototype.doValidation = function (textDocument, jsonDocument, documentSettings, schema) {
|
||||
var _this = this;
|
||||
if (!this.validationEnabled) {
|
||||
return this.promise.resolve([]);
|
||||
}
|
||||
var diagnostics = [];
|
||||
var added = {};
|
||||
var addProblem = function (problem) {
|
||||
// remove duplicated messages
|
||||
var signature = problem.range.start.line + ' ' + problem.range.start.character + ' ' + problem.message;
|
||||
if (!added[signature]) {
|
||||
added[signature] = true;
|
||||
diagnostics.push(problem);
|
||||
}
|
||||
};
|
||||
var getDiagnostics = function (schema) {
|
||||
var trailingCommaSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.trailingCommas) ? toDiagnosticSeverity(documentSettings.trailingCommas) : DiagnosticSeverity.Error;
|
||||
var commentSeverity = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.comments) ? toDiagnosticSeverity(documentSettings.comments) : _this.commentSeverity;
|
||||
var schemaValidation = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaValidation) ? toDiagnosticSeverity(documentSettings.schemaValidation) : DiagnosticSeverity.Warning;
|
||||
var schemaRequest = (documentSettings === null || documentSettings === void 0 ? void 0 : documentSettings.schemaRequest) ? toDiagnosticSeverity(documentSettings.schemaRequest) : DiagnosticSeverity.Warning;
|
||||
if (schema) {
|
||||
if (schema.errors.length && jsonDocument.root && schemaRequest) {
|
||||
var astRoot = jsonDocument.root;
|
||||
var property = astRoot.type === 'object' ? astRoot.properties[0] : undefined;
|
||||
if (property && property.keyNode.value === '$schema') {
|
||||
var node = property.valueNode || property;
|
||||
var range = Range.create(textDocument.positionAt(node.offset), textDocument.positionAt(node.offset + node.length));
|
||||
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
||||
}
|
||||
else {
|
||||
var range = Range.create(textDocument.positionAt(astRoot.offset), textDocument.positionAt(astRoot.offset + 1));
|
||||
addProblem(Diagnostic.create(range, schema.errors[0], schemaRequest, ErrorCode.SchemaResolveError));
|
||||
}
|
||||
}
|
||||
else if (schemaValidation) {
|
||||
var semanticErrors = jsonDocument.validate(textDocument, schema.schema, schemaValidation);
|
||||
if (semanticErrors) {
|
||||
semanticErrors.forEach(addProblem);
|
||||
}
|
||||
}
|
||||
if (schemaAllowsComments(schema.schema)) {
|
||||
commentSeverity = undefined;
|
||||
}
|
||||
if (schemaAllowsTrailingCommas(schema.schema)) {
|
||||
trailingCommaSeverity = undefined;
|
||||
}
|
||||
}
|
||||
for (var _i = 0, _a = jsonDocument.syntaxErrors; _i < _a.length; _i++) {
|
||||
var p = _a[_i];
|
||||
if (p.code === ErrorCode.TrailingComma) {
|
||||
if (typeof trailingCommaSeverity !== 'number') {
|
||||
continue;
|
||||
}
|
||||
p.severity = trailingCommaSeverity;
|
||||
}
|
||||
addProblem(p);
|
||||
}
|
||||
if (typeof commentSeverity === 'number') {
|
||||
var message_1 = localize('InvalidCommentToken', 'Comments are not permitted in JSON.');
|
||||
jsonDocument.comments.forEach(function (c) {
|
||||
addProblem(Diagnostic.create(c, message_1, commentSeverity, ErrorCode.CommentNotPermitted));
|
||||
});
|
||||
}
|
||||
return diagnostics;
|
||||
};
|
||||
if (schema) {
|
||||
var id = schema.id || ('schemaservice://untitled/' + idCounter++);
|
||||
return this.jsonSchemaService.resolveSchemaContent(new UnresolvedSchema(schema), id, {}).then(function (resolvedSchema) {
|
||||
return getDiagnostics(resolvedSchema);
|
||||
});
|
||||
}
|
||||
return this.jsonSchemaService.getSchemaForResource(textDocument.uri, jsonDocument).then(function (schema) {
|
||||
return getDiagnostics(schema);
|
||||
});
|
||||
};
|
||||
return JSONValidation;
|
||||
}());
|
||||
export { JSONValidation };
|
||||
var idCounter = 0;
|
||||
function schemaAllowsComments(schemaRef) {
|
||||
if (schemaRef && typeof schemaRef === 'object') {
|
||||
if (isBoolean(schemaRef.allowComments)) {
|
||||
return schemaRef.allowComments;
|
||||
}
|
||||
if (schemaRef.allOf) {
|
||||
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
||||
var schema = _a[_i];
|
||||
var allow = schemaAllowsComments(schema);
|
||||
if (isBoolean(allow)) {
|
||||
return allow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function schemaAllowsTrailingCommas(schemaRef) {
|
||||
if (schemaRef && typeof schemaRef === 'object') {
|
||||
if (isBoolean(schemaRef.allowTrailingCommas)) {
|
||||
return schemaRef.allowTrailingCommas;
|
||||
}
|
||||
var deprSchemaRef = schemaRef;
|
||||
if (isBoolean(deprSchemaRef['allowsTrailingCommas'])) { // deprecated
|
||||
return deprSchemaRef['allowsTrailingCommas'];
|
||||
}
|
||||
if (schemaRef.allOf) {
|
||||
for (var _i = 0, _a = schemaRef.allOf; _i < _a.length; _i++) {
|
||||
var schema = _a[_i];
|
||||
var allow = schemaAllowsTrailingCommas(schema);
|
||||
if (isBoolean(allow)) {
|
||||
return allow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
function toDiagnosticSeverity(severityLevel) {
|
||||
switch (severityLevel) {
|
||||
case 'error': return DiagnosticSeverity.Error;
|
||||
case 'warning': return DiagnosticSeverity.Warning;
|
||||
case 'ignore': return undefined;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user