11import  { 
2+   Disposable , 
23  FakeIDE , 
34  getFakeCommandServerApi , 
45  IDE , 
@@ -35,7 +36,8 @@ import { KeyboardCommands } from "./keyboard/KeyboardCommands";
3536import  {  registerCommands  }  from  "./registerCommands" ; 
3637import  {  ReleaseNotes  }  from  "./ReleaseNotes" ; 
3738import  { 
38-   ScopeVisualizerCommandApi , 
39+   ScopeVisualizer , 
40+   ScopeVisualizerListener , 
3941  VisualizationType , 
4042}  from  "./ScopeVisualizerCommandApi" ; 
4143import  {  StatusBarItem  }  from  "./StatusBarItem" ; 
@@ -91,13 +93,14 @@ export async function activate(
9193
9294  const  statusBarItem  =  StatusBarItem . create ( "cursorless.showQuickPick" ) ; 
9395  const  keyboardCommands  =  KeyboardCommands . create ( context ,  statusBarItem ) ; 
96+   const  scopeVisualizer  =  createScopeVisualizer ( normalizedIde ,  scopeProvider ) ; 
9497
9598  registerCommands ( 
9699    context , 
97100    vscodeIDE , 
98101    commandApi , 
99102    testCaseRecorder , 
100-     createScopeVisualizerCommandApi ( normalizedIde ,   scopeProvider ) , 
103+     scopeVisualizer , 
101104    keyboardCommands , 
102105    hats , 
103106  ) ; 
@@ -155,11 +158,14 @@ function createTreeSitter(parseTreeApi: ParseTreeApi): TreeSitter {
155158  } ; 
156159} 
157160
158- function  createScopeVisualizerCommandApi ( 
161+ function  createScopeVisualizer ( 
159162  ide : IDE , 
160163  scopeProvider : ScopeProvider , 
161- ) : ScopeVisualizerCommandApi  { 
164+ ) : ScopeVisualizer  { 
162165  let  scopeVisualizer : VscodeScopeVisualizer  |  undefined ; 
166+   let  currentScopeType : ScopeType  |  undefined ; 
167+ 
168+   const  listeners : ScopeVisualizerListener [ ]  =  [ ] ; 
163169
164170  return  { 
165171    start ( scopeType : ScopeType ,  visualizationType : VisualizationType )  { 
@@ -171,11 +177,29 @@ function createScopeVisualizerCommandApi(
171177        visualizationType , 
172178      ) ; 
173179      scopeVisualizer . start ( ) ; 
180+       currentScopeType  =  scopeType ; 
181+       listeners . forEach ( ( listener )  =>  listener ( scopeType ,  visualizationType ) ) ; 
174182    } , 
175183
176184    stop ( )  { 
177185      scopeVisualizer ?. dispose ( ) ; 
178186      scopeVisualizer  =  undefined ; 
187+       currentScopeType  =  undefined ; 
188+       listeners . forEach ( ( listener )  =>  listener ( undefined ,  undefined ) ) ; 
189+     } , 
190+ 
191+     get  scopeType ( )  { 
192+       return  currentScopeType ; 
193+     } , 
194+ 
195+     onDidChangeScopeType ( listener : ScopeVisualizerListener ) : Disposable  { 
196+       listeners . push ( listener ) ; 
197+ 
198+       return  { 
199+         dispose ( )  { 
200+           listeners . splice ( listeners . indexOf ( listener ) ,  1 ) ; 
201+         } , 
202+       } ; 
179203    } , 
180204  } ; 
181205} 
0 commit comments