Skip to content

Commit a383dc0

Browse files
author
Benjamin Pasero
committed
atomic ext host restart (fix microsoft#78609)
1 parent 9e65deb commit a383dc0

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ export class WorkspaceChangeExtHostRelauncher extends Disposable implements IWor
167167
if (!!environmentService.extensionTestsLocationURI) {
168168
return; // no restart when in tests: see https://github.com/Microsoft/vscode/issues/66936
169169
}
170+
170171
if (environmentService.configuration.remoteAuthority) {
171-
windowSevice.reloadWindow(); // TODO aeschli, workaround
172+
windowSevice.reloadWindow(); // TODO@aeschli, workaround
172173
} else {
173174
extensionService.restartExtensionHost();
174175
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,10 @@ export abstract class AbstractExtensionService extends Disposable implements IEx
170170
this._startExtensionHostProcess(false, Array.from(this._allRequestedActivateEvents.keys()));
171171
}
172172

173-
public startExtensionHost(): void {
173+
protected startExtensionHost(): void {
174174
this._startExtensionHostProcess(false, Array.from(this._allRequestedActivateEvents.keys()));
175175
}
176176

177-
public stopExtensionHost(): void {
178-
this._stopExtensionHostProcess();
179-
}
180-
181177
public activateByEvent(activationEvent: string): Promise<void> {
182178
if (this._installedExtensionsReady.isOpen()) {
183179
// Extensions have been scanned and interpreted

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,6 @@ export interface IExtensionService {
219219
*/
220220
restartExtensionHost(): void;
221221

222-
/**
223-
* Starts the extension host.
224-
*/
225-
startExtensionHost(): void;
226-
227-
/**
228-
* Stops the extension host.
229-
*/
230-
stopExtensionHost(): void;
231-
232222
/**
233223
* Modify the environment of the remote extension host
234224
* @param env New properties for the remote extension host
@@ -282,8 +272,6 @@ export class NullExtensionService implements IExtensionService {
282272
getExtensionsStatus(): { [id: string]: IExtensionsStatus; } { return Object.create(null); }
283273
getInspectPort(): number { return 0; }
284274
restartExtensionHost(): void { }
285-
startExtensionHost(): void { }
286-
stopExtensionHost(): void { }
287275
async setRemoteEnvironment(_env: { [key: string]: string | null }): Promise<void> { }
288276
canAddExtension(): boolean { return false; }
289277
canRemoveExtension(): boolean { return false; }

src/vs/workbench/services/workspace/electron-browser/workspaceEditingService.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
220220
private async doAddFolders(foldersToAdd: IWorkspaceFolderCreationData[], index?: number, donotNotifyError: boolean = false): Promise<void> {
221221
const state = this.contextService.getWorkbenchState();
222222
if (this.environmentService.configuration.remoteAuthority) {
223+
223224
// Do not allow workspace folders with scheme different than the current remote scheme
224225
const schemas = this.contextService.getWorkspace().folders.map(f => f.uri.scheme);
225226
if (schemas.length && foldersToAdd.some(f => schemas.indexOf(f.uri.scheme) === -1)) {
@@ -286,31 +287,34 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
286287
if (path && !await this.isValidTargetWorkspacePath(path)) {
287288
return;
288289
}
290+
289291
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
290292
const untitledWorkspace = await this.workspaceService.createUntitledWorkspace(folders, remoteAuthority);
291293
if (path) {
292294
await this.saveWorkspaceAs(untitledWorkspace, path);
293295
} else {
294296
path = untitledWorkspace.configPath;
295297
}
298+
296299
return this.enterWorkspace(path);
297300
}
298301

299302
async saveAndEnterWorkspace(path: URI): Promise<void> {
300303
if (!await this.isValidTargetWorkspacePath(path)) {
301304
return;
302305
}
306+
303307
const workspaceIdentifier = this.getCurrentWorkspaceIdentifier();
304308
if (!workspaceIdentifier) {
305309
return;
306310
}
311+
307312
await this.saveWorkspaceAs(workspaceIdentifier, path);
308313

309314
return this.enterWorkspace(path);
310315
}
311316

312317
async isValidTargetWorkspacePath(path: URI): Promise<boolean> {
313-
314318
const windows = await this.windowsService.getWindows();
315319

316320
// Prevent overwriting a workspace that is currently opened in another window
@@ -382,30 +386,34 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
382386
}
383387

384388
const workspace = await this.workspaceService.getWorkspaceIdentifier(path);
389+
385390
// Settings migration (only if we come from a folder workspace)
386391
if (this.contextService.getWorkbenchState() === WorkbenchState.FOLDER) {
387392
await this.migrateWorkspaceSettings(workspace);
388393
}
394+
389395
const workspaceImpl = this.contextService as WorkspaceService;
390396
await workspaceImpl.initialize(workspace);
391397

392-
// Restart extension host if first root folder changed (impact on deprecated workspace.rootPath API)
393-
// Stop the extension host first to give extensions most time to shutdown
394-
this.extensionService.stopExtensionHost();
395-
396398
const result = await this.windowService.enterWorkspace(path);
397399
if (result) {
398400
await this.migrateStorage(result.workspace);
401+
399402
// Reinitialize backup service
400403
if (this.backupFileService instanceof BackupFileService) {
401404
this.backupFileService.initialize(toBackupWorkspaceResource(result.backupPath!, this.environmentService));
402405
}
403406
}
404407

408+
// TODO@aeschli: workaround until restarting works
405409
if (this.environmentService.configuration.remoteAuthority) {
406-
this.windowService.reloadWindow(); // TODO aeschli: workaround until restarting works
407-
} else {
408-
this.extensionService.startExtensionHost();
410+
this.windowService.reloadWindow();
411+
}
412+
413+
// Restart the extension host: entering a workspace means a new location for
414+
// storage and potentially a change in the workspace.rootPath property.
415+
else {
416+
this.extensionService.restartExtensionHost();
409417
}
410418
}
411419

0 commit comments

Comments
 (0)