1
1
import {
2
+ Disposable ,
2
3
FakeIDE ,
3
4
getFakeCommandServerApi ,
4
5
IDE ,
@@ -35,7 +36,8 @@ import { KeyboardCommands } from "./keyboard/KeyboardCommands";
35
36
import { registerCommands } from "./registerCommands" ;
36
37
import { ReleaseNotes } from "./ReleaseNotes" ;
37
38
import {
38
- ScopeVisualizerCommandApi ,
39
+ ScopeVisualizer ,
40
+ ScopeVisualizerListener ,
39
41
VisualizationType ,
40
42
} from "./ScopeVisualizerCommandApi" ;
41
43
import { StatusBarItem } from "./StatusBarItem" ;
@@ -91,13 +93,14 @@ export async function activate(
91
93
92
94
const statusBarItem = StatusBarItem . create ( "cursorless.showQuickPick" ) ;
93
95
const keyboardCommands = KeyboardCommands . create ( context , statusBarItem ) ;
96
+ const scopeVisualizer = createScopeVisualizer ( normalizedIde , scopeProvider ) ;
94
97
95
98
registerCommands (
96
99
context ,
97
100
vscodeIDE ,
98
101
commandApi ,
99
102
testCaseRecorder ,
100
- createScopeVisualizerCommandApi ( normalizedIde , scopeProvider ) ,
103
+ scopeVisualizer ,
101
104
keyboardCommands ,
102
105
hats ,
103
106
) ;
@@ -155,11 +158,14 @@ function createTreeSitter(parseTreeApi: ParseTreeApi): TreeSitter {
155
158
} ;
156
159
}
157
160
158
- function createScopeVisualizerCommandApi (
161
+ function createScopeVisualizer (
159
162
ide : IDE ,
160
163
scopeProvider : ScopeProvider ,
161
- ) : ScopeVisualizerCommandApi {
164
+ ) : ScopeVisualizer {
162
165
let scopeVisualizer : VscodeScopeVisualizer | undefined ;
166
+ let currentScopeType : ScopeType | undefined ;
167
+
168
+ const listeners : ScopeVisualizerListener [ ] = [ ] ;
163
169
164
170
return {
165
171
start ( scopeType : ScopeType , visualizationType : VisualizationType ) {
@@ -171,11 +177,29 @@ function createScopeVisualizerCommandApi(
171
177
visualizationType ,
172
178
) ;
173
179
scopeVisualizer . start ( ) ;
180
+ currentScopeType = scopeType ;
181
+ listeners . forEach ( ( listener ) => listener ( scopeType , visualizationType ) ) ;
174
182
} ,
175
183
176
184
stop ( ) {
177
185
scopeVisualizer ?. dispose ( ) ;
178
186
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
+ } ;
179
203
} ,
180
204
} ;
181
205
}
0 commit comments