Skip to content

Commit 7161372

Browse files
authored
feat: open parent folder of venv after creation (#567)
fixes #553
1 parent e4d98a6 commit 7161372

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/managers/builtin/venvManager.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import * as fs from 'fs/promises';
22
import * as path from 'path';
3-
import { EventEmitter, l10n, LogOutputChannel, MarkdownString, ProgressLocation, ThemeIcon, Uri } from 'vscode';
3+
import {
4+
commands,
5+
EventEmitter,
6+
l10n,
7+
LogOutputChannel,
8+
MarkdownString,
9+
ProgressLocation,
10+
ThemeIcon,
11+
Uri,
12+
} from 'vscode';
413
import {
514
CreateEnvironmentOptions,
615
CreateEnvironmentScope,
@@ -162,6 +171,7 @@ export class VenvManager implements EnvironmentManager {
162171
showQuickAndCustomOptions: options?.quickCreate === undefined,
163172
});
164173
}
174+
165175
if (environment) {
166176
this.addEnvironment(environment, true);
167177

@@ -175,6 +185,21 @@ export class VenvManager implements EnvironmentManager {
175185
`Failed to create .gitignore in venv: ${err instanceof Error ? err.message : String(err)}`,
176186
);
177187
}
188+
189+
// Open the parent folder of the venv in the current window immediately after creation
190+
const envParent = path.dirname(environment.sysPrefix);
191+
try {
192+
await commands.executeCommand('vscode.openFolder', Uri.file(envParent), {
193+
forceNewWindow: false,
194+
});
195+
} catch (error) {
196+
showErrorMessage(
197+
l10n.t('Failed to open venv parent folder: but venv was still created in {0}', envParent),
198+
);
199+
traceError(
200+
`Failed to open venv parent folder: ${error instanceof Error ? error.message : String(error)}`,
201+
);
202+
}
178203
}
179204
return environment;
180205
} finally {

0 commit comments

Comments
 (0)