Skip to content

Commit 3a9d73b

Browse files
committed
Add open diagnostic folder button to windows/linux
1 parent 4c6710f commit 3a9d73b

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/commands/captureDiagnostics.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,49 @@ export async function captureDiagnostics(ctx: WorkspaceContext) {
4141

4242
ctx.outputChannel.log(`Saved diagnostics to ${diagnosticsDir}`);
4343

44-
const showInFinderButton = "Show In Finder";
44+
const showInFinderButton = `Show In ${showCommandType()}`;
4545
const copyPath = "Copy Path to Clipboard";
46-
const infoDialogButtons = [
47-
...(process.platform === "darwin" ? [showInFinderButton] : []),
48-
copyPath,
49-
];
5046
const result = await vscode.window.showInformationMessage(
5147
`Saved diagnostic logs to ${diagnosticsDir}`,
52-
...infoDialogButtons
48+
showInFinderButton,
49+
copyPath
5350
);
5451
if (result === copyPath) {
5552
vscode.env.clipboard.writeText(diagnosticsDir);
5653
} else if (result === showInFinderButton) {
57-
exec(`open ${diagnosticsDir}`, error => {
58-
if (error) {
59-
vscode.window.showErrorMessage(`Failed to open Finder: ${error.message}`);
60-
return;
54+
exec(showDirectoryCommand(diagnosticsDir), error => {
55+
// Opening the explorer on windows returns an exit code of 1 despite opening successfully.
56+
if (error && process.platform !== "win32") {
57+
vscode.window.showErrorMessage(
58+
`Failed to open ${showCommandType()}: ${error.message}`
59+
);
6160
}
6261
});
6362
}
6463
} catch (error) {
65-
vscode.window.showErrorMessage(`Unable to captrure diagnostics logs: ${error}`);
64+
vscode.window.showErrorMessage(`Unable to capture diagnostic logs: ${error}`);
65+
}
66+
}
67+
68+
function showDirectoryCommand(dir: string): string {
69+
switch (process.platform) {
70+
case "win32":
71+
return `explorer ${dir}`;
72+
case "darwin":
73+
return `open ${dir}`;
74+
default:
75+
return `xdg-open ${dir}`;
76+
}
77+
}
78+
79+
function showCommandType(): string {
80+
switch (process.platform) {
81+
case "win32":
82+
return "Explorer";
83+
case "darwin":
84+
return "Finder";
85+
default:
86+
return "File Manager";
6687
}
6788
}
6889

0 commit comments

Comments
 (0)