From 99e717629ee2d70818ef7b4facc092a9d37ea29c Mon Sep 17 00:00:00 2001 From: Stephen Sigwart Date: Wed, 24 Nov 2021 20:56:59 -0500 Subject: [PATCH] Prevent overlapping checks - Because of the await for getDocumentSettings, multiple linters can run for the same file at the same time. On large files, this can cause high CPU usage --- phpcs-server/src/server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpcs-server/src/server.ts b/phpcs-server/src/server.ts index 514df61..7d8fbff 100644 --- a/phpcs-server/src/server.ts +++ b/phpcs-server/src/server.ts @@ -232,7 +232,6 @@ class PhpcsServer { * @param document The text document on which validation started. */ private sendStartValidationNotification(document: TextDocument): void { - this.validating.set(document.uri, document); this.connection.sendNotification( proto.DidStartValidateTextDocumentNotification.type, { textDocument: TextDocumentIdentifier.create(document.uri) } @@ -246,7 +245,6 @@ class PhpcsServer { * @param document The text document on which validation ended. */ private sendEndValidationNotification(document: TextDocument): void { - this.validating.delete(document.uri); this.connection.sendNotification( proto.DidEndValidateTextDocumentNotification.type, { textDocument: TextDocumentIdentifier.create(document.uri) } @@ -263,6 +261,7 @@ class PhpcsServer { public async validateSingle(document: TextDocument): Promise { const { uri } = document; if (this.validating.has(uri) === false) { + this.validating.set(uri, document); let settings = await this.getDocumentSettings(document); if (settings.enable) { let diagnostics: Diagnostic[] = []; @@ -273,9 +272,12 @@ class PhpcsServer { } catch(error) { throw new Error(this.getExceptionMessage(error, document)); } finally { + this.validating.delete(uri); this.sendEndValidationNotification(document); this.sendDiagnostics({ uri, diagnostics }); } + } else { + this.validating.delete(uri); } } }