Skip to content

Commit 57c8495

Browse files
author
Benjamin Pasero
committed
cleanup workspace editing service
1 parent a1561eb commit 57c8495

7 files changed

Lines changed: 69 additions & 67 deletions

File tree

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import { URI } from 'vs/base/common/uri';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
88
import { ITextBufferFactory, ITextSnapshot } from 'vs/editor/common/model';
9-
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
10-
import { joinPath, relativePath } from 'vs/base/common/resources';
119

1210
export const IBackupFileService = createDecorator<IBackupFileService>('backupFileService');
1311

@@ -88,7 +86,3 @@ export interface IBackupFileService {
8886
*/
8987
discardAllWorkspaceBackups(): Promise<void>;
9088
}
91-
92-
export function toBackupWorkspaceResource(backupWorkspacePath: string, environmentService: IEnvironmentService): URI {
93-
return joinPath(environmentService.userRoamingDataHome, relativePath(URI.file(environmentService.userDataPath), URI.file(backupWorkspacePath))!);
94-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { URI } from 'vs/base/common/uri';
7+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
8+
import { joinPath, relativePath } from 'vs/base/common/resources';
9+
10+
export function toBackupWorkspaceResource(backupWorkspacePath: string, environmentService: IEnvironmentService): URI {
11+
return joinPath(environmentService.userRoamingDataHome, relativePath(URI.file(environmentService.userDataPath), URI.file(backupWorkspacePath))!);
12+
}

src/vs/workbench/services/environment/electron-browser/environmentService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
99
import { memoize } from 'vs/base/common/decorators';
1010
import { URI } from 'vs/base/common/uri';
1111
import { Schemas } from 'vs/base/common/network';
12-
import { toBackupWorkspaceResource } from 'vs/workbench/services/backup/common/backup';
12+
import { toBackupWorkspaceResource } from 'vs/workbench/services/backup/electron-browser/backup';
1313
import { join } from 'vs/base/common/path';
1414
import { IDebugParams } from 'vs/platform/environment/common/environment';
1515
import product from 'vs/platform/product/common/product';

src/vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService.ts

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ import { URI } from 'vs/base/common/uri';
88
import * as nls from 'vs/nls';
99
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1010
import { IJSONEditingService, JSONEditingError, JSONEditingErrorCode } from 'vs/workbench/services/configuration/common/jsonEditing';
11-
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, IWorkspacesService, rewriteWorkspaceFileForNewLocation, WORKSPACE_FILTER } from 'vs/platform/workspaces/common/workspaces';
11+
import { IWorkspaceIdentifier, IWorkspaceFolderCreationData, IWorkspacesService, rewriteWorkspaceFileForNewLocation, WORKSPACE_FILTER, IEnterWorkspaceResult } from 'vs/platform/workspaces/common/workspaces';
1212
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
13-
import { IStorageService } from 'vs/platform/storage/common/storage';
1413
import { ConfigurationScope, IConfigurationRegistry, Extensions as ConfigurationExtensions, IConfigurationPropertySchema } from 'vs/platform/configuration/common/configurationRegistry';
1514
import { Registry } from 'vs/platform/registry/common/platform';
16-
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
17-
import { IBackupFileService, toBackupWorkspaceResource } from 'vs/workbench/services/backup/common/backup';
18-
import { BackupFileService } from 'vs/workbench/services/backup/common/backupFileService';
1915
import { ICommandService } from 'vs/platform/commands/common/commands';
2016
import { distinct } from 'vs/base/common/arrays';
2117
import { isEqual, getComparisonKey } from 'vs/base/common/resources';
@@ -36,9 +32,6 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
3632
@IJSONEditingService private readonly jsonEditingService: IJSONEditingService,
3733
@IWorkspaceContextService private readonly contextService: WorkspaceService,
3834
@IConfigurationService private readonly configurationService: IConfigurationService,
39-
@IStorageService private readonly storageService: IStorageService,
40-
@IExtensionService private readonly extensionService: IExtensionService,
41-
@IBackupFileService private readonly backupFileService: IBackupFileService,
4235
@INotificationService private readonly notificationService: INotificationService,
4336
@ICommandService private readonly commandService: ICommandService,
4437
@IFileService private readonly fileService: IFileService,
@@ -267,7 +260,9 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
267260
);
268261
}
269262

