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

De-duplicate cargo watch diagnostics #1438

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 21 additions & 1 deletion editors/code/src/commands/cargo_watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ export class CargoWatchProvider implements vscode.Disposable {
return vscode.DiagnosticSeverity.Information;
}

function areDiagnosticsEqual(
left: vscode.Diagnostic,
right: vscode.Diagnostic
): boolean {
return (
left.source === right.source &&
left.severity === right.severity &&
left.range.isEqual(right.range) &&
left.message === right.message
);
}

// Reference:
// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
interface RustDiagnosticSpan {
Expand Down Expand Up @@ -247,7 +259,15 @@ export class CargoWatchProvider implements vscode.Disposable {
const diagnostics: vscode.Diagnostic[] = [
...(this.diagnosticCollection!.get(fileUrl) || [])
];
diagnostics.push(diagnostic);

// If we're building multiple targets it's possible we've already seen this diagnostic
const isDuplicate = diagnostics.some(d =>
areDiagnosticsEqual(d, diagnostic)
);

if (!isDuplicate) {
diagnostics.push(diagnostic);
}

this.diagnosticCollection!.set(fileUrl, diagnostics);
}
Expand Down