@@ -10,10 +10,18 @@ export class DiagnosticProvider {
10
10
private diagnosticCollection : vscode . DiagnosticCollection ,
11
11
) {
12
12
rtlDebugger . onDidChangeSession ( ( session ) => {
13
- this . update ( session ) ;
14
- if ( session !== null ) {
15
- session . onDidChangeSimulationStatus ( ( _simulationStatus ) => this . update ( session ) ) ;
16
- session . onDidChangeTimeCursor ( ( _timeCursor ) => this . update ( session ) ) ;
13
+ if ( session === null ) {
14
+ this . clear ( ) ;
15
+ } else {
16
+ session . onDidChangeSimulationStatus ( ( simulationStatus ) => {
17
+ if ( simulationStatus . status === 'running' ) {
18
+ this . clear ( ) ;
19
+ }
20
+ } ) ;
21
+ session . onDidChangeTimeCursor ( ( _timeCursor ) => {
22
+ this . request ( session ) ;
23
+ } ) ;
24
+ this . request ( session ) ;
17
25
}
18
26
} ) ;
19
27
}
@@ -22,17 +30,20 @@ export class DiagnosticProvider {
22
30
this . diagnosticCollection . dispose ( ) ;
23
31
}
24
32
25
- private async update ( session : Session | null ) {
26
- if ( session === null || session ?. simulationStatus . status === 'running' ) {
27
- this . apply ( [ ] ) ;
28
- } else {
29
- const sample = await session . queryAtCursor ( { diagnostics : true } ) ;
30
- this . apply ( sample . diagnostics ! ) ;
31
- }
33
+ private async clear ( ) {
34
+ this . apply ( [ ] ) ;
35
+ }
36
+
37
+ private async request ( session : Session ) {
38
+ const sample = await session . queryAtCursor ( { diagnostics : true } ) ;
39
+ this . apply ( sample . diagnostics ! ) ;
32
40
}
33
41
34
42
private apply ( diagnostics : Diagnostic [ ] ) {
35
43
const diagnosticMap = new Map ( ) ;
44
+ let mostImportantDiagnostic = null ;
45
+ let mostImportantDiagnosticSeverity = vscode . DiagnosticSeverity . Hint ;
46
+ let multipleImportantDiagnostics = false ;
36
47
for ( const diagnostic of diagnostics ) {
37
48
if ( diagnostic . location === null ) {
38
49
continue ;
@@ -85,6 +96,17 @@ export class DiagnosticProvider {
85
96
severity = vscode . DiagnosticSeverity . Error ;
86
97
break ;
87
98
}
99
+ if ( severity !== vscode . DiagnosticSeverity . Information && diagnostic . location !== null ) {
100
+ // Prioritize assertions/assumptions over breakpoints. (It's unclear whether this
101
+ // specific prioritization is the best one, but one of them should probably take
102
+ // priority over the other.)
103
+ multipleImportantDiagnostics = ( mostImportantDiagnostic !== null ) ;
104
+ if ( severity < mostImportantDiagnosticSeverity ) {
105
+ mostImportantDiagnostic = diagnostic ;
106
+ mostImportantDiagnosticSeverity = severity ;
107
+ }
108
+ }
109
+
88
110
if ( message !== '' ) {
89
111
const mappedDiagnostic = new vscode . Diagnostic ( range , message , severity ) ;
90
112
mappedDiagnostic . code = < string > diagnostic . type ;
@@ -95,5 +117,18 @@ export class DiagnosticProvider {
95
117
96
118
this . diagnosticCollection . clear ( ) ;
97
119
this . diagnosticCollection . set ( Array . from ( diagnosticMap . entries ( ) ) ) ;
120
+
121
+ if ( mostImportantDiagnostic !== null ) {
122
+ this . focus ( mostImportantDiagnostic , multipleImportantDiagnostics ) ;
123
+ }
124
+ }
125
+
126
+ private async focus ( diagnostic : Diagnostic , showDiagnosticsPane : boolean = false ) {
127
+ if ( showDiagnosticsPane ) {
128
+ await vscode . commands . executeCommand ( 'workbench.actions.view.problems' ) ;
129
+ }
130
+ // 2024-11-14: Upsettingly, this is the best (and, more or less, only) way to expand a diagnostic.
131
+ await vscode . window . showTextDocument ( ...diagnostic . location ! . openCommandArguments ( ) ) ;
132
+ await vscode . commands . executeCommand ( 'editor.action.marker.next' ) ;
98
133
}
99
134
}
0 commit comments