mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Refactor SchemaRetryNotification to ForceValidateRequest
Now returns the new diagnostics. Also, actually refresh the schemas instead of just revalidating the documents. It worked only sometimes before.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
import {
|
||||
createConnection, IConnection,
|
||||
TextDocuments, TextDocument, InitializeParams, InitializeResult, NotificationType, RequestType,
|
||||
DocumentRangeFormattingRequest, Disposable, ServerCapabilities
|
||||
DocumentRangeFormattingRequest, Disposable, ServerCapabilities, Diagnostic
|
||||
} from 'vscode-languageserver';
|
||||
|
||||
import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDescription } from 'request-light';
|
||||
@@ -34,8 +34,8 @@ namespace SchemaContentChangeNotification {
|
||||
export const type: NotificationType<string, any> = new NotificationType('json/schemaContent');
|
||||
}
|
||||
|
||||
namespace SchemaRetryNotification {
|
||||
export const type: NotificationType<string, any> = new NotificationType('json/schemaRetry');
|
||||
namespace ForceValidateRequest {
|
||||
export const type: RequestType<string, Diagnostic[], any, any> = new RequestType('json/validate');
|
||||
}
|
||||
|
||||
// Create a connection for the server
|
||||
@@ -212,11 +212,18 @@ connection.onNotification(SchemaContentChangeNotification.type, uri => {
|
||||
});
|
||||
|
||||
// Retry schema validation on all open documents
|
||||
connection.onNotification(SchemaRetryNotification.type, uri => {
|
||||
const document = documents.get(uri);
|
||||
if (document) {
|
||||
triggerValidation(document);
|
||||
}
|
||||
connection.onRequest(ForceValidateRequest.type, uri => {
|
||||
return new Promise<Diagnostic[]>(resolve => {
|
||||
const document = documents.get(uri);
|
||||
if (document) {
|
||||
updateConfiguration();
|
||||
validateTextDocument(document, diagnostics => {
|
||||
resolve(diagnostics);
|
||||
});
|
||||
} else {
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function updateConfiguration() {
|
||||
@@ -283,10 +290,15 @@ function triggerValidation(textDocument: TextDocument): void {
|
||||
}, validationDelayMs);
|
||||
}
|
||||
|
||||
function validateTextDocument(textDocument: TextDocument): void {
|
||||
function validateTextDocument(textDocument: TextDocument, callback?: (diagnostics: Diagnostic[]) => void): void {
|
||||
const respond = (diagnostics: Diagnostic[]) => {
|
||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
||||
if (callback) {
|
||||
callback(diagnostics);
|
||||
}
|
||||
};
|
||||
if (textDocument.getText().length === 0) {
|
||||
// ignore empty documents
|
||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
|
||||
respond([]); // ignore empty documents
|
||||
return;
|
||||
}
|
||||
const jsonDocument = getJSONDocument(textDocument);
|
||||
@@ -297,8 +309,7 @@ function validateTextDocument(textDocument: TextDocument): void {
|
||||
setTimeout(() => {
|
||||
const currDocument = documents.get(textDocument.uri);
|
||||
if (currDocument && currDocument.version === version) {
|
||||
// Send the computed diagnostics to VSCode.
|
||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
||||
respond(diagnostics); // Send the computed diagnostics to VSCode.
|
||||
}
|
||||
}, 100);
|
||||
}, error => {
|
||||
|
||||
Reference in New Issue
Block a user