workspace - more tests for identifiers

This commit is contained in:
Benjamin Pasero
2021-01-22 11:55:06 +01:00
parent 05bf7b0afc
commit 4c0a4179e6
5 changed files with 73 additions and 25 deletions
@@ -829,12 +829,18 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
return undefined;
}
// handle local files in `parsePath` with some extra validation
// handle local openables with some extra validation
let uri = this.resourceFromURIToOpen(toOpen);
if (uri.scheme === Schemas.file) {
return this.resolvePath(uri.fsPath, options, isFileToOpen(toOpen));
}
// handle remote openables
return this.resolveRemoteUri(uri, toOpen, options);
}
private resolveRemoteUri(uri: URI, toOpen: IWindowOpenable, options: IPathParseOptions = {}): IPathToOpen | undefined {
// open remote if either specified in the cli or if it's a remotehost URI
const remoteAuthority = options.remoteAuthority || getRemoteAuthority(uri);
@@ -844,7 +850,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
// remove trailing slash
uri = removeTrailingPathSeparator(uri);
// File
// Remote File
if (isFileToOpen(toOpen)) {
if (options.gotoLineMode) {
const { path, line, column } = parseLineAndColumnAware(uri.path);
@@ -857,25 +863,16 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
};
}
return {
fileUri: uri,
remoteAuthority
};
return { fileUri: uri, remoteAuthority };
}
// Workspace
// Remote Workspace
else if (isWorkspaceToOpen(toOpen)) {
return {
workspace: getWorkspaceIdentifier(uri),
remoteAuthority
};
return { workspace: getWorkspaceIdentifier(uri), remoteAuthority };
}
// Folder
return {
workspace: getSingleFolderWorkspaceIdentifier(uri),
remoteAuthority
};
// Remote Folder
return { workspace: getSingleFolderWorkspaceIdentifier(uri), remoteAuthority };
}
private resourceFromURIToOpen(openable: IWindowOpenable): URI {
@@ -984,10 +981,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
// are neither file nor folder but some external tools might pass them
// over to us)
else if (pathStat.isDirectory()) {
return {
workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat),
exists: true
};
return { workspace: getSingleFolderWorkspaceIdentifier(URI.file(path), pathStat), exists: true };
}
} catch (error) {
const fileUri = URI.file(path);
@@ -997,10 +991,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
// assume this is a file that does not yet exist
if (options?.ignoreFileNotFound) {
return {
fileUri,
exists: false
};
return { fileUri, exists: false };
}
}
@@ -320,6 +320,10 @@ export class WorkspacesMainService extends Disposable implements IWorkspacesMain
}
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT CHANGE. IDENTIFIERS HAVE TO REMAIN STABLE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export function getWorkspaceIdentifier(configPath: URI): IWorkspaceIdentifier {
function getWorkspaceId(): string {
@@ -337,6 +341,12 @@ export function getWorkspaceIdentifier(configPath: URI): IWorkspaceIdentifier {
};
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT CHANGE. IDENTIFIERS HAVE TO REMAIN STABLE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export function getSingleFolderWorkspaceIdentifier(folderUri: URI): ISingleFolderWorkspaceIdentifier | undefined;
export function getSingleFolderWorkspaceIdentifier(folderUri: URI, folderStat: Stats): ISingleFolderWorkspaceIdentifier;
export function getSingleFolderWorkspaceIdentifier(folderUri: URI, folderStat?: Stats): ISingleFolderWorkspaceIdentifier | undefined {
function getFolderId(): string | undefined {
@@ -10,7 +10,7 @@ import * as path from 'vs/base/common/path';
import * as pfs from 'vs/base/node/pfs';
import { EnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { parseArgs, OPTIONS } from 'vs/platform/environment/node/argv';
import { WorkspacesMainService, IStoredWorkspace, getSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/electron-main/workspacesMainService';
import { WorkspacesMainService, IStoredWorkspace, getSingleFolderWorkspaceIdentifier, getWorkspaceIdentifier } from 'vs/platform/workspaces/electron-main/workspacesMainService';
import { WORKSPACE_EXTENSION, IRawFileWorkspaceFolder, IWorkspaceFolderCreationData, IRawUriWorkspaceFolder, rewriteWorkspaceFileForNewLocation, IWorkspaceIdentifier, IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
import { NullLogService } from 'vs/platform/log/common/log';
import { URI } from 'vs/base/common/uri';
@@ -464,4 +464,24 @@ suite('WorkspacesMainService', () => {
const localExistingUriId = getSingleFolderWorkspaceIdentifier(localExistingUri);
assert.ok(localExistingUriId?.id);
});
test('workspace identifiers are stable', function () {
// workspace identifier (local)
assert.strictEqual(getWorkspaceIdentifier(URI.file('/hello/test')).id, 'e36736311be12ff6d695feefe415b3e8');
// single folder identifier (local)
const fakeStat = {
ino: 1611312115129,
birthtimeMs: 1611312115129,
birthtime: new Date(1611312115129)
};
assert.strictEqual(getSingleFolderWorkspaceIdentifier(URI.file('/hello/test'), fakeStat as fs.Stats)?.id, '1d726b3d516dc2a6d343abf4797eaaef');
// workspace identifier (remote)
assert.strictEqual(getWorkspaceIdentifier(URI.parse('vscode-remote:/hello/test')).id, '786de4f224d57691f218dc7f31ee2ee3');
// single folder identifier (remote)
assert.strictEqual(getSingleFolderWorkspaceIdentifier(URI.parse('vscode-remote:/hello/test'))?.id, '786de4f224d57691f218dc7f31ee2ee3');
});
});
@@ -7,6 +7,10 @@ import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platf
import { URI } from 'vs/base/common/uri';
import { hash } from 'vs/base/common/hash';
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT CHANGE. IDENTIFIERS HAVE TO REMAIN STABLE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export function getWorkspaceIdentifier(workspacePath: URI): IWorkspaceIdentifier {
return {
id: getWorkspaceId(workspacePath),
@@ -14,6 +18,10 @@ export function getWorkspaceIdentifier(workspacePath: URI): IWorkspaceIdentifier
};
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// NOTE: DO NOT CHANGE. IDENTIFIERS HAVE TO REMAIN STABLE
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
export function getSingleFolderWorkspaceIdentifier(folderPath: URI): ISingleFolderWorkspaceIdentifier {
return {
id: getWorkspaceId(folderPath),
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { getWorkspaceIdentifier, getSingleFolderWorkspaceIdentifier } from 'vs/workbench/services/workspaces/browser/workspaces';
suite('Workspaces', () => {
test('workspace identifiers are stable', function () {
// workspace identifier
assert.strictEqual(getWorkspaceIdentifier(URI.parse('vscode-remote:/hello/test')).id, '474434e4');
// single folder identifier
assert.strictEqual(getSingleFolderWorkspaceIdentifier(URI.parse('vscode-remote:/hello/test'))?.id, '474434e4');
});
});