@@ -7,10 +7,23 @@ import { TimeInterval, TimePoint } from '../model/time';
77import { Reference , Sample , UnboundReference } from '../model/sample' ;
88import { Variable } from '../model/variable' ;
99import { Scope } from '../model/scope' ;
10+ import { Location } from '../model/source' ;
1011
1112function lazy < T > ( thunk : ( ) => Thenable < T > ) : Thenable < T > {
1213 return { then : ( onfulfilled , onrejected ) => thunk ( ) . then ( onfulfilled , onrejected ) } ;
1314}
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+ }
1427
1528export interface ISimulationStatus {
1629 status : 'running' | 'paused' | 'finished' ;
@@ -35,10 +48,6 @@ export class Session {
3548 this . connection . dispose ( ) ;
3649 }
3750
38- get connection2 ( ) : Connection {
39- return this . connection ;
40- }
41-
4251 // ======================================== Inspecting the design
4352
4453 private itemCache : Map < string , proto . ItemDescriptionMap > = new Map ( ) ;
@@ -145,6 +154,27 @@ export class Session {
145154 }
146155 }
147156
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+
148178 // ======================================== Querying the database
149179
150180 private referenceEpochs : Map < string , number > = new Map ( ) ;
@@ -184,8 +214,8 @@ export class Session {
184214 }
185215
186216 async queryInterval (
187- interval : TimeInterval ,
188217 reference : Reference ,
218+ interval : TimeInterval ,
189219 options : { collapse ?: boolean } = { }
190220 ) : Promise < Sample [ ] > {
191221 this . checkReferenceEpoch ( reference . name , reference . epoch ) ;
@@ -213,6 +243,12 @@ export class Session {
213243 } ) ;
214244 }
215245
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+
216252 // ======================================== Manipulating the simulation
217253
218254 private simulationStatusTimeout : NodeJS . Timeout | null = null ;
0 commit comments