Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加相对于工作空间的路径生成规则 #472

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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