Skip to content

Commit

Permalink
More clean up of get label format
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Sep 21, 2023
1 parent b73fbf3 commit 7357bbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "andreas-talon",
"displayName": "Andreas Talon",
"description": "VSCode extension used by Talon Voice",
"version": "3.36.2",
"version": "3.36.3",
"publisher": "AndreasArvidsson",
"license": "MIT",
"main": "./out/extension.js",
Expand Down
31 changes: 15 additions & 16 deletions src/util/getLabelFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getLabelFormat(tab: vscode.Tab, uri: vscode.Uri): string | undef
}
}

function getFolderName(uri: vscode.Uri) {
function getFolderName(uri: vscode.Uri): string {
return path.basename(path.dirname(uri.fsPath));
}

Expand All @@ -41,24 +41,23 @@ function getConflictPath(tab: vscode.Tab, uri: vscode.Uri): string | undefined {
return undefined;
}

const parts = [];
const relativePath = vscode.workspace.asRelativePath(uri);
const parsedPath = path.parse(relativePath);
const parentName = path.basename(parsedPath.dir);
const wsFolder = vscode.workspace.getWorkspaceFolder(uri);
const fsPath = wsFolder != null ? path.relative(wsFolder.uri.fsPath, uri.fsPath) : uri.fsPath;
const parsedPath = path.parse(fsPath);
const parts = [parsedPath.root];

if (parsedPath.root) {
parts.push(parsedPath.root);
const dirParent = path.dirname(parsedPath.dir);
if (dirParent && dirParent !== parsedPath.root) {
parts.push("...");
parts.push(path.sep);
if (parsedPath.dir) {
const grandFolder = path.dirname(parsedPath.dir);
const folderName = path.basename(parsedPath.dir);
// Have additional folders above this one that is not root.
if (grandFolder && grandFolder !== parsedPath.root && grandFolder !== ".") {
parts.push("...", path.sep);
}
} else if (!parentName) {
parts.push(".", path.sep);
parts.push(folderName);
}

if (parentName) {
parts.push(parentName);
// Empty relative path. ie workspace folder
else {
parts.push(".", path.sep);
}

return parts.join("");
Expand Down

0 comments on commit 7357bbe

Please sign in to comment.