Skip to content

Commit b7c81ac

Browse files
authored
extension host - add reason property and adopt (microsoft#180514) (microsoft#182523)
* extension host - add reason property and adopt (microsoft#180514) * lint
1 parent 5c37a19 commit b7c81ac

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWor
199199
if (environmentService.remoteAuthority) {
200200
hostService.reload(); // TODO@aeschli, workaround
201201
} else if (isNative) {
202-
const stopped = await extensionService.stopExtensionHosts();
202+
const stopped = await extensionService.stopExtensionHosts(localize('restartExtensionHost.reason', "Restart of extensions required because of workspace folder change."));
203203
if (stopped) {
204204
extensionService.startExtensionHosts();
205205
}

src/vs/workbench/services/extensions/common/abstractExtensionService.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,14 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
621621

622622
//#region Stopping / Starting / Restarting
623623

624-
public stopExtensionHosts(): Promise<boolean>;
624+
public stopExtensionHosts(reason: string): Promise<boolean>;
625625
public stopExtensionHosts(force: true): void;
626-
public stopExtensionHosts(force?: boolean): void | Promise<boolean> {
627-
if (force) {
626+
public stopExtensionHosts(arg0: true | string): void | Promise<boolean> {
627+
if (arg0 === true) {
628628
return this._doStopExtensionHosts();
629629
}
630630

631-
return this._doStopExtensionHostsWithVeto();
631+
return this._doStopExtensionHostsWithVeto(arg0);
632632
}
633633

634634
protected _doStopExtensionHosts(): void {
@@ -655,10 +655,11 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
655655
}
656656
}
657657

658-
private async _doStopExtensionHostsWithVeto(): Promise<boolean> {
658+
private async _doStopExtensionHostsWithVeto(reason: string): Promise<boolean> {
659659
const vetos: (boolean | Promise<boolean>)[] = [];
660660

661661
this._onWillStop.fire({
662+
reason,
662663
veto(value) {
663664
vetos.push(value);
664665
}

src/vs/workbench/services/extensions/common/extensions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ export const enum ActivationKind {
325325

326326
export interface WillStopExtensionHostsEvent {
327327

328+
/**
329+
* A human readable reason for stopping the extension hosts
330+
* that e.g. can be shown in a confirmation dialog to the
331+
* user.
332+
*/
333+
readonly reason: string;
334+
328335
/**
329336
* Allows to veto the stopping of extension hosts. The veto can be a long running
330337
* operation.
@@ -445,10 +452,13 @@ export interface IExtensionService {
445452
/**
446453
* Stops the extension hosts.
447454
*
455+
* @param reason a human readable reason for stopping the extension hosts. This maybe
456+
* can be presented to the user when showing dialogs.
457+
*
448458
* @returns a promise that resolves to `true` if the extension hosts were stopped, `false`
449459
* if the operation was vetoed by listeners of the `onWillStop` event.
450460
*/
451-
stopExtensionHosts(): Promise<boolean>;
461+
stopExtensionHosts(reason: string): Promise<boolean>;
452462

453463
/**
454464
* @deprecated Use `stopExtensionHosts()` instead.

src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ class RestartExtensionHostAction extends Action2 {
720720
async run(accessor: ServicesAccessor): Promise<void> {
721721
const extensionService = accessor.get(IExtensionService);
722722

723-
const stopped = await extensionService.stopExtensionHosts();
723+
const stopped = await extensionService.stopExtensionHosts(nls.localize('restartExtensionHost.reason', "Restart of extensions explicitly requested by user."));
724724
if (stopped) {
725725
extensionService.startExtensionHosts();
726726
}

src/vs/workbench/services/extensions/test/browser/extensionService.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ suite('ExtensionService', () => {
260260

261261
test('Extension host disposed when awaited', async () => {
262262
await extService.startExtensionHosts();
263-
await extService.stopExtensionHosts();
263+
await extService.stopExtensionHosts(`foo`);
264264
assert.deepStrictEqual(extService.order, (['create 1', 'create 2', 'create 3', 'dispose 3', 'dispose 2', 'dispose 1']));
265265
});
266266

@@ -270,7 +270,7 @@ suite('ExtensionService', () => {
270270
extService.onWillStop(e => e.veto(true, 'test 1'));
271271
extService.onWillStop(e => e.veto(false, 'test 2'));
272272

273-
await extService.stopExtensionHosts();
273+
await extService.stopExtensionHosts(`foo`);
274274
assert.deepStrictEqual(extService.order, (['create 1', 'create 2', 'create 3']));
275275
});
276276

@@ -281,7 +281,7 @@ suite('ExtensionService', () => {
281281
extService.onWillStop(e => e.veto(Promise.resolve(true), 'test 2'));
282282
extService.onWillStop(e => e.veto(Promise.resolve(false), 'test 3'));
283283

284-
await extService.stopExtensionHosts();
284+
await extService.stopExtensionHosts(`foo`);
285285
assert.deepStrictEqual(extService.order, (['create 1', 'create 2', 'create 3']));
286286
});
287287
});

src/vs/workbench/services/workspaces/electron-sandbox/workspaceEditingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
154154
}
155155

156156
async enterWorkspace(workspaceUri: URI): Promise<void> {
157-
const stopped = await this.extensionService.stopExtensionHosts();
157+
const stopped = await this.extensionService.stopExtensionHosts(localize('restartExtensionHost.reason', "Restart of extensions required because of opening a multi-root workspace."));
158158
if (!stopped) {
159159
return;
160160
}

0 commit comments

Comments
 (0)