@@ -45,7 +45,15 @@ interface ProgressParams {
45
45
done ?: boolean ;
46
46
}
47
47
48
- export async function activate ( context : ExtensionContext ) {
48
+ /**
49
+ * External API as exposed by the extension. Can be queried by other extensions
50
+ * or by the integration test runner for VSCode extensions.
51
+ */
52
+ export interface Api {
53
+ activeWorkspace : typeof activeWorkspace ;
54
+ }
55
+
56
+ export async function activate ( context : ExtensionContext ) : Promise < Api > {
49
57
context . subscriptions . push (
50
58
...[
51
59
configureLanguage ( ) ,
@@ -84,6 +92,8 @@ export async function activate(context: ExtensionContext) {
84
92
return ;
85
93
} ) ;
86
94
}
95
+
96
+ return { activeWorkspace } ;
87
97
}
88
98
89
99
export async function deactivate ( ) {
@@ -106,7 +116,7 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
106
116
return ;
107
117
}
108
118
109
- activeWorkspace = workspace ;
119
+ activeWorkspace . value = workspace ;
110
120
111
121
const updateProgress = ( progress : WorkspaceProgress ) => {
112
122
if ( progress . state === 'progress' ) {
@@ -121,9 +131,9 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
121
131
if ( progressObserver ) {
122
132
progressObserver . dispose ( ) ;
123
133
}
124
- progressObserver = activeWorkspace . progress . observe ( updateProgress ) ;
134
+ progressObserver = workspace . progress . observe ( updateProgress ) ;
125
135
// Update UI ourselves immediately and don't wait for value update callbacks
126
- updateProgress ( activeWorkspace . progress . value ) ;
136
+ updateProgress ( workspace . progress . value ) ;
127
137
}
128
138
129
139
function whenChangingWorkspaceFolders ( e : WorkspaceFoldersChangeEvent ) {
@@ -176,7 +186,7 @@ type WorkspaceProgress =
176
186
// We run one RLS and one corresponding language client per workspace folder
177
187
// (VSCode workspace, not Cargo workspace). This class contains all the per-client
178
188
// and per-workspace stuff.
179
- class ClientWorkspace {
189
+ export class ClientWorkspace {
180
190
public readonly folder : WorkspaceFolder ;
181
191
// FIXME(#233): Don't only rely on lazily initializing it once on startup,
182
192
// handle possible `rust-client.*` value changes while extension is running
@@ -440,7 +450,7 @@ class ClientWorkspace {
440
450
* Tracks the most current VSCode workspace as opened by the user. Used by the
441
451
* commands to know in which workspace these should be executed.
442
452
*/
443
- let activeWorkspace : ClientWorkspace | null ;
453
+ const activeWorkspace = new Observable < ClientWorkspace | null > ( null ) ;
444
454
445
455
/**
446
456
* Registers the VSCode [commands] used by the extension.
@@ -451,23 +461,24 @@ function registerCommands(): Disposable[] {
451
461
return [
452
462
commands . registerCommand (
453
463
'rls.update' ,
454
- ( ) => activeWorkspace && activeWorkspace . rustupUpdate ( ) ,
464
+ ( ) => activeWorkspace . value && activeWorkspace . value . rustupUpdate ( ) ,
455
465
) ,
456
466
commands . registerCommand (
457
467
'rls.restart' ,
458
- async ( ) => activeWorkspace && activeWorkspace . restart ( ) ,
468
+ async ( ) => activeWorkspace . value && activeWorkspace . value . restart ( ) ,
459
469
) ,
460
470
commands . registerCommand (
461
471
'rls.run' ,
462
- ( cmd : Execution ) => activeWorkspace && activeWorkspace . runRlsCommand ( cmd ) ,
472
+ ( cmd : Execution ) =>
473
+ activeWorkspace . value && activeWorkspace . value . runRlsCommand ( cmd ) ,
463
474
) ,
464
475
commands . registerCommand (
465
476
'rls.start' ,
466
- ( ) => activeWorkspace && activeWorkspace . start ( ) ,
477
+ ( ) => activeWorkspace . value && activeWorkspace . value . start ( ) ,
467
478
) ,
468
479
commands . registerCommand (
469
480
'rls.stop' ,
470
- ( ) => activeWorkspace && activeWorkspace . stop ( ) ,
481
+ ( ) => activeWorkspace . value && activeWorkspace . value . stop ( ) ,
471
482
) ,
472
483
] ;
473
484
}
0 commit comments