@@ -45,7 +45,15 @@ interface ProgressParams {
4545 done ?: boolean ;
4646}
4747
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 > {
4957 context . subscriptions . push (
5058 ...[
5159 configureLanguage ( ) ,
@@ -84,6 +92,8 @@ export async function activate(context: ExtensionContext) {
8492 return ;
8593 } ) ;
8694 }
95+
96+ return { activeWorkspace } ;
8797}
8898
8999export async function deactivate ( ) {
@@ -106,7 +116,7 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
106116 return ;
107117 }
108118
109- activeWorkspace = workspace ;
119+ activeWorkspace . value = workspace ;
110120
111121 const updateProgress = ( progress : WorkspaceProgress ) => {
112122 if ( progress . state === 'progress' ) {
@@ -121,9 +131,9 @@ function onDidChangeActiveTextEditor(editor: TextEditor | undefined) {
121131 if ( progressObserver ) {
122132 progressObserver . dispose ( ) ;
123133 }
124- progressObserver = activeWorkspace . progress . observe ( updateProgress ) ;
134+ progressObserver = workspace . progress . observe ( updateProgress ) ;
125135 // Update UI ourselves immediately and don't wait for value update callbacks
126- updateProgress ( activeWorkspace . progress . value ) ;
136+ updateProgress ( workspace . progress . value ) ;
127137}
128138
129139function whenChangingWorkspaceFolders ( e : WorkspaceFoldersChangeEvent ) {
@@ -176,7 +186,7 @@ type WorkspaceProgress =
176186// We run one RLS and one corresponding language client per workspace folder
177187// (VSCode workspace, not Cargo workspace). This class contains all the per-client
178188// and per-workspace stuff.
179- class ClientWorkspace {
189+ export class ClientWorkspace {
180190 public readonly folder : WorkspaceFolder ;
181191 // FIXME(#233): Don't only rely on lazily initializing it once on startup,
182192 // handle possible `rust-client.*` value changes while extension is running
@@ -440,7 +450,7 @@ class ClientWorkspace {
440450 * Tracks the most current VSCode workspace as opened by the user. Used by the
441451 * commands to know in which workspace these should be executed.
442452 */
443- let activeWorkspace : ClientWorkspace | null ;
453+ const activeWorkspace = new Observable < ClientWorkspace | null > ( null ) ;
444454
445455/**
446456 * Registers the VSCode [commands] used by the extension.
@@ -451,23 +461,24 @@ function registerCommands(): Disposable[] {
451461 return [
452462 commands . registerCommand (
453463 'rls.update' ,
454- ( ) => activeWorkspace && activeWorkspace . rustupUpdate ( ) ,
464+ ( ) => activeWorkspace . value && activeWorkspace . value . rustupUpdate ( ) ,
455465 ) ,
456466 commands . registerCommand (
457467 'rls.restart' ,
458- async ( ) => activeWorkspace && activeWorkspace . restart ( ) ,
468+ async ( ) => activeWorkspace . value && activeWorkspace . value . restart ( ) ,
459469 ) ,
460470 commands . registerCommand (
461471 'rls.run' ,
462- ( cmd : Execution ) => activeWorkspace && activeWorkspace . runRlsCommand ( cmd ) ,
472+ ( cmd : Execution ) =>
473+ activeWorkspace . value && activeWorkspace . value . runRlsCommand ( cmd ) ,
463474 ) ,
464475 commands . registerCommand (
465476 'rls.start' ,
466- ( ) => activeWorkspace && activeWorkspace . start ( ) ,
477+ ( ) => activeWorkspace . value && activeWorkspace . value . start ( ) ,
467478 ) ,
468479 commands . registerCommand (
469480 'rls.stop' ,
470- ( ) => activeWorkspace && activeWorkspace . stop ( ) ,
481+ ( ) => activeWorkspace . value && activeWorkspace . value . stop ( ) ,
471482 ) ,
472483 ] ;
473484}
0 commit comments