当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript URI.from方法代码示例

本文整理汇总了TypeScript中vs/base/common/uri.URI.from方法的典型用法代码示例。如果您正苦于以下问题:TypeScript URI.from方法的具体用法?TypeScript URI.from怎么用?TypeScript URI.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vs/base/common/uri.URI的用法示例。


在下文中一共展示了URI.from方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

	test('Parse Storage (mixed)', () => {

		// Fill the storage with multiple workspaces of all kinds (empty, root, folders)
		const workspaceIds = [

			// Multi Root Workspace
			URI.from({ path: '1500007676869', scheme: 'root' }).toString(),
			URI.from({ path: '2500007676869', scheme: 'root' }).toString(),
			URI.from({ path: '3500007676869', scheme: 'root' }).toString(),

			// Empty Workspace
			URI.from({ path: '4500007676869', scheme: 'empty' }).toString(),
			URI.from({ path: '5500007676869', scheme: 'empty' }).toString(),
			URI.from({ path: '6500007676869', scheme: 'empty' }).toString(),

			// Unix Paths
			URI.file('/some/folder/folder1').toString(),
			URI.file('/some/folder/folder2').toString(),
			URI.file('/some/folder/folder3').toString(),
			URI.file('/some/folder/folder1/sub1').toString(),
			URI.file('/some/folder/folder2/sub2').toString(),
			URI.file('/some/folder/folder3/sub3').toString(),

			// Windows Paths
			URI.file('c:\\some\\folder\\folder1').toString(),
			URI.file('c:\\some\\folder\\folder2').toString(),
			URI.file('c:\\some\\folder\\folder3').toString(),
			URI.file('c:\\some\\folder\\folder1\\sub1').toString(),
			URI.file('c:\\some\\folder\\folder2\\sub2').toString(),
			URI.file('c:\\some\\folder\\folder3\\sub3').toString(),

			// UNC Paths
			'file://localhost/c%3A/some/folder/folder1',
			'file://localhost/c%3A/some/folder/folder2',
			'file://localhost/c%3A/some/folder/folder3',
			'file://localhost/c%3A/some/folder/folder1/sub1',
			'file://localhost/c%3A/some/folder/folder2/sub2',
			'file://localhost/c%3A/some/folder/folder3/sub3'
		];

		const services = workspaceIds.map(id => createService(id));

		services.forEach((service, index) => {
			let expectedKeyCount = 4;
			let storageToTest;

			const workspaceId = workspaceIds[index];
			if (startsWith(workspaceId, 'file:')) {
				storageToTest = parseFolderStorage(storage, workspaceId);
				expectedKeyCount++; // workspaceIdentifier gets added!
			} else if (startsWith(workspaceId, 'empty:')) {
				storageToTest = parseEmptyStorage(storage, workspaceId);
			} else if (startsWith(workspaceId, 'root:')) {
				storageToTest = parseMultiRootStorage(storage, workspaceId);
			}

			assert.equal(Object.keys(storageToTest).length, expectedKeyCount, 's');
			assert.equal(storageToTest['key1'], service.get('key1', StorageLegacyScope.WORKSPACE));
			assert.equal(storageToTest['key2.something'], service.get('key2.something', StorageLegacyScope.WORKSPACE));
			assert.equal(storageToTest['key3/special'], service.get('key3/special', StorageLegacyScope.WORKSPACE));
			assert.equal(storageToTest['key4 space'], service.get('key4 space', StorageLegacyScope.WORKSPACE));
		});
	});
开发者ID:,项目名称:,代码行数:63,代码来源:

示例2: getRandomTestPath

import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
import { Workspace, toWorkspaceFolders } from 'vs/platform/workspace/common/workspace';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { DefaultEndOfLine } from 'vs/editor/common/model';
import { snapshotToString } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';

const parentDir = getRandomTestPath(os.tmpdir(), 'vsctests', 'backupfileservice');
const backupHome = path.join(parentDir, 'Backups');
const workspacesJsonPath = path.join(backupHome, 'workspaces.json');

const workspaceResource = Uri.file(platform.isWindows ? 'c:\\workspace' : '/workspace');
const workspaceBackupPath = path.join(backupHome, crypto.createHash('md5').update(workspaceResource.fsPath).digest('hex'));
const fooFile = Uri.file(platform.isWindows ? 'c:\\Foo' : '/Foo');
const barFile = Uri.file(platform.isWindows ? 'c:\\Bar' : '/Bar');
const untitledFile = Uri.from({ scheme: Schemas.untitled, path: 'Untitled-1' });
const fooBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(fooFile.fsPath).digest('hex'));
const barBackupPath = path.join(workspaceBackupPath, 'file', crypto.createHash('md5').update(barFile.fsPath).digest('hex'));
const untitledBackupPath = path.join(workspaceBackupPath, 'untitled', crypto.createHash('md5').update(untitledFile.fsPath).digest('hex'));

class TestBackupFileService extends BackupFileService {
	constructor(workspace: Uri, backupHome: string, workspacesJsonPath: string) {
		const fileService = new FileService(new TestContextService(new Workspace(workspace.fsPath, toWorkspaceFolders([{ path: workspace.fsPath }]))), TestEnvironmentService, new TestTextResourceConfigurationService(), new TestConfigurationService(), new TestLifecycleService(), new TestStorageService(), new TestNotificationService(), { disableWatcher: true });

		super(workspaceBackupPath, fileService);
	}

