Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/logic/filePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ const createFilePath = (FilePath) => {
let res = `${path.sep}${itemName}${fileItemPath}` // 拼接项目名称和相对于项目的路径
if (FilePath === 'no item name') {
res = `${fileItemPath}`
} else if (FilePath === 'relative path') {
if (vscode.workspace.workspaceFolders.length > 0) {
// 获取工作空间路径
let folder = vscode.workspace.workspaceFolders[0];
let root = path.resolve(folder.uri.fsPath, '..');
if (fileItemPath.indexOf(root) === 0) {
res = path.sep + path.relative(root, fileItemPath);
}
}
} else if (FilePath === 'relative path without workspace') {
if (vscode.workspace.workspaceFolders.length > 0) {
// 遍历工作空间路径
for (const workspaceFolder of vscode.workspace.workspaceFolders) {
let root = workspaceFolder.uri.fsPath;
if (fileItemPath.indexOf(root) === 0) {
// 存在于工作空间的路径才进行转换
res = path.sep + path.relative(root, fileItemPath);
break;
}
}
}
} else if (FilePath === 'only file name') {
const arr = fileItemPath.split(path.sep)
res = arr[arr.length - 1]
Expand Down