Skip to content

Commit

Permalink
extension host - add reason property and adopt (#180514)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed May 15, 2023
1 parent 693848c commit babc5d5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 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 @@ -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 babc5d5

Please sign in to comment.