	public toBackupResource(resource: Uri): Uri {
		return super.toBackupResource(resource);
	}
}
开发者ID:VishalMadhvani,项目名称:vscode,代码行数:31,代码来源:backupFileService.test.ts

示例3: parseStorage

export function parseStorage(storage: IStorage): IParsedStorage {
	const globalStorage = new Map<string, string>();
	const folderWorkspacesStorage = new Map<string /* workspace file resource */, StorageObject>();
	const emptyWorkspacesStorage = new Map<string /* empty workspace id */, StorageObject>();
	const multiRootWorkspacesStorage = new Map<string /* multi root workspace id */, StorageObject>();

	const workspaces: { prefix: string; resource: string; }[] = [];
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// Workspace Storage (storage://workspace/)
		if (startsWith(key, StorageService.WORKSPACE_PREFIX)) {

			// We are looking for key: storage://workspace/<folder>/workspaceIdentifier to be able to find all folder
			// paths that are known to the storage. is the only way how to parse all folder paths known in storage.
			if (endsWith(key, StorageService.WORKSPACE_IDENTIFIER)) {

				// storage://workspace/<folder>/workspaceIdentifier => <folder>/
				let workspace = key.substring(StorageService.WORKSPACE_PREFIX.length, key.length - StorageService.WORKSPACE_IDENTIFIER.length);

				// macOS/Unix: Users/name/folder/
				//    Windows: c%3A/Users/name/folder/
				if (!startsWith(workspace, 'file:')) {
					workspace = `file:///${rtrim(workspace, '/')}`;
				}

				// Windows UNC path: file://localhost/c%3A/Users/name/folder/
				else {
					workspace = rtrim(workspace, '/');
				}

				// storage://workspace/<folder>/workspaceIdentifier => storage://workspace/<folder>/
				const prefix = key.substr(0, key.length - StorageService.WORKSPACE_IDENTIFIER.length);
				workspaces.push({ prefix, resource: workspace });
			}

			// Empty workspace key: storage://workspace/empty:<id>/<key>
			else if (startsWith(key, EMPTY_WORKSPACE_PREFIX)) {

				// storage://workspace/empty:<id>/<key> => <id>
				const emptyWorkspaceId = key.substring(EMPTY_WORKSPACE_PREFIX.length, key.indexOf('/', EMPTY_WORKSPACE_PREFIX.length));
				const emptyWorkspaceResource = URI.from({ path: emptyWorkspaceId, scheme: 'empty' }).toString();

				let emptyWorkspaceStorage = emptyWorkspacesStorage.get(emptyWorkspaceResource);
				if (!emptyWorkspaceStorage) {
					emptyWorkspaceStorage = Object.create(null);
					emptyWorkspacesStorage.set(emptyWorkspaceResource, emptyWorkspaceStorage);
				}

				// storage://workspace/empty:<id>/someKey => someKey
				const storageKey = key.substr(EMPTY_WORKSPACE_PREFIX.length + emptyWorkspaceId.length + 1 /* trailing / */);

				emptyWorkspaceStorage[storageKey] = storage.getItem(key);
			}

			// Multi root workspace key: storage://workspace/root:<id>/<key>
			else if (startsWith(key, MULTI_ROOT_WORKSPACE_PREFIX)) {

				// storage://workspace/root:<id>/<key> => <id>
				const multiRootWorkspaceId = key.substring(MULTI_ROOT_WORKSPACE_PREFIX.length, key.indexOf('/', MULTI_ROOT_WORKSPACE_PREFIX.length));
				const multiRootWorkspaceResource = URI.from({ path: multiRootWorkspaceId, scheme: 'root' }).toString();

				let multiRootWorkspaceStorage = multiRootWorkspacesStorage.get(multiRootWorkspaceResource);
				if (!multiRootWorkspaceStorage) {
					multiRootWorkspaceStorage = Object.create(null);
					multiRootWorkspacesStorage.set(multiRootWorkspaceResource, multiRootWorkspaceStorage);
				}

				// storage://workspace/root:<id>/someKey => someKey
				const storageKey = key.substr(MULTI_ROOT_WORKSPACE_PREFIX.length + multiRootWorkspaceId.length + 1 /* trailing / */);

				multiRootWorkspaceStorage[storageKey] = storage.getItem(key);
			}
		}

		// Global Storage (storage://global)
		else if (startsWith(key, StorageService.GLOBAL_PREFIX)) {

			// storage://global/someKey => someKey
			const globalStorageKey = key.substr(StorageService.GLOBAL_PREFIX.length);
			if (startsWith(globalStorageKey, StorageService.COMMON_PREFIX)) {
				continue; // filter out faulty keys that have the form storage://something/storage://
			}

			globalStorage.set(globalStorageKey, storage.getItem(key));
		}
	}

	// With all the folder paths known we can now extract storage for each path. We have to go through all workspaces
	// from the longest path first to reliably extract the storage. The reason is that one folder path can be a parent
	// of another folder path and as such a simple indexOf check is not enough.
	const workspacesByLength = workspaces.sort((w1, w2) => w1.prefix.length >= w2.prefix.length ? -1 : 1);
	const handledKeys = new Map<string, boolean>();
	workspacesByLength.forEach(workspace => {
		for (let i = 0; i < storage.length; i++) {
			const key = storage.key(i);

			if (handledKeys.has(key) || !startsWith(key, workspace.prefix)) {
				continue; // not part of workspace prefix or already handled
			}
//.........这里部分代码省略.........
开发者ID:ramesius,项目名称:vscode,代码行数:101,代码来源:migration.ts


注:本文中的vs/base/common/uri.URI.from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。