Skip to content

Commit

Permalink
Focus important diagnostics (break, assert, assume) after moving cursor.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Nov 15, 2024
1 parent ba3d495 commit e0f16ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
3 changes: 3 additions & 0 deletions example/design.sv
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ module top(
always @(posedge clk)
assert (timer < 5);

always @(posedge clk)
assert (timer < 7); // two asserts at once

endmodule
1 change: 0 additions & 1 deletion src/debug/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ export class Session {
if (this.simulationStatus.status === 'paused') {
const nextSampleTime = this.simulationStatus.nextSampleTime!;
await this.runSimulation({ untilTime: nextSampleTime });
await this.querySimulationStatus();
if (!nextSampleTime.greaterThan(this.simulationStatus.latestTime)) {
this.timeCursor = nextSampleTime;
}
Expand Down
3 changes: 2 additions & 1 deletion src/model/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Location {
);
}

private openCommandArguments(): [vscode.Uri, vscode.TextDocumentShowOptions] {
openCommandArguments(): [vscode.Uri, vscode.TextDocumentShowOptions] {
const position = new vscode.Position(this.startLine, this.startColumn ?? 0);
return [
this.fileUri,
Expand All @@ -60,6 +60,7 @@ export class Location {
};
}

// Really? *Three* different command representations depending on the API? VS Code please.
asOpenCommandUri(): vscode.Uri {
const args = this.openCommandArguments();
return vscode.Uri.parse(`command:rtlDebugger.openDocument?${encodeURIComponent(JSON.stringify(args))}`);
Expand Down
57 changes: 46 additions & 11 deletions src/ui/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ export class DiagnosticProvider {
private diagnosticCollection: vscode.DiagnosticCollection,
) {
rtlDebugger.onDidChangeSession((session) => {
this.update(session);
if (session !== null) {
session.onDidChangeSimulationStatus((_simulationStatus) => this.update(session));
session.onDidChangeTimeCursor((_timeCursor) => this.update(session));
if (session === null) {
this.clear();
} else {
session.onDidChangeSimulationStatus((simulationStatus) => {
if (simulationStatus.status === 'running') {
this.clear();
}
});
session.onDidChangeTimeCursor((_timeCursor) => {
this.request(session);
});
this.request(session);
}
});
}
Expand All @@ -22,17 +30,20 @@ export class DiagnosticProvider {
this.diagnosticCollection.dispose();
}

private async update(session: Session | null) {
if (session === null || session?.simulationStatus.status === 'running') {
this.apply([]);
} else {
const sample = await session.queryAtCursor({ diagnostics: true });
this.apply(sample.diagnostics!);
}
private async clear() {
this.apply([]);
}

private async request(session: Session) {
const sample = await session.queryAtCursor({ diagnostics: true });
this.apply(sample.diagnostics!);
}

private apply(diagnostics: Diagnostic[]) {
const diagnosticMap = new Map();
let mostImportantDiagnostic = null;
let mostImportantDiagnosticSeverity = vscode.DiagnosticSeverity.Hint;
let multipleImportantDiagnostics = false;
for (const diagnostic of diagnostics) {
if (diagnostic.location === null) {
continue;
Expand Down Expand Up @@ -85,6 +96,17 @@ export class DiagnosticProvider {
severity = vscode.DiagnosticSeverity.Error;
break;
}
if (severity !== vscode.DiagnosticSeverity.Information && diagnostic.location !== null) {
// Prioritize assertions/assumptions over breakpoints. (It's unclear whether this
// specific prioritization is the best one, but one of them should probably take
// priority over the other.)
multipleImportantDiagnostics = (mostImportantDiagnostic !== null);
if (severity < mostImportantDiagnosticSeverity) {
mostImportantDiagnostic = diagnostic;
mostImportantDiagnosticSeverity = severity;
}
}

if (message !== '') {
const mappedDiagnostic = new vscode.Diagnostic(range, message, severity);
mappedDiagnostic.code = <string>diagnostic.type;
Expand All @@ -95,5 +117,18 @@ export class DiagnosticProvider {

this.diagnosticCollection.clear();
this.diagnosticCollection.set(Array.from(diagnosticMap.entries()));

if (mostImportantDiagnostic !== null) {
this.focus(mostImportantDiagnostic, multipleImportantDiagnostics);
}
}

private async focus(diagnostic: Diagnostic, showDiagnosticsPane: boolean = false) {
if (showDiagnosticsPane) {
await vscode.commands.executeCommand('workbench.actions.view.problems');
}
// 2024-11-14: Upsettingly, this is the best (and, more or less, only) way to expand a diagnostic.
await vscode.window.showTextDocument(...diagnostic.location!.openCommandArguments());
await vscode.commands.executeCommand('editor.action.marker.next');
}
}

0 comments on commit e0f16ee

Please sign in to comment.