Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable backups when extensions are being debugged #15593

Merged
merged 3 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/vs/code/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,9 @@ export class WindowsManager implements IWindowsMainService {
let configuration: IWindowConfiguration;
let openInNewWindow = openConfig.preferNewWindow || openConfig.forceNewWindow;

// Restore any existing backup workspaces on the first initial startup
if (openConfig.initialStartup) {
// Restore any existing backup workspaces on the first initial startup, provided an
// extension development path is not being launch.
if (openConfig.initialStartup && !this.environmentService.isExtensionDevelopment) {
const workspacesWithBackups = this.backupService.getWorkspaceBackupPaths();
workspacesWithBackups.forEach(workspacePath => {
if (!fs.existsSync(workspacePath)) {
Expand All @@ -380,7 +381,7 @@ export class WindowsManager implements IWindowsMainService {
openFilesInNewWindow = true;
} else {
openFilesInNewWindow = openConfig.preferNewWindow;
if (openFilesInNewWindow && !openConfig.cli.extensionDevelopmentPath) { // can be overriden via settings (not for PDE though!)
if (openFilesInNewWindow && !this.environmentService.isExtensionDevelopment) { // can be overriden via settings (not for PDE though!)
const windowConfig = this.configurationService.getConfiguration<IWindowSettings>('window');
if (windowConfig && !windowConfig.openFilesInNewWindow) {
openFilesInNewWindow = false; // do not open in new window if user configured this explicitly
Expand Down Expand Up @@ -479,7 +480,9 @@ export class WindowsManager implements IWindowsMainService {
}

// Register new paths for backup
this.backupService.pushWorkspaceBackupPathsSync(iPathsToOpen.filter(p => p.workspacePath).map(p => Uri.file(p.workspacePath)));
if (!this.environmentService.isExtensionDevelopment) {
this.backupService.pushWorkspaceBackupPathsSync(iPathsToOpen.filter(p => p.workspacePath).map(p => Uri.file(p.workspacePath)));
}

// Emit events
iPathsToOpen.forEach(iPath => this._onPathOpen.fire(iPath));
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface IEnvironmentService {
backupHome: string;
backupWorkspacesPath: string;

isExtensionDevelopment: boolean;
disableExtensions: boolean;
extensionsPath: string;
extensionDevelopmentPath: string;
Expand Down
3 changes: 3 additions & 0 deletions src/vs/platform/environment/node/environmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class EnvironmentService implements IEnvironmentService {
@memoize
get appKeybindingsPath(): string { return path.join(this.appSettingsHome, 'keybindings.json'); }

@memoize
get isExtensionDevelopment(): boolean { return !!this._args.extensionDevelopmentPath; }

@memoize
get backupHome(): string { return path.join(this.userDataPath, 'Backups'); }

Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/parts/backup/common/backupModelTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ITextFileService, TextFileModelChangeEvent } from 'vs/workbench/service
import { IFileService } from 'vs/platform/files/common/files';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';

export class BackupModelTracker implements IWorkbenchContribution {
Expand All @@ -26,14 +27,19 @@ export class BackupModelTracker implements IWorkbenchContribution {
@IFileService private fileService: IFileService,
@ITextFileService private textFileService: ITextFileService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
this.toDispose = [];

this.registerListeners();
}

private registerListeners() {
if (this.environmentService.isExtensionDevelopment) {
return;
}

// Listen for text file model changes
this.toDispose.push(this.textFileService.models.onModelContentChanged((e) => this.onTextFileModelChanged(e)));
this.toDispose.push(this.textFileService.models.onModelSaved((e) => this.discardBackup(e.resource)));
Expand Down
20 changes: 18 additions & 2 deletions src/vs/workbench/services/backup/node/backupFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ export class BackupFileService implements IBackupFileService {

constructor(
private currentWorkspace: Uri,
@IEnvironmentService environmentService: IEnvironmentService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService
) {
this.backupHome = environmentService.backupHome;
this.workspacesJsonPath = environmentService.backupWorkspacesPath;
}

public getWorkspaceBackupPaths(): TPromise<string[]> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as([]);
}

return this.loadWorkspaces().then(workspacesJsonContent => {
return workspacesJsonContent.folderWorkspaces;
});
Expand All @@ -47,7 +51,7 @@ export class BackupFileService implements IBackupFileService {

public getBackupResource(resource: Uri): Uri {
// Hot exit is disabled for empty workspaces
if (!this.currentWorkspace) {
if (!this.currentWorkspace || this.environmentService.isExtensionDevelopment) {
return null;
}

Expand All @@ -63,6 +67,10 @@ export class BackupFileService implements IBackupFileService {
}

public backupResource(resource: Uri, content: string): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}

const backupResource = this.getBackupResource(resource);

// Hot exit is disabled for empty workspaces
Expand All @@ -74,6 +82,10 @@ export class BackupFileService implements IBackupFileService {
}

public discardResourceBackup(resource: Uri): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}

const backupResource = this.getBackupResource(resource);

// Hot exit is disabled for empty workspaces
Expand All @@ -85,6 +97,10 @@ export class BackupFileService implements IBackupFileService {
}

public discardAllWorkspaceBackups(): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}

return this.fileService.del(Uri.file(this.getWorkspaceBackupDirectory()));
}

Expand Down
16 changes: 13 additions & 3 deletions src/vs/workbench/services/backup/node/backupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IFileService, IFilesConfiguration } from 'vs/platform/files/common/file
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { TPromise } from 'vs/base/common/winjs.base';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';

export class BackupService implements IBackupService {

Expand All @@ -34,7 +35,8 @@ export class BackupService implements IBackupService {
@IConfigurationService private configurationService: IConfigurationService,
@IFileService private fileService: IFileService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
this.toDispose = [];
this.backupPromises = [];
Expand Down Expand Up @@ -123,10 +125,14 @@ export class BackupService implements IBackupService {
public get isHotExitEnabled(): boolean {
// If hot exit is enabled then save the dirty files in the workspace and then exit
// Hot exit is currently disabled for empty workspaces (#13733).
return this.configuredHotExit && !!this.contextService.getWorkspace();
return !this.environmentService.isExtensionDevelopment && this.configuredHotExit && !!this.contextService.getWorkspace();
}

public backupBeforeShutdown(dirtyToBackup: Uri[], textFileEditorModelManager: ITextFileEditorModelManager, quitRequested: boolean): TPromise<IBackupResult> {
if (!this.isHotExitEnabled) {
return TPromise.as({ didBackup: false });
}

return this.backupFileService.getWorkspaceBackupPaths().then(workspaceBackupPaths => {
// When quit is requested skip the confirm callback and attempt to backup all workspaces.
// When quit is not requested the confirm callback should be shown when the window being
Expand All @@ -142,9 +148,13 @@ export class BackupService implements IBackupService {
}

public cleanupBackupsBeforeShutdown(): TPromise<void> {
if (this.environmentService.isExtensionDevelopment) {
return TPromise.as(void 0);
}

const workspace = this.contextService.getWorkspace();
if (!workspace) {
return TPromise.as(null); // no backups to cleanup
return TPromise.as(void 0); // no backups to cleanup
}

return this.backupFileService.discardAllWorkspaceBackups();
Expand Down