Skip to content

Commit

Permalink
extension host - add reason property and adopt (#180514) (#182523)
Browse files Browse the repository at this point in the history
* extension host - add reason property and adopt (#180514)

* lint
  • Loading branch information
bpasero authored May 15, 2023
1 parent 5c37a19 commit b7c81ac
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWor
if (environmentService.remoteAuthority) {
hostService.reload(); // TODO@aeschli, workaround
} else if (isNative) {
const stopped = await extensionService.stopExtensionHosts();
const stopped = await extensionService.stopExtensionHosts(localize('restartExtensionHost.reason', "Restart of extensions required because of workspace folder change."));
if (stopped) {
extensionService.startExtensionHosts();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,14 +621,14 @@ export abstract class AbstractExtensionService extends Disposable implements IEx

//#region Stopping / Starting / Restarting

public stopExtensionHosts(): Promise<boolean>;
public stopExtensionHosts(reason: string): Promise<boolean>;
public stopExtensionHosts(force: true): void;
public stopExtensionHosts(force?: boolean): void | Promise<boolean> {
if (force) {
public stopExtensionHosts(arg0: true | string): void | Promise<boolean> {
if (arg0 === true) {
return this._doStopExtensionHosts();
}

return this._doStopExtensionHostsWithVeto();
return this._doStopExtensionHostsWithVeto(arg0);
}

protected _doStopExtensionHosts(): void {
Expand All @@ -655,10 +655,11 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
}
}

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

this._onWillStop.fire({
reason,
veto(value) {
vetos.push(value);
}
Expand Down
12 changes: 11 additions & 1 deletion src/vs/workbench/services/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ export const enum ActivationKind {

export interface WillStopExtensionHostsEvent {

/**
* A human readable reason for stopping the extension hosts
* that e.g. can be shown in a confirmation dialog to the
* user.
*/
readonly reason: string;

/**
* Allows to veto the stopping of extension hosts. The veto can be a long running
* operation.
Expand Down Expand Up @@ -445,10 +452,13 @@ export interface IExtensionService {
/**
* Stops the extension hosts.
*
* @param reason a human readable reason for stopping the extension hosts. This maybe
* can be presented to the user when showing dialogs.
*
* @returns a promise that resolves to `true` if the extension hosts were stopped, `false`
* if the operation was vetoed by listeners of the `onWillStop` event.
*/
stopExtensionHosts(): Promise<boolean>;
stopExtensionHosts(reason: string): Promise<boolean>;

/**
* @deprecated Use `stopExtensionHosts()` instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ class RestartExtensionHostAction extends Action2 {
async run(accessor: ServicesAccessor): Promise<void> {
const extensionService = accessor.get(IExtensionService);

const stopped = await extensionService.stopExtensionHosts();
const stopped = await extensionService.stopExtensionHosts(nls.localize('restartExtensionHost.reason', "Restart of extensions explicitly requested by user."));
if (stopped) {
extensionService.startExtensionHosts();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ suite('ExtensionService', () => {

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

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

await extService.stopExtensionHosts();
await extService.stopExtensionHosts(`foo`);
assert.deepStrictEqual(extService.order, (['create 1', 'create 2', 'create 3']));
});

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

await extService.stopExtensionHosts();
await extService.stopExtensionHosts(`foo`);
assert.deepStrictEqual(extService.order, (['create 1', 'create 2', 'create 3']));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
}

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

0 comments on commit b7c81ac

Please sign in to comment.