270-
async enterWorkspace(path: URI): Promise<void> {
263+
abstract async enterWorkspace(path: URI): Promise<void>;
264+
265+
protected async doEnterWorkspace(path: URI): Promise<IEnterWorkspaceResult | null> {
271266
if (!!this.environmentService.extensionTestsLocationURI) {
272267
throw new Error('Entering a new workspace is not possible in tests.');
273268
}
@@ -282,34 +277,7 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
282277
const workspaceImpl = this.contextService as WorkspaceService;
283278
await workspaceImpl.initialize(workspace);
284279

285-
const result = await this.workspacesService.enterWorkspace(path);
286-
if (result) {
287-
288-
// Migrate storage to new workspace
289-
await this.migrateStorage(result.workspace);
290-
291-
// Reinitialize backup service
292-
this.environmentService.configuration.backupPath = result.backupPath;
293-
this.environmentService.configuration.backupWorkspaceResource = result.backupPath ? toBackupWorkspaceResource(result.backupPath, this.environmentService) : undefined;
294-
if (this.backupFileService instanceof BackupFileService) {
295-
this.backupFileService.reinitialize();
296-
}
297-
}
298-
299-
// TODO@aeschli: workaround until restarting works
300-
if (this.environmentService.configuration.remoteAuthority) {
301-
this.hostService.reload();
302-
}
303-
304-
// Restart the extension host: entering a workspace means a new location for
305-
// storage and potentially a change in the workspace.rootPath property.
306-
else {
307-
this.extensionService.restartExtensionHost();
308-
}
309-
}
310-
311-
private migrateStorage(toWorkspace: IWorkspaceIdentifier): Promise<void> {
312-
return this.storageService.migrate(toWorkspace);
280+
return this.workspacesService.enterWorkspace(path);
313281
}
314282

315283
private migrateWorkspaceSettings(toWorkspace: IWorkspaceIdentifier): Promise<void> {

src/vs/workbench/services/workspaces/browser/workspaceEditingService.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
77
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
8-
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
8+
import { IWorkspacesService, isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces';
99
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
10-
import { IStorageService } from 'vs/platform/storage/common/storage';
11-
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
12-
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
1310
import { ICommandService } from 'vs/platform/commands/common/commands';
1411
import { INotificationService } from 'vs/platform/notification/common/notification';
1512
import { IFileService } from 'vs/platform/files/common/files';
@@ -21,6 +18,7 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
2118
import { AbstractWorkspaceEditingService } from 'vs/workbench/services/workspaces/browser/abstractWorkspaceEditingService';
2219
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
2320
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
21+
import { URI } from 'vs/base/common/uri';
2422

2523
export class BrowserWorkspaceEditingService extends AbstractWorkspaceEditingService {
2624

@@ -30,9 +28,6 @@ export class BrowserWorkspaceEditingService extends AbstractWorkspaceEditingServ
3028
@IJSONEditingService jsonEditingService: IJSONEditingService,
3129
@IWorkspaceContextService contextService: WorkspaceService,
3230
@IConfigurationService configurationService: IConfigurationService,
33-
@IStorageService storageService: IStorageService,
34-
@IExtensionService extensionService: IExtensionService,
35-
@IBackupFileService backupFileService: IBackupFileService,
3631
@INotificationService notificationService: INotificationService,
3732
@ICommandService commandService: ICommandService,
3833
@IFileService fileService: IFileService,
@@ -43,9 +38,17 @@ export class BrowserWorkspaceEditingService extends AbstractWorkspaceEditingServ
4338
@IDialogService dialogService: IDialogService,
4439
@IHostService hostService: IHostService
4540
) {
46-
super(jsonEditingService, contextService, configurationService, storageService, extensionService, backupFileService, notificationService, commandService, fileService, textFileService, workspacesService, environmentService, fileDialogService, dialogService, hostService);
41+
super(jsonEditingService, contextService, configurationService, notificationService, commandService, fileService, textFileService, workspacesService, environmentService, fileDialogService, dialogService, hostService);
42+
}
43+
44+
async enterWorkspace(path: URI): Promise<void> {
45+
const result = await this.doEnterWorkspace(path);
46+
if (result) {
47+
48+
// Open workspace in same window
49+
await this.hostService.openWindow([{ workspaceUri: path }], { forceReuseWindow: true, noRecentEntry: isUntitledWorkspace(path, this.environmentService) });
50+
}
4751
}
4852
}
4953

5054
registerSingleton(IWorkspaceEditingService, BrowserWorkspaceEditingService, true);
51-

src/vs/workbench/services/workspaces/browser/workspacesService.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/
1212
import { ILogService } from 'vs/platform/log/common/log';
1313
import { Disposable } from 'vs/base/common/lifecycle';
1414
import { getWorkspaceIdentifier } from 'vs/workbench/services/workspaces/browser/workspaces';
15-
import { IHostService } from 'vs/workbench/services/host/browser/host';
1615
import { IFileService } from 'vs/platform/files/common/files';
1716
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1817
import { joinPath } from 'vs/base/common/resources';
@@ -31,7 +30,6 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS
3130
@IStorageService private readonly storageService: IStorageService,
3231
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
3332
@ILogService private readonly logService: ILogService,
34-
@IHostService private readonly hostService: IHostService,
3533
@IFileService private readonly fileService: IFileService,
3634
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService
3735
) {
@@ -125,13 +123,7 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS
125123
//#region Workspace Management
126124

127125
async enterWorkspace(path: URI): Promise<IEnterWorkspaceResult | null> {
128-
129-
// Open workspace in same window
130-
await this.hostService.openWindow([{ workspaceUri: path }], { forceReuseWindow: true, noRecentEntry: isUntitledWorkspace(path, this.environmentService) });
131-
132-
return {
133-
workspace: await this.getWorkspaceIdentifier(path)
134-
};
126+
return { workspace: await this.getWorkspaceIdentifier(path) };
135127
}
136128

137129
async createUntitledWorkspace(folders?: IWorkspaceFolderCreationData[], remoteAuthority?: string): Promise<IWorkspaceIdentifier> {

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { URI } from 'vs/base/common/uri';
88
import * as nls from 'vs/nls';
99
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
1010
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
11-
import { IWorkspacesService, isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces';
11+
import { IWorkspacesService, isUntitledWorkspace, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1212
import { WorkspaceService } from 'vs/workbench/services/configuration/browser/configurationService';
1313
import { IStorageService } from 'vs/platform/storage/common/storage';
1414
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
1515
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
16+
import { toBackupWorkspaceResource } from 'vs/workbench/services/backup/electron-browser/backup';
1617
import { ICommandService } from 'vs/platform/commands/common/commands';
1718
import { isEqual, basename } from 'vs/base/common/resources';
1819
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
@@ -29,6 +30,7 @@ import { AbstractWorkspaceEditingService } from 'vs/workbench/services/workspace
2930
import { IElectronService } from 'vs/platform/electron/node/electron';
3031
import { isMacintosh, isWindows, isLinux } from 'vs/base/common/platform';
3132
import { mnemonicButtonLabel } from 'vs/base/common/labels';
33+
import { BackupFileService } from 'vs/workbench/services/backup/common/backupFileService';
3234

3335
export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingService {
3436

@@ -39,9 +41,9 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
3941
@IWorkspaceContextService contextService: WorkspaceService,
4042
@IElectronService private electronService: IElectronService,
4143
@IConfigurationService configurationService: IConfigurationService,
42-
@IStorageService storageService: IStorageService,
43-
@IExtensionService extensionService: IExtensionService,
44-
@IBackupFileService backupFileService: IBackupFileService,
44+
@IStorageService private storageService: IStorageService,
45+
@IExtensionService private extensionService: IExtensionService,
46+
@IBackupFileService private backupFileService: IBackupFileService,
4547
@INotificationService notificationService: INotificationService,
4648
@ICommandService commandService: ICommandService,
4749
@IFileService fileService: IFileService,
@@ -54,7 +56,7 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
5456
@ILabelService private readonly labelService: ILabelService,
5557
@IHostService hostService: IHostService,
5658
) {
57-
super(jsonEditingService, contextService, configurationService, storageService, extensionService, backupFileService, notificationService, commandService, fileService, textFileService, workspacesService, environmentService, fileDialogService, dialogService, hostService);
59+
super(jsonEditingService, contextService, configurationService, notificationService, commandService, fileService, textFileService, workspacesService, environmentService, fileDialogService, dialogService, hostService);
5860

5961
this.registerListeners();
6062
}
@@ -165,6 +167,37 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
165167

166168
return true; // OK
167169
}
170+
171+
async enterWorkspace(path: URI): Promise<void> {
172+
const result = await this.doEnterWorkspace(path);
173+
if (result) {
174+
175+
// Migrate storage to new workspace
176+
await this.migrateStorage(result.workspace);
177+
178+
// Reinitialize backup service
179+
this.environmentService.configuration.backupPath = result.backupPath;
180+
this.environmentService.configuration.backupWorkspaceResource = result.backupPath ? toBackupWorkspaceResource(result.backupPath, this.environmentService) : undefined;
181+
if (this.backupFileService instanceof BackupFileService) {
182+
this.backupFileService.reinitialize();
183+
}
184+
}
185+
186+
// TODO@aeschli: workaround until restarting works
187+
if (this.environmentService.configuration.remoteAuthority) {
188+
this.hostService.reload();
189+
}
190+
191+
// Restart the extension host: entering a workspace means a new location for
192+
// storage and potentially a change in the workspace.rootPath property.
193+
else {
194+
this.extensionService.restartExtensionHost();
195+
}
196+
}
197+
198+
private migrateStorage(toWorkspace: IWorkspaceIdentifier): Promise<void> {
199+
return this.storageService.migrate(toWorkspace);
200+
}
168201
}
169202

170203
registerSingleton(IWorkspaceEditingService, NativeWorkspaceEditingService, true);

0 commit comments

Comments
 (0)