3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { raceCancellablePromises , timeout } from '../../../../base/common/async.js' ;
6
+ import { CancelablePromise , notCancellablePromise , raceCancellablePromises , timeout } from '../../../../base/common/async.js' ;
7
7
import { Emitter , Event } from '../../../../base/common/event.js' ;
8
8
import { Disposable } from '../../../../base/common/lifecycle.js' ;
9
9
import { CommandsRegistry , ICommandEvent , ICommandService } from '../../../../platform/commands/common/commands.js' ;
@@ -17,7 +17,7 @@ export class CommandService extends Disposable implements ICommandService {
17
17
declare readonly _serviceBrand : undefined ;
18
18
19
19
private _extensionHostIsReady : boolean = false ;
20
- private _starActivation : Promise < void > | null ;
20
+ private _starActivation : CancelablePromise < void > | null ;
21
21
22
22
private readonly _onWillExecuteCommand : Emitter < ICommandEvent > = this . _register ( new Emitter < ICommandEvent > ( ) ) ;
23
23
public readonly onWillExecuteCommand : Event < ICommandEvent > = this . _onWillExecuteCommand . event ;
@@ -37,15 +37,16 @@ export class CommandService extends Disposable implements ICommandService {
37
37
38
38
private _activateStar ( ) : Promise < void > {
39
39
if ( ! this . _starActivation ) {
40
- // wait for * activation, limited to at most 30s. This is wrapped with
41
- // Promise.resolve() so it doesn't get cancelled early because it is
42
- // shared between consumers.
43
- this . _starActivation = Promise . resolve ( raceCancellablePromises ( [
40
+ // wait for * activation, limited to at most 30s.
41
+ this . _starActivation = raceCancellablePromises ( [
44
42
this . _extensionService . activateByEvent ( `*` ) ,
45
43
timeout ( 30000 )
46
- ] ) ) ;
44
+ ] ) ;
47
45
}
48
- return this . _starActivation ;
46
+
47
+ // This is wrapped with notCancellablePromise so it doesn't get cancelled
48
+ // early because it is shared between consumers.
49
+ return notCancellablePromise ( this . _starActivation ) ;
49
50
}
50
51
51
52
async executeCommand < T > ( id : string , ...args : any [ ] ) : Promise < T > {
@@ -102,6 +103,11 @@ export class CommandService extends Disposable implements ICommandService {
102
103
return Promise . reject ( err ) ;
103
104
}
104
105
}
106
+
107
+ public override dispose ( ) : void {
108
+ super . dispose ( ) ;
109
+ this . _starActivation ?. cancel ( ) ;
110
+ }
105
111
}
106
112
107
113
registerSingleton ( ICommandService , CommandService , InstantiationType . Delayed ) ;
0 commit comments