Skip to content

Commit

Permalink
[json] Allow "json.validate.enable": false in settings / disable JSON…
Browse files Browse the repository at this point in the history
… validation or error checking. Fixes #114775
  • Loading branch information
aeschli committed Apr 12, 2022
1 parent 4f4bf42 commit 8f5b743
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 34 deletions.
2 changes: 1 addition & 1 deletion extensions/html-language-features/server/src/htmlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion extensions/json-language-features/client/src/jsonClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ namespace ResultLimitReachedNotification {
interface Settings {
json?: {
schemas?: JSONSchemaSettings[];
format?: { enable: boolean };
format?: { enable?: boolean };
validate?: { enable?: boolean };
resultLimit?: number;
};
http?: {
Expand All @@ -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';
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions extensions/json-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions extensions/json-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`.",
Expand Down
2 changes: 2 additions & 0 deletions extensions/json-language-features/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion extensions/json-language-features/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 24 additions & 17 deletions extensions/json-language-features/server/src/jsonServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
}

Expand Down Expand Up @@ -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' }];
Expand Down Expand Up @@ -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>()
};
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions extensions/json-language-features/server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions extensions/json-language-features/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 8f5b743

Please sign in to comment.