@@ -7,10 +7,23 @@ import { TimeInterval, TimePoint } from '../model/time';
7
7
import { Reference , Sample , UnboundReference } from '../model/sample' ;
8
8
import { Variable } from '../model/variable' ;
9
9
import { Scope } from '../model/scope' ;
10
+ import { Location } from '../model/source' ;
10
11
11
12
function lazy < T > ( thunk : ( ) => Thenable < T > ) : Thenable < T > {
12
13
return { then : ( onfulfilled , onrejected ) => thunk ( ) . then ( onfulfilled , onrejected ) } ;
13
14
}
15
+ function matchLocation ( location : Location , filename : string , position : vscode . Position ) {
16
+ if ( location . file !== filename ) {
17
+ return false ;
18
+ }
19
+ if ( location . startLine !== position . line ) {
20
+ return false ;
21
+ }
22
+ if ( location . startColumn !== undefined && location . startColumn !== position . character ) {
23
+ return false ;
24
+ }
25
+ return true ;
26
+ }
14
27
15
28
export interface ISimulationStatus {
16
29
status : 'running' | 'paused' | 'finished' ;
@@ -35,10 +48,6 @@ export class Session {
35
48
this . connection . dispose ( ) ;
36
49
}
37
50
38
- get connection2 ( ) : Connection {
39
- return this . connection ;
40
- }
41
-
42
51
// ======================================== Inspecting the design
43
52
44
53
private itemCache : Map < string , proto . ItemDescriptionMap > = new Map ( ) ;
@@ -145,6 +154,27 @@ export class Session {
145
154
}
146
155
}
147
156
157
+ async getVariablesForLocation ( filename : string , position : vscode . Position ) : Promise < Variable [ ] > {
158
+ const variables : Variable [ ] = [ ] ;
159
+ const extractVariablesForLocationFromScope = async ( scope : string ) => {
160
+ const items = await this . listItemsInScope ( scope ) ;
161
+ for ( const [ itemName , itemDesc ] of Object . entries ( items ) ) {
162
+ const itemLocation = Location . fromCXXRTL ( itemDesc . src ) ;
163
+ console . log ( itemLocation , filename , position , itemLocation !== null && matchLocation ( itemLocation , filename , position ) ) ;
164
+ if ( itemLocation !== null && matchLocation ( itemLocation , filename , position ) ) {
165
+ variables . push ( Variable . fromCXXRTL ( itemName , itemDesc ) ) ;
166
+ }
167
+ }
168
+ const subScopes = await this . listScopesInScope ( scope ) ;
169
+ for ( const subScopeName of Object . keys ( subScopes ) ) {
170
+ await extractVariablesForLocationFromScope ( subScopeName ) ;
171
+ }
172
+ return null ;
173
+ } ;
174
+ await extractVariablesForLocationFromScope ( '' ) ;
175
+ return variables ;
176
+ }
177
+
148
178
// ======================================== Querying the database
149
179
150
180
private referenceEpochs : Map < string , number > = new Map ( ) ;
@@ -184,8 +214,8 @@ export class Session {
184
214
}
185
215
186
216
async queryInterval (
187
- interval : TimeInterval ,
188
217
reference : Reference ,
218
+ interval : TimeInterval ,
189
219
options : { collapse ?: boolean } = { }
190
220
) : Promise < Sample [ ] > {
191
221
this . checkReferenceEpoch ( reference . name , reference . epoch ) ;
@@ -213,6 +243,12 @@ export class Session {
213
243
} ) ;
214
244
}
215
245
246
+ async queryAtCursor ( reference : Reference ) : Promise < Sample > {
247
+ const interval = new TimeInterval ( this . timeCursor , this . timeCursor ) ;
248
+ const [ sample ] = await this . queryInterval ( reference , interval ) ;
249
+ return sample ;
250
+ }
251
+
216
252
// ======================================== Manipulating the simulation
217
253
218
254
private simulationStatusTimeout : NodeJS . Timeout | null = null ;
0 commit comments