From 5749ac1c3e80bb19a0ce06a1ee4da5728f79be32 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Aug 2016 08:34:17 +0100 Subject: [PATCH] async display of linting results (#190) --- src/client/providers/lintProvider.ts | 48 +++++++++++++++------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/client/providers/lintProvider.ts b/src/client/providers/lintProvider.ts index 02e25bb58377..3ce7c483c72c 100644 --- a/src/client/providers/lintProvider.ts +++ b/src/client/providers/lintProvider.ts @@ -102,7 +102,7 @@ export class LintProvider extends vscode.Disposable { this.pendingLintings.set(documentUri.fsPath, cancelToken); this.outputChannel.clear(); - let promises = this.linters.map(linter => { + let promises: Promise[] = this.linters.map(linter => { if (!linter.isEnabled()) { return Promise.resolve([]); } @@ -114,27 +114,29 @@ export class LintProvider extends vscode.Disposable { }); }); - Promise.all(promises).then(msgs => { - if (cancelToken.token.isCancellationRequested) { - return; - } - - // Flatten the array - let consolidatedMessages: linter.ILintMessage[] = []; - msgs.forEach(lintMessages => consolidatedMessages = consolidatedMessages.concat(lintMessages)); - - // Limit the number of messages to the max value - consolidatedMessages = consolidatedMessages.filter((value, index) => index <= this.settings.linting.maxNumberOfProblems); - - // Build the message and suffix the message with the name of the linter used - let messages = []; - consolidatedMessages.forEach(d => { - d.message = `${d.message}`; - messages.push(createDiagnostics(d, documentLines)); - }); - - this.diagnosticCollection.delete(documentUri); - this.diagnosticCollection.set(documentUri, messages); - }); + // linters will resolve asynchronously - keep a track of all + // diagnostics reported as them come in + let diagnostics: vscode.Diagnostic[] = []; + + promises.forEach(p => { + p.then(msgs => { + if (cancelToken.token.isCancellationRequested) { + return; + } + + // Build the message and suffix the message with the name of the linter used + msgs.forEach(d => { + d.message = `${d.message}`; + diagnostics.push(createDiagnostics(d, documentLines)); + }); + + // Limit the number of messages to the max value + diagnostics = diagnostics.filter((value, index) => index <= this.settings.linting.maxNumberOfProblems); + + // set all diagnostics found in this pass, as this method always clears existing diagnostics. + this.diagnosticCollection.set(documentUri, diagnostics) + + }) + }) } } \ No newline at end of file