11// 负责各种的文件相关信息;
22// 所有输出路径都必须视情况在对应情境中考虑 **转义**。
33
4- export { Uris2Paths , getWorkspacePaths , isFile , normalizePaths } ;
54
65import * as vscode from "vscode" ;
76
87/** 获取当前工作区路径:以数组形式返回。 */
9- function getWorkspacePaths ( ) : string [ ] {
8+ export function getWorkspacePaths ( ) : string [ ] {
109 const workspacePaths : string [ ] = [ ] ;
1110 if ( vscode . workspace . workspaceFolders ) {
1211 for ( const workspaceFolder of vscode . workspace . workspaceFolders ) {
@@ -21,7 +20,7 @@ function getWorkspacePaths(): string[] {
2120 * @param uris 所有要处理的文件/文件夹的 URI 数组
2221 * @returns 要处理的文件/文件夹的路径,转义后的数组
2322 */
24- function Uris2Paths ( uris : vscode . Uri [ ] ) : string [ ] {
23+ export function Uris2Paths ( uris : vscode . Uri [ ] ) : string [ ] {
2524 return uris // 让父目录永远排在子目录/文件前面。这样删除的时候,父目录会先被删除,子目录/文件后被删除。便于恢复。
2625 . map ( ( f ) => f . fsPath )
2726 . sort ( ( a , b ) => {
@@ -37,14 +36,14 @@ function Uris2Paths(uris: vscode.Uri[]): string[] {
3736}
3837
3938/** 判断给定的path是文件还是目录*/
40- function isFile ( path : string ) : boolean {
39+ export function isFile ( path : string ) : boolean {
4140 // 不能使用 fsUtils.isFile(path) 因为这些文件已经被删除到回收站了
4241 const hasExtension = / \. [ ^ / \. ] + $ / . test ( path ) ;
4342 const endsWithSlash = path . endsWith ( "/" ) || path . endsWith ( "\\" ) ;
4443 return hasExtension && ! endsWithSlash ;
4544}
4645
4746/**去掉首尾空格与换行符以及移除空字符串 */
48- function normalizePaths ( paths : string [ ] ) : string [ ] {
47+ export function normalizePaths ( paths : string [ ] ) : string [ ] {
4948 return paths . map ( ( path ) => path . trim ( ) ) . filter ( ( path ) => path !== "" ) ;
5049}
0 commit comments