mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
add a 'json.validate' command (#244784)
This commit is contained in:
committed by
GitHub
parent
7f01c2f4f4
commit
c64fbf3ddb
@@ -40,6 +40,10 @@ namespace LanguageStatusRequest {
|
||||
export const type: RequestType<string, JSONLanguageStatus, any> = new RequestType('json/languageStatus');
|
||||
}
|
||||
|
||||
namespace ValidateContentRequest {
|
||||
export const type: RequestType<{ schemaUri: string; content: string }, Diagnostic[], any> = new RequestType('json/validateContent');
|
||||
}
|
||||
|
||||
export interface DocumentSortingParams {
|
||||
/**
|
||||
* The uri of the document to sort.
|
||||
@@ -299,6 +303,14 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
return [];
|
||||
});
|
||||
|
||||
connection.onRequest(ValidateContentRequest.type, async ({ schemaUri, content }) => {
|
||||
const docURI = 'vscode://schemas/temp/' + new Date().getTime();
|
||||
const document = TextDocument.create(docURI, 'json', 1, content);
|
||||
updateConfiguration([{ uri: schemaUri, fileMatch: [docURI] }]);
|
||||
return await validateTextDocument(document);
|
||||
});
|
||||
|
||||
|
||||
connection.onRequest(LanguageStatusRequest.type, async uri => {
|
||||
const document = documents.get(uri);
|
||||
if (document) {
|
||||
@@ -319,7 +331,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
return [];
|
||||
});
|
||||
|
||||
function updateConfiguration() {
|
||||
function updateConfiguration(extraSchemas?: SchemaConfiguration[]) {
|
||||
const languageSettings = {
|
||||
validate: validateEnabled,
|
||||
allowComments: true,
|
||||
@@ -350,6 +362,10 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
}
|
||||
});
|
||||
}
|
||||
if (extraSchemas) {
|
||||
languageSettings.schemas.push(...extraSchemas);
|
||||
}
|
||||
|
||||
languageService.configure(languageSettings);
|
||||
|
||||
diagnosticsSupport?.requestRefresh();
|
||||
@@ -529,3 +545,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment)
|
||||
function getFullRange(document: TextDocument): Range {
|
||||
return Range.create(Position.create(0, 0), document.positionAt(document.getText().length));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user