Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async display of linting results (#190) #264

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/client/providers/lintProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<linter.ILintMessage[]>[] = this.linters.map(linter => {
if (!linter.isEnabled()) {
return Promise.resolve([]);
}
Expand All @@ -114,27 +114,29 @@ export class LintProvider extends vscode.Disposable {
});
});

Promise.all<linter.ILintMessage[]>(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}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DonJayamanne I kept this line from the previous code but it doesn't make sense to me - as d.message is a string, surely:

d.message === `${d.message}`

so this is a no-op?

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)

})
})
}
}