[json] Allow "json.validate.enable": false in settings / disable JSON validation or error checking. Fixes #114775

This commit is contained in:
Martin Aeschlimann 2022-04-12 15:33:14 +02:00
parent 4f4bf42424
commit 8f5b743a0b
No known key found for this signature in database
GPG Key ID: 2609A01E695523E3
9 changed files with 55 additions and 34 deletions

View File

@ -67,7 +67,7 @@ namespace SemanticTokenLegendRequest {
export interface RuntimeEnvironment {
fileFs?: FileSystemProvider;
configureHttpRequests?(proxy: string, strictSSL: boolean): void;
configureHttpRequests?(proxy: string | undefined, strictSSL: boolean): void;
readonly timer: {
setImmediate(callback: (...args: any[]) => void, ...args: any[]): Disposable;
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable;

View File

@ -59,7 +59,8 @@ namespace ResultLimitReachedNotification {
interface Settings {
json?: {
schemas?: JSONSchemaSettings[];
format?: { enable: boolean };
format?: { enable?: boolean };
validate?: { enable?: boolean };
resultLimit?: number;
};
http?: {
@ -76,6 +77,7 @@ export interface JSONSchemaSettings {
namespace SettingIds {
export const enableFormatter = 'json.format.enable';
export const enableValidation = 'json.validate.enable';
export const enableSchemaDownload = 'json.schemaDownload.enable';
export const maxItemsComputed = 'json.maxItemsComputed';
}
@ -425,6 +427,7 @@ function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[]
}
function getSettings(): Settings {
const configuration = workspace.getConfiguration();
const httpSettings = workspace.getConfiguration('http');
const resultLimit: number = Math.trunc(Math.max(0, Number(workspace.getConfiguration().get(SettingIds.maxItemsComputed)))) || 5000;
@ -435,6 +438,8 @@ function getSettings(): Settings {
proxyStrictSSL: httpSettings.get('proxyStrictSSL')
},
json: {
validate: { enable: configuration.get(SettingIds.enableValidation) },
format: { enable: configuration.get(SettingIds.enableFormatter) },
schemas: [],
resultLimit
}

View File

@ -73,6 +73,12 @@
}
}
},
"json.validate.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.validate.enable.desc%"
},
"json.format.enable": {
"type": "boolean",
"scope": "window",
@ -141,8 +147,8 @@
]
},
"dependencies": {
"request-light": "^0.5.7",
"@vscode/extension-telemetry": "0.4.10",
"@vscode/extension-telemetry": "0.5.0",
"request-light": "^0.5.8",
"vscode-languageclient": "^7.0.0",
"vscode-nls": "^5.0.0"
},

View File

@ -7,6 +7,7 @@
"json.schemas.fileMatch.item.desc": "A file pattern that can contain '*' to match against when resolving JSON files to schemas.",
"json.schemas.schema.desc": "The schema definition for the given URL. The schema only needs to be provided to avoid accesses to the schema URL.",
"json.format.enable.desc": "Enable/disable default JSON formatter",
"json.validate.enable.desc": "Enable/disable JSON validation.",
"json.tracing.desc": "Traces the communication between VS Code and the JSON language server.",
"json.colorDecorators.enable.desc": "Enables or disables color decorators",
"json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`.",

View File

@ -62,6 +62,8 @@ The server supports the following settings:
- json
- `format`
- `enable`: Whether the server should register the formatting support. This option is only applicable if the client supports *dynamicRegistration* for *rangeFormatting* and `initializationOptions.provideFormatter` is not defined.
- `validate`
- `enable`: Whether the server should validate. Defaults to `true` if not set.
- `schemas`: Configures association of file names to schema URL or schemas and/or associations of schema URL to schema content.
- `fileMatch`: an array of file names or paths (separated by `/`). `*` can be used as a wildcard. Exclusion patterns can also be defined and start with '!'. A file matches when there is at least one matching pattern and the last matching pattern is not an exclusion pattern.
- `url`: The URL of the schema, optional when also a schema is provided.

View File

@ -13,7 +13,7 @@
"main": "./out/node/jsonServerMain",
"dependencies": {
"jsonc-parser": "^3.0.0",
"request-light": "^0.5.7",
"request-light": "^0.5.8",
"vscode-json-languageservice": "^4.2.1",
"vscode-languageserver": "^7.0.0",
"vscode-uri": "^3.0.3"

View File

@ -57,7 +57,7 @@ export interface RequestService {
export interface RuntimeEnvironment {
file?: RequestService;
http?: RequestService;
configureHttpRequests?(proxy: string, strictSSL: boolean): void;
configureHttpRequests?(proxy: string | undefined, strictSSL: boolean): void;
readonly timer: {
setImmediate(callback: (...args: any[]) => void, ...args: any[]): Disposable;
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): Disposable;
@ -166,14 +166,15 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
// The settings interface describes the server relevant settings part
interface Settings {
json: {
schemas: JSONSchemaSettings[];
format: { enable: boolean };
json?: {
schemas?: JSONSchemaSettings[];
format?: { enable?: boolean };
validate?: { enable?: boolean };
resultLimit?: number;
};
http: {
proxy: string;
proxyStrictSSL: boolean;
http?: {
proxy?: string;
proxyStrictSSL?: boolean;
};
}
@ -226,22 +227,24 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
let schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined;
let formatterRegistrations: Thenable<Disposable>[] | null = null;
let validateEnabled = true;
// The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration((change) => {
let settings = <Settings>change.settings;
if (runtime.configureHttpRequests) {
runtime.configureHttpRequests(settings.http && settings.http.proxy, settings.http && settings.http.proxyStrictSSL);
runtime.configureHttpRequests(settings?.http?.proxy, !!settings.http?.proxyStrictSSL);
}
jsonConfigurationSettings = settings.json && settings.json.schemas;
jsonConfigurationSettings = settings.json?.schemas;
validateEnabled = !!settings.json?.validate?.enable;
updateConfiguration();
foldingRangeLimit = Math.trunc(Math.max(settings.json && settings.json.resultLimit || foldingRangeLimitDefault, 0));
resultLimit = Math.trunc(Math.max(settings.json && settings.json.resultLimit || Number.MAX_VALUE, 0));
foldingRangeLimit = Math.trunc(Math.max(settings.json?.resultLimit || foldingRangeLimitDefault, 0));
resultLimit = Math.trunc(Math.max(settings.json?.resultLimit || Number.MAX_VALUE, 0));
// dynamically enable & disable the formatter
if (dynamicFormatterRegistration) {
const enableFormatter = settings && settings.json && settings.json.format && settings.json.format.enable;
const enableFormatter = settings.json?.format?.enable;
if (enableFormatter) {
if (!formatterRegistrations) {
const documentSelector = [{ language: 'json' }, { language: 'jsonc' }];
@ -309,7 +312,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
function updateConfiguration() {
const languageSettings = {
validate: true,
validate: validateEnabled,
allowComments: true,
schemas: new Array<SchemaConfiguration>()
};
@ -371,10 +374,14 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
function triggerValidation(textDocument: TextDocument): void {
cleanPendingValidation(textDocument);
pendingValidationRequests[textDocument.uri] = runtime.timer.setTimeout(() => {
delete pendingValidationRequests[textDocument.uri];
validateTextDocument(textDocument);
}, validationDelayMs);
if (validateEnabled) {
pendingValidationRequests[textDocument.uri] = runtime.timer.setTimeout(() => {
delete pendingValidationRequests[textDocument.uri];
validateTextDocument(textDocument);
}, validationDelayMs);
} else {
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
}
}
function validateTextDocument(textDocument: TextDocument, callback?: (diagnostics: Diagnostic[]) => void): void {

View File

@ -17,10 +17,10 @@ jsonc-parser@^3.0.0:
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==
request-light@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.7.tgz#1c448c22153b55d2cd278eb414df24a5ad6e6d5e"
integrity sha512-i/wKzvcx7Er8tZnvqSxWuNO5ZGggu2UgZAqj/RyZ0si7lBTXL7kZiI/dWxzxnQjaY7s5HEy1qK21Do4Ncr6cVw==
request-light@^0.5.8:
version "0.5.8"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.8.tgz#8bf73a07242b9e7b601fac2fa5dc22a094abcc27"
integrity sha512-3Zjgh+8b5fhRJBQZoy+zbVKpAQGLyka0MPgW3zruTF4dFFJ8Fqcfu9YsAvi/rvdcaTeWG3MkbZv4WKxAn/84Lg==
vscode-json-languageservice@^4.2.1:
version "4.2.1"

View File

@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae"
integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w==
"@vscode/extension-telemetry@0.4.10":
version "0.4.10"
resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.4.10.tgz#be960c05bdcbea0933866346cf244acad6cac910"
integrity sha512-XgyUoWWRQExTmd9DynIIUQo1NPex/zIeetdUAXeBjVuW9ioojM1TcDaSqOa/5QLC7lx+oEXwSU1r0XSBgzyz6w==
"@vscode/extension-telemetry@0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.5.0.tgz#8214171e550393d577fc56326fa986c6800b831b"
integrity sha512-27FsgeVJvC4zVw7Ar3Ub+7vJswDt8RoBFpbgBwf8Xq/B2gaT8G6a+gkw3s2pQmjWGIqyu7TRA8e9rS8/vxv6NQ==
balanced-match@^1.0.0:
version "1.0.0"
@ -44,10 +44,10 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
request-light@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.7.tgz#1c448c22153b55d2cd278eb414df24a5ad6e6d5e"
integrity sha512-i/wKzvcx7Er8tZnvqSxWuNO5ZGggu2UgZAqj/RyZ0si7lBTXL7kZiI/dWxzxnQjaY7s5HEy1qK21Do4Ncr6cVw==
request-light@^0.5.8:
version "0.5.8"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.8.tgz#8bf73a07242b9e7b601fac2fa5dc22a094abcc27"
integrity sha512-3Zjgh+8b5fhRJBQZoy+zbVKpAQGLyka0MPgW3zruTF4dFFJ8Fqcfu9YsAvi/rvdcaTeWG3MkbZv4WKxAn/84Lg==
semver@^7.3.4:
version "7.3.4"