mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-02 00:09:30 +01:00
Add configurable severity levels for JSON validation (#297911)
Co-authored-by: Martin Aeschlimann <martinae@microsoft.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
import { runSafe, runSafeAsync } from './utils/runner';
|
||||
import { DiagnosticsSupport, registerDiagnosticsPullSupport, registerDiagnosticsPushSupport } from './utils/validation';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position, SortOptions } from 'vscode-json-languageservice';
|
||||
import { TextDocument, JSONDocument, JSONSchema, getLanguageService, DocumentLanguageSettings, SchemaConfiguration, ClientCapabilities, Range, Position, SortOptions, SeverityLevel } from 'vscode-json-languageservice';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
import { Utils, URI } from 'vscode-uri';
|
||||
import * as l10n from '@vscode/l10n';
|
||||
@@ -216,7 +216,13 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
schemas?: JSONSchemaSettings[];
|
||||
format?: { enable?: boolean };
|
||||
keepLines?: { enable?: boolean };
|
||||
validate?: { enable?: boolean };
|
||||
validate?: {
|
||||
enable?: boolean;
|
||||
comments?: SeverityLevel;
|
||||
trailingCommas?: SeverityLevel;
|
||||
schemaValidation?: SeverityLevel;
|
||||
schemaRequest?: SeverityLevel;
|
||||
};
|
||||
resultLimit?: number;
|
||||
jsonFoldingLimit?: number;
|
||||
jsoncFoldingLimit?: number;
|
||||
@@ -242,6 +248,10 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
let schemaAssociations: ISchemaAssociations | SchemaConfiguration[] | undefined = undefined;
|
||||
let formatterRegistrations: Thenable<Disposable>[] | null = null;
|
||||
let validateEnabled = true;
|
||||
let commentsSeverity: SeverityLevel | undefined = undefined;
|
||||
let trailingCommasSeverity: SeverityLevel | undefined = undefined;
|
||||
let schemaValidationSeverity: SeverityLevel | undefined = undefined;
|
||||
let schemaRequestSeverity: SeverityLevel | undefined = undefined;
|
||||
let keepLinesEnabled = false;
|
||||
|
||||
// The settings have changed. Is sent on server activation as well.
|
||||
@@ -250,6 +260,10 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
runtime.configureHttpRequests?.(settings?.http?.proxy, !!settings.http?.proxyStrictSSL);
|
||||
jsonConfigurationSettings = settings.json?.schemas;
|
||||
validateEnabled = !!settings.json?.validate?.enable;
|
||||
commentsSeverity = settings.json?.validate?.comments;
|
||||
trailingCommasSeverity = settings.json?.validate?.trailingCommas;
|
||||
schemaValidationSeverity = settings.json?.validate?.schemaValidation;
|
||||
schemaRequestSeverity = settings.json?.validate?.schemaRequest;
|
||||
keepLinesEnabled = settings.json?.keepLines?.enable || false;
|
||||
updateConfiguration();
|
||||
|
||||
@@ -388,7 +402,12 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
return []; // ignore empty documents
|
||||
}
|
||||
const jsonDocument = getJSONDocument(textDocument);
|
||||
const documentSettings: DocumentLanguageSettings = textDocument.languageId === 'jsonc' ? { comments: 'ignore', trailingCommas: 'warning' } : { comments: 'error', trailingCommas: 'error' };
|
||||
const documentSettings: DocumentLanguageSettings = {
|
||||
comments: commentsSeverity ?? (textDocument.languageId === 'jsonc' ? 'ignore' : 'error'),
|
||||
trailingCommas: trailingCommasSeverity ?? (textDocument.languageId === 'jsonc' ? 'warning' : 'error'),
|
||||
schemaValidation: schemaValidationSeverity,
|
||||
schemaRequest: schemaRequestSeverity
|
||||
};
|
||||
return await languageService.doValidation(textDocument, jsonDocument, documentSettings);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user