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

View file

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

View file

@ -73,6 +73,12 @@
} }
} }
}, },
"json.validate.enable": {
"type": "boolean",
"scope": "window",
"default": true,
"description": "%json.validate.enable.desc%"
},
"json.format.enable": { "json.format.enable": {
"type": "boolean", "type": "boolean",
"scope": "window", "scope": "window",
@ -141,8 +147,8 @@
] ]
}, },
"dependencies": { "dependencies": {
"request-light": "^0.5.7", "@vscode/extension-telemetry": "0.5.0",
"@vscode/extension-telemetry": "0.4.10", "request-light": "^0.5.8",
"vscode-languageclient": "^7.0.0", "vscode-languageclient": "^7.0.0",
"vscode-nls": "^5.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.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.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.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.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.desc": "Enables or disables color decorators",
"json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`.", "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 - json
- `format` - `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. - `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. - `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. - `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. - `url`: The URL of the schema, optional when also a schema is provided.

View file

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

View file

@ -57,7 +57,7 @@ export interface RequestService {
export interface RuntimeEnvironment { export interface RuntimeEnvironment {
file?: RequestService; file?: RequestService;
http?: RequestService; http?: RequestService;
configureHttpRequests?(proxy: string, strictSSL: boolean): void; configureHttpRequests?(proxy: string | undefined, strictSSL: boolean): void;
readonly timer: { readonly timer: {
setImmediate(callback: (...args: any[]) => void, ...args: any[]): Disposable; setImmediate(callback: (...args: any[]) => void, ...args: any[]): Disposable;
setTimeout(callback: (...args: any[]) => void, ms: number, ...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 // The settings interface describes the server relevant settings part
interface Settings { interface Settings {
json: { json?: {
schemas: JSONSchemaSettings[]; schemas?: JSONSchemaSettings[];
format: { enable: boolean }; format?: { enable?: boolean };
validate?: { enable?: boolean };
resultLimit?: number; resultLimit?: number;
}; };
http: { http?: {
proxy: string; proxy?: string;
proxyStrictSSL: boolean; proxyStrictSSL?: boolean;
}; };
} }
@ -226,22 +227,24 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined; let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
let schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined; let schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined;
let formatterRegistrations: Thenable<Disposable>[] | null = null; let formatterRegistrations: Thenable<Disposable>[] | null = null;
let validateEnabled = true;
// The settings have changed. Is send on server activation as well. // The settings have changed. Is send on server activation as well.
connection.onDidChangeConfiguration((change) => { connection.onDidChangeConfiguration((change) => {
let settings = <Settings>change.settings; let settings = <Settings>change.settings;
if (runtime.configureHttpRequests) { 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(); updateConfiguration();
foldingRangeLimit = Math.trunc(Math.max(settings.json && settings.json.resultLimit || foldingRangeLimitDefault, 0)); foldingRangeLimit = Math.trunc(Math.max(settings.json?.resultLimit || foldingRangeLimitDefault, 0));
resultLimit = Math.trunc(Math.max(settings.json && settings.json.resultLimit || Number.MAX_VALUE, 0)); resultLimit = Math.trunc(Math.max(settings.json?.resultLimit || Number.MAX_VALUE, 0));
// dynamically enable & disable the formatter // dynamically enable & disable the formatter
if (dynamicFormatterRegistration) { if (dynamicFormatterRegistration) {
const enableFormatter = settings && settings.json && settings.json.format && settings.json.format.enable; const enableFormatter = settings.json?.format?.enable;
if (enableFormatter) { if (enableFormatter) {
if (!formatterRegistrations) { if (!formatterRegistrations) {
const documentSelector = [{ language: 'json' }, { language: 'jsonc' }]; const documentSelector = [{ language: 'json' }, { language: 'jsonc' }];
@ -309,7 +312,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
function updateConfiguration() { function updateConfiguration() {
const languageSettings = { const languageSettings = {
validate: true, validate: validateEnabled,
allowComments: true, allowComments: true,
schemas: new Array<SchemaConfiguration>() schemas: new Array<SchemaConfiguration>()
}; };
@ -371,10 +374,14 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
function triggerValidation(textDocument: TextDocument): void { function triggerValidation(textDocument: TextDocument): void {
cleanPendingValidation(textDocument); cleanPendingValidation(textDocument);
pendingValidationRequests[textDocument.uri] = runtime.timer.setTimeout(() => { if (validateEnabled) {
delete pendingValidationRequests[textDocument.uri]; pendingValidationRequests[textDocument.uri] = runtime.timer.setTimeout(() => {
validateTextDocument(textDocument); delete pendingValidationRequests[textDocument.uri];
}, validationDelayMs); validateTextDocument(textDocument);
}, validationDelayMs);
} else {
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
}
} }
function validateTextDocument(textDocument: TextDocument, callback?: (diagnostics: Diagnostic[]) => void): void { 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" resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA== integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==
request-light@^0.5.7: request-light@^0.5.8:
version "0.5.7" version "0.5.8"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.7.tgz#1c448c22153b55d2cd278eb414df24a5ad6e6d5e" resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.8.tgz#8bf73a07242b9e7b601fac2fa5dc22a094abcc27"
integrity sha512-i/wKzvcx7Er8tZnvqSxWuNO5ZGggu2UgZAqj/RyZ0si7lBTXL7kZiI/dWxzxnQjaY7s5HEy1qK21Do4Ncr6cVw== integrity sha512-3Zjgh+8b5fhRJBQZoy+zbVKpAQGLyka0MPgW3zruTF4dFFJ8Fqcfu9YsAvi/rvdcaTeWG3MkbZv4WKxAn/84Lg==
vscode-json-languageservice@^4.2.1: vscode-json-languageservice@^4.2.1:
version "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" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae"
integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w== integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w==
"@vscode/extension-telemetry@0.4.10": "@vscode/extension-telemetry@0.5.0":
version "0.4.10" version "0.5.0"
resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.4.10.tgz#be960c05bdcbea0933866346cf244acad6cac910" resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.5.0.tgz#8214171e550393d577fc56326fa986c6800b831b"
integrity sha512-XgyUoWWRQExTmd9DynIIUQo1NPex/zIeetdUAXeBjVuW9ioojM1TcDaSqOa/5QLC7lx+oEXwSU1r0XSBgzyz6w== integrity sha512-27FsgeVJvC4zVw7Ar3Ub+7vJswDt8RoBFpbgBwf8Xq/B2gaT8G6a+gkw3s2pQmjWGIqyu7TRA8e9rS8/vxv6NQ==
balanced-match@^1.0.0: balanced-match@^1.0.0:
version "1.0.0" version "1.0.0"
@ -44,10 +44,10 @@ minimatch@^3.0.4:
dependencies: dependencies:
brace-expansion "^1.1.7" brace-expansion "^1.1.7"
request-light@^0.5.7: request-light@^0.5.8:
version "0.5.7" version "0.5.8"
resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.7.tgz#1c448c22153b55d2cd278eb414df24a5ad6e6d5e" resolved "https://registry.yarnpkg.com/request-light/-/request-light-0.5.8.tgz#8bf73a07242b9e7b601fac2fa5dc22a094abcc27"
integrity sha512-i/wKzvcx7Er8tZnvqSxWuNO5ZGggu2UgZAqj/RyZ0si7lBTXL7kZiI/dWxzxnQjaY7s5HEy1qK21Do4Ncr6cVw== integrity sha512-3Zjgh+8b5fhRJBQZoy+zbVKpAQGLyka0MPgW3zruTF4dFFJ8Fqcfu9YsAvi/rvdcaTeWG3MkbZv4WKxAn/84Lg==
semver@^7.3.4: semver@^7.3.4:
version "7.3.4" version "7.3.4"