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


TypeScript resources.dirname函数代码示例

本文整理汇总了TypeScript中vs/base/common/resources.dirname函数的典型用法代码示例。如果您正苦于以下问题:TypeScript dirname函数的具体用法?TypeScript dirname怎么用?TypeScript dirname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: rewriteWorkspaceFileForNewLocation

export function rewriteWorkspaceFileForNewLocation(rawWorkspaceContents: string, configPathURI: URI, targetConfigPathURI: URI) {
	let storedWorkspace = doParseStoredWorkspace(configPathURI, rawWorkspaceContents);

	const sourceConfigFolder = dirname(configPathURI);
	const targetConfigFolder = dirname(targetConfigPathURI);

	const rewrittenFolders: IStoredWorkspaceFolder[] = [];
	const slashForPath = useSlashForPath(storedWorkspace.folders);

	// Rewrite absolute paths to relative paths if the target workspace folder
	// is a parent of the location of the workspace file itself. Otherwise keep
	// using absolute paths.
	for (const folder of storedWorkspace.folders) {
		let folderURI = isRawFileWorkspaceFolder(folder) ? resolvePath(sourceConfigFolder, folder.path) : URI.parse(folder.uri);
		rewrittenFolders.push(getStoredWorkspaceFolder(folderURI, folder.name, targetConfigFolder, slashForPath));
	}

	// Preserve as much of the existing workspace as possible by using jsonEdit
	// and only changing the folders portion.
	const formattingOptions: FormattingOptions = { insertSpaces: false, tabSize: 4, eol: (isLinux || isMacintosh) ? '\n' : '\r\n' };
	const edits = jsonEdit.setProperty(rawWorkspaceContents, ['folders'], rewrittenFolders, formattingOptions);
	let newContent = jsonEdit.applyEdits(rawWorkspaceContents, edits);

	if (storedWorkspace.remoteAuthority === getRemoteAuthority(targetConfigPathURI)) {
		// unsaved remote workspaces have the remoteAuthority set. Remove it when no longer nexessary.
		newContent = jsonEdit.applyEdits(newContent, jsonEdit.removeProperty(newContent, ['remoteAuthority'], formattingOptions));
	}
	return newContent;
}
开发者ID:PKRoma,项目名称:vscode,代码行数:29,代码来源:workspaces.ts

示例2: rewriteWorkspaceFileForNewLocation

export function rewriteWorkspaceFileForNewLocation(rawWorkspaceContents: string, configPathURI: URI, targetConfigPathURI: URI) {
	let storedWorkspace = doParseStoredWorkspace(configPathURI, rawWorkspaceContents);

	const sourceConfigFolder = dirname(configPathURI);
	const targetConfigFolder = dirname(targetConfigPathURI);

	const rewrittenFolders: IStoredWorkspaceFolder[] = [];
	const slashForPath = useSlashForPath(storedWorkspace.folders);

	// Rewrite absolute paths to relative paths if the target workspace folder
	// is a parent of the location of the workspace file itself. Otherwise keep
	// using absolute paths.
	for (const folder of storedWorkspace.folders) {
		let folderURI = isRawFileWorkspaceFolder(folder) ? resolvePath(sourceConfigFolder, folder.path) : URI.parse(folder.uri);
		rewrittenFolders.push(getStoredWorkspaceFolder(folderURI, folder.name, targetConfigFolder, slashForPath));
	}

	// Preserve as much of the existing workspace as possible by using jsonEdit
	// and only changing the folders portion.
	let newRawWorkspaceContents = rawWorkspaceContents;
	const edits = jsonEdit.setProperty(rawWorkspaceContents, ['folders'], rewrittenFolders, { insertSpaces: false, tabSize: 4, eol: (isLinux || isMacintosh) ? '\n' : '\r\n' });
	edits.forEach(edit => {
		newRawWorkspaceContents = jsonEdit.applyEdit(rawWorkspaceContents, edit);
	});
	return newRawWorkspaceContents;
}
开发者ID:joelday,项目名称:vscode,代码行数:26,代码来源:workspaces.ts

示例3: test

	test('dirname', () => {
		const f = URI.file('/some/file/test.txt');
		const d = dirname(f);
		assert.equal(d.fsPath, normalize('/some/file', true));

		// does not explode (https://github.com/Microsoft/vscode/issues/41987)
		dirname(URI.from({ scheme: 'file', authority: '/users/someone/portal.h' }));
	});
开发者ID:burhandodhy,项目名称:azuredatastudio,代码行数:8,代码来源:resources.test.ts

示例4: getIconClasses

	const folderPicks: IQuickPickItem[] = folders.map(folder => {
		return {
			label: folder.name,
			description: labelService.getUriLabel(resources.dirname(folder.uri), { relative: true }),
			folder,
			iconClasses: getIconClasses(modelService, modeService, folder.uri, FileKind.ROOT_FOLDER)
		};
	});
开发者ID:eamodio,项目名称:vscode,代码行数:8,代码来源:workspaceCommands.ts

示例5: getPathLabel

	const folderPicks = folders.map(folder => {
		return {
			label: folder.name,
			description: getPathLabel(resources.dirname(folder.uri), void 0, environmentService),
			folder,
			resource: folder.uri,
			fileKind: FileKind.ROOT_FOLDER
		} as IFilePickOpenEntry;
	});
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:9,代码来源:workspaceCommands.ts

示例6:

	const folderPicks = folders.map(folder => {
		return {
			label: folder.name,
			description: uriDisplayService.getLabel(resources.dirname(folder.uri), true),
			folder,
			resource: folder.uri,
			fileKind: FileKind.ROOT_FOLDER
		} as IFilePickOpenEntry;
	});
开发者ID:burhandodhy,项目名称:azuredatastudio,代码行数:9,代码来源:workspaceCommands.ts

示例7: test

	test('dirname', () => {
		if (isWindows) {
			assert.equal(dirname(URI.file('c:\\some\\file\\test.txt'))!.toString(), 'file:///c%3A/some/file');
			assert.equal(dirname(URI.file('c:\\some\\file'))!.toString(), 'file:///c%3A/some');
			assert.equal(dirname(URI.file('c:\\some\\file\\'))!.toString(), 'file:///c%3A/some');
			assert.equal(dirname(URI.file('c:\\some'))!.toString(), 'file:///c%3A/');
			assert.equal(dirname(URI.file('C:\\some'))!.toString(), 'file:///c%3A/');
		} else {
			assert.equal(dirname(URI.file('/some/file/test.txt'))!.toString(), 'file:///some/file');
			assert.equal(dirname(URI.file('/some/file/'))!.toString(), 'file:///some');
			assert.equal(dirname(URI.file('/some/file'))!.toString(), 'file:///some');
		}
		assert.equal(dirname(URI.parse('foo://a/some/file/test.txt'))!.toString(), 'foo://a/some/file');
		assert.equal(dirname(URI.parse('foo://a/some/file/'))!.toString(), 'foo://a/some');
		assert.equal(dirname(URI.parse('foo://a/some/file'))!.toString(), 'foo://a/some');
		assert.equal(dirname(URI.parse('foo://a/some'))!.toString(), 'foo://a/');

		// does not explode (https://github.com/Microsoft/vscode/issues/41987)
		dirname(URI.from({ scheme: 'file', authority: '/users/someone/portal.h' }));
	});
开发者ID:kumarharsh,项目名称:vscode,代码行数:20,代码来源:resources.test.ts


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