當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript paths.dirname函數代碼示例

本文整理匯總了TypeScript中vs/base/common/paths.dirname函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dirname函數的具體用法?TypeScript dirname怎麽用?TypeScript dirname使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了dirname函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: dirname

export function dirname(resource: URI): URI | null {
	if (resource.scheme === Schemas.file) {
		return URI.file(paths.dirname(fsPath(resource)));
	}
	let dirname = paths.dirname(resource.path, '/');
	if (resource.authority && dirname.length && dirname.charCodeAt(0) !== CharCode.Slash) {
		return null; // If a URI contains an authority component, then the path component must either be empty or begin with a CharCode.Slash ("/") character
	}
	return resource.with({
		path: dirname
	});
}
開發者ID:felipecaputo,項目名稱:vscode,代碼行數:12,代碼來源:resources.ts

示例2: resolve

	resolve(variable: Variable): string {

		const { name } = variable;

		if (name === 'TM_FILENAME') {
			return basename(this._model.uri.fsPath);

		} else if (name === 'TM_FILENAME_BASE') {
			const name = basename(this._model.uri.fsPath);
			const idx = name.lastIndexOf('.');
			if (idx <= 0) {
				return name;
			} else {
				return name.slice(0, idx);
			}

		} else if (name === 'TM_DIRECTORY') {
			const dir = dirname(this._model.uri.fsPath);
			return dir !== '.' ? dir : '';

		} else if (name === 'TM_FILEPATH') {
			return this._model.uri.fsPath;
		}

		return undefined;
	}
開發者ID:servicesgpr,項目名稱:vscode,代碼行數:26,代碼來源:snippetVariables.ts

示例3: resolve

	resolve(name: string): string {
		if (name === 'SELECTION' || name === 'TM_SELECTED_TEXT') {
			return this._model.getValueInRange(this._selection);

		} else if (name === 'TM_CURRENT_LINE') {
			return this._model.getLineContent(this._selection.positionLineNumber);

		} else if (name === 'TM_CURRENT_WORD') {
			const info = this._model.getWordAtPosition({
				lineNumber: this._selection.positionLineNumber,
				column: this._selection.positionColumn
			});
			return info ? info.word : '';

		} else if (name === 'TM_LINE_INDEX') {
			return String(this._selection.positionLineNumber - 1);

		} else if (name === 'TM_LINE_NUMBER') {
			return String(this._selection.positionLineNumber);

		} else if (name === 'TM_FILENAME') {
			return basename(this._model.uri.fsPath);

		} else if (name === 'TM_DIRECTORY') {
			const dir = dirname(this._model.uri.fsPath);
			return dir !== '.' ? dir : '';

		} else if (name === 'TM_FILEPATH') {
			return this._model.uri.fsPath;

		} else {
			return undefined;
		}
	}
開發者ID:hungys,項目名稱:vscode,代碼行數:34,代碼來源:snippetVariables.ts

示例4: assertDirname

	function assertDirname(path: string, expected: string, win = false) {
		const actual = paths.dirname(path, win ? '\\' : '/');

		if (actual !== expected) {
			assert.fail(`${path}: expected: ${expected}, ours: ${actual}`);
		}
	}
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:7,代碼來源:paths.test.ts

示例5: save

export function save(file: string, content: string): any {
	mkdirp(dirname(file)).then(() => {
		return writeFile(file, content, 'ascii');
	}, err => {
		//
	});
}
開發者ID:AjuanM,項目名稱:vscode,代碼行數:7,代碼來源:fileAccessor.ts

示例6: createPath

export function createPath(parent: string, fileName: string): string {
	var stat = fs.statSync(parent);
	if (stat && !stat.isDirectory()) {
		parent = dirname(parent);
	}

	return join(parent, fileName);
};
開發者ID:AjuanM,項目名稱:vscode,代碼行數:8,代碼來源:fileAccessor.ts

示例7: defaultWorkspacePath

export function defaultWorkspacePath(contextService: IWorkspaceContextService, historyService: IHistoryService, environmentService: IEnvironmentService): string {

	// Check for current workspace config file first...
	if (contextService.getWorkbenchState() === WorkbenchState.WORKSPACE && !isUntitledWorkspace(contextService.getWorkspace().configuration.fsPath, environmentService)) {
		return dirname(contextService.getWorkspace().configuration.fsPath);
	}

	// ...then fallback to default folder path
	return defaultFolderPath(contextService, historyService);
}
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:10,代碼來源:workspaceCommands.ts

示例8: dirname

export function dirname(resource: uri): uri {
	const dirname = paths.dirname(resource.path);
	if (resource.authority && dirname && !paths.isAbsolute(dirname)) {
		return null; // If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character
	}

	return resource.with({
		path: dirname
	});
}
開發者ID:jinlongchen2018,項目名稱:vscode,代碼行數:10,代碼來源:resources.ts

示例9: defaultFilePath

export function defaultFilePath(contextService: IWorkspaceContextService, historyService: IHistoryService): string {
	let candidate: URI;

	// Check for last active file first...
	candidate = historyService.getLastActiveFile();

	// ...then for last active file root
	if (!candidate) {
		candidate = historyService.getLastActiveWorkspaceRoot('file');
	}

	return candidate ? dirname(candidate.fsPath) : void 0;
}
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:13,代碼來源:workspaceCommands.ts

示例10:

	handler: (accessor) => {
		const historyService = accessor.get(IHistoryService);
		const terminalService = accessor.get(ITerminalService);
		const root = historyService.getLastActiveWorkspaceRoot(Schemas.file);
		if (root) {
			terminalService.openTerminal(root.fsPath);
		} else {
			// Opens current file's folder, if no folder is open in editor
			const activeFile = historyService.getLastActiveFile();
			if (activeFile) {
				terminalService.openTerminal(paths.dirname(activeFile.fsPath));
			}
		}
	}
開發者ID:liunian,項目名稱:vscode,代碼行數:14,代碼來源:execution.contribution.ts


注:本文中的vs/base/common/paths.dirname函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。