mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
debt - clean up some todos (#168158)
This commit is contained in:
parent
c4d4c382c2
commit
12988f1ea0
|
@ -11,7 +11,7 @@ import { isLinux } from 'vs/base/common/platform';
|
|||
import { extUriBiasedIgnorePathCase } from 'vs/base/common/resources';
|
||||
import { Promises, RimRafMode } from 'vs/base/node/pfs';
|
||||
import { IBackupMainService } from 'vs/platform/backup/electron-main/backup';
|
||||
import { ISerializedBackupWorkspaces, IEmptyWindowBackupInfo, isEmptyWindowBackupInfo, deserializeWorkspaceInfos, deserializeFolderInfos, ISerializedWorkspaceBackupInfo, ISerializedFolderBackupInfo, ISerializedEmptyWindowBackupInfo, ILegacySerializedBackupWorkspaces } from 'vs/platform/backup/node/backup';
|
||||
import { ISerializedBackupWorkspaces, IEmptyWindowBackupInfo, isEmptyWindowBackupInfo, deserializeWorkspaceInfos, deserializeFolderInfos, ISerializedWorkspaceBackupInfo, ISerializedFolderBackupInfo, ISerializedEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
|
||||
import { IStateMainService } from 'vs/platform/state/electron-main/state';
|
||||
|
@ -50,7 +50,7 @@ export class BackupMainService implements IBackupMainService {
|
|||
async initialize(): Promise<void> {
|
||||
|
||||
// read backup workspaces
|
||||
const serializedBackupWorkspaces = await this.initializeAndMigrateBackupWorkspacesMetadata();
|
||||
const serializedBackupWorkspaces = this.stateMainService.getItem<ISerializedBackupWorkspaces>(BackupMainService.backupWorkspacesMetadataStorageKey) ?? { workspaces: [], folders: [], emptyWindows: [] };
|
||||
|
||||
// validate empty workspaces backups first
|
||||
this.emptyWindows = await this.validateEmptyWorkspaces(serializedBackupWorkspaces.emptyWindows);
|
||||
|
@ -65,36 +65,6 @@ export class BackupMainService implements IBackupMainService {
|
|||
this.storeWorkspacesMetadata();
|
||||
}
|
||||
|
||||
private async initializeAndMigrateBackupWorkspacesMetadata(): Promise<ISerializedBackupWorkspaces> {
|
||||
let serializedBackupWorkspaces = this.stateMainService.getItem<ISerializedBackupWorkspaces>(BackupMainService.backupWorkspacesMetadataStorageKey);
|
||||
if (!serializedBackupWorkspaces) {
|
||||
try {
|
||||
//TODO@bpasero remove after a while
|
||||
const legacyBackupWorkspacesPath = join(this.backupHome, 'workspaces.json');
|
||||
const legacyBackupWorkspaces = await Promises.readFile(legacyBackupWorkspacesPath, 'utf8');
|
||||
|
||||
try {
|
||||
await Promises.unlink(legacyBackupWorkspacesPath);
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
const legacySerializedBackupWorkspaces = JSON.parse(legacyBackupWorkspaces) as ILegacySerializedBackupWorkspaces;
|
||||
serializedBackupWorkspaces = {
|
||||
workspaces: Array.isArray(legacySerializedBackupWorkspaces.rootURIWorkspaces) ? legacySerializedBackupWorkspaces.rootURIWorkspaces : [],
|
||||
folders: Array.isArray(legacySerializedBackupWorkspaces.folderWorkspaceInfos) ? legacySerializedBackupWorkspaces.folderWorkspaceInfos : [],
|
||||
emptyWindows: Array.isArray(legacySerializedBackupWorkspaces.emptyWorkspaceInfos) ? legacySerializedBackupWorkspaces.emptyWorkspaceInfos : [],
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
this.logService.error(`Backup: Could not migrate legacy backup workspaces metadata: ${error.toString()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return serializedBackupWorkspaces ?? { workspaces: [], folders: [], emptyWindows: [] };
|
||||
}
|
||||
|
||||
protected getWorkspaceBackups(): IWorkspaceBackupInfo[] {
|
||||
if (this.isHotExitOnExitAndWindowClose()) {
|
||||
// Only non-folder windows are restored on main process launch when
|
||||
|
|
|
@ -81,11 +81,6 @@ flakySuite('BackupMainService', () => {
|
|||
return workspace;
|
||||
}
|
||||
|
||||
function ensureEmptyWindowExists(id: string): Promise<void> {
|
||||
const backupFolder = service.toBackupPath(id);
|
||||
return createBackupFolder(backupFolder);
|
||||
}
|
||||
|
||||
async function createBackupFolder(backupFolder: string): Promise<void> {
|
||||
if (!fs.existsSync(backupFolder)) {
|
||||
fs.mkdirSync(backupFolder);
|
||||
|
@ -171,73 +166,6 @@ flakySuite('BackupMainService', () => {
|
|||
return Promises.rm(testDir);
|
||||
});
|
||||
|
||||
test('service migrates from old workspace.json', async function () {
|
||||
const legacyWorkspaceJsonPath = path.join(backupHome, 'workspaces.json');
|
||||
|
||||
// malformed file
|
||||
stateMainService.removeItem('backupWorkspaces');
|
||||
await Promises.writeFile(legacyWorkspaceJsonPath, '{ hello world');
|
||||
await service.initialize();
|
||||
assert.ok(!await Promises.exists(legacyWorkspaceJsonPath));
|
||||
assert.equal(service.getEmptyWindowBackups().length, 0);
|
||||
assert.equal(service.testGetFolderBackups().length, 0);
|
||||
assert.equal(service.testGetWorkspaceBackups().length, 0);
|
||||
|
||||
// file with empty contents (1)
|
||||
stateMainService.removeItem('backupWorkspaces');
|
||||
await Promises.writeFile(legacyWorkspaceJsonPath, '{}');
|
||||
await service.initialize();
|
||||
assert.ok(!await Promises.exists(legacyWorkspaceJsonPath));
|
||||
assert.equal(service.getEmptyWindowBackups().length, 0);
|
||||
assert.equal(service.testGetFolderBackups().length, 0);
|
||||
assert.equal(service.testGetWorkspaceBackups().length, 0);
|
||||
|
||||
// file with empty contents (2)
|
||||
stateMainService.removeItem('backupWorkspaces');
|
||||
await Promises.writeFile(legacyWorkspaceJsonPath, JSON.stringify({
|
||||
rootURIWorkspaces: [],
|
||||
folderWorkspaceInfos: [],
|
||||
emptyWorkspaceInfos: []
|
||||
}));
|
||||
await service.initialize();
|
||||
assert.ok(!await Promises.exists(legacyWorkspaceJsonPath));
|
||||
assert.equal(service.getEmptyWindowBackups().length, 0);
|
||||
assert.equal(service.testGetFolderBackups().length, 0);
|
||||
assert.equal(service.testGetWorkspaceBackups().length, 0);
|
||||
|
||||
// file with contents
|
||||
|
||||
const workspacePath = path.join(testDir, 'Foo.code-workspace');
|
||||
const workspace1 = await ensureWorkspaceExists(toWorkspace(workspacePath));
|
||||
await ensureFolderExists(existingTestFolder1);
|
||||
const emptyWindowWorkspaceId = '1662626964151';
|
||||
await ensureEmptyWindowExists(emptyWindowWorkspaceId);
|
||||
|
||||
stateMainService.removeItem('backupWorkspaces');
|
||||
await Promises.writeFile(legacyWorkspaceJsonPath, JSON.stringify({
|
||||
rootURIWorkspaces: [workspace1].map(toSerializedWorkspace),
|
||||
folderWorkspaceInfos: [{ folderUri: existingTestFolder1.toString() }],
|
||||
emptyWorkspaceInfos: [{ backupFolder: emptyWindowWorkspaceId }]
|
||||
}));
|
||||
await service.initialize();
|
||||
assert.ok(!await Promises.exists(legacyWorkspaceJsonPath));
|
||||
assert.equal(service.getEmptyWindowBackups().length, 1);
|
||||
assert.equal(service.testGetFolderBackups().length, 1);
|
||||
assert.equal(service.testGetWorkspaceBackups().length, 1);
|
||||
|
||||
// subsequent initialize ignores file
|
||||
|
||||
await Promises.writeFile(legacyWorkspaceJsonPath, JSON.stringify({
|
||||
rootURIWorkspaces: [],
|
||||
folderWorkspaceInfos: [],
|
||||
emptyWorkspaceInfos: []
|
||||
}));
|
||||
await service.initialize();
|
||||
assert.equal(service.getEmptyWindowBackups().length, 1);
|
||||
assert.equal(service.testGetFolderBackups().length, 1);
|
||||
assert.equal(service.testGetWorkspaceBackups().length, 1);
|
||||
});
|
||||
|
||||
test('service validates backup workspaces on startup and cleans up (folder workspaces)', async function () {
|
||||
|
||||
// 1) backup workspace path does not exist
|
||||
|
|
|
@ -31,7 +31,7 @@ import { IStatusbarService } from 'vs/workbench/services/statusbar/browser/statu
|
|||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { coalesce } from 'vs/base/common/arrays';
|
||||
import { assertIsDefined, isNumber } from 'vs/base/common/types';
|
||||
import { assertIsDefined } from 'vs/base/common/types';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { WINDOW_ACTIVE_BORDER, WINDOW_INACTIVE_BORDER } from 'vs/workbench/common/theme';
|
||||
|
@ -683,23 +683,11 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
|
|||
return {
|
||||
layout: defaultLayout.layout?.editors,
|
||||
filesToOpenOrCreate: defaultLayout?.editors?.map(editor => {
|
||||
// TODO@bpasero remove me eventually
|
||||
const editor2 = editor as any;
|
||||
const legacySelection = editor2.selection && editor2.selection.start && isNumber(editor2.selection.start.line) ? {
|
||||
startLineNumber: editor2.selection.start.line,
|
||||
startColumn: isNumber(editor2.selection.start.column) ? editor2.selection.start.column : 1,
|
||||
endLineNumber: isNumber(editor2.selection.end.line) ? editor2.selection.end.line : undefined,
|
||||
endColumn: isNumber(editor2.selection.end.line) ? (isNumber(editor2.selection.end.column) ? editor2.selection.end.column : 1) : undefined,
|
||||
} : undefined;
|
||||
|
||||
return {
|
||||
viewColumn: editor.viewColumn,
|
||||
fileUri: URI.revive(editor.uri),
|
||||
openOnlyIfExists: editor.openOnlyIfExists,
|
||||
options: {
|
||||
selection: legacySelection,
|
||||
...editor.options // keep at the end to override legacy selection/override that may be `undefined`
|
||||
}
|
||||
options: editor.options
|
||||
};
|
||||
})
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue