Skip to content

Commit 44a683d

Browse files
Add "Reveal Project in Explorer" context menu action for Python Projects (#568)
This PR adds a "Reveal Project in Explorer" context menu action to the Python Projects view, allowing users to easily navigate from the Python Project view to its file location in the OS file explorer. ## Changes Made - **Added new command**: `python-envs.revealProjectInExplorer` with folder icon (`$(folder-opened)`) - **Context menu integration**: Added the command to the context menu for all python-workspace items (both removable and non-removable) - **Localization**: Added localized title string "Reveal Project in Explorer" - **Command implementation**: Uses VS Code's built-in `revealFileInOS` command to open the project folder in the OS file explorer - **Command palette**: Hidden from command palette (only available via context menu as requested) ## Usage Users can now right-click on any Python project in the Python Projects view and select "Reveal Project in Explorer" to open the project folder in their operating system's file explorer. ![Context menu showing the new reveal action](https://github.com/user-attachments/assets/80808960-1b87-4741-9fe8-2116f1d1c9fa) Fixes #488. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent fde4d1d commit 44a683d

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@
255255
"command": "python-envs.reportIssue",
256256
"title": "%python-envs.reportIssue.title%",
257257
"category": "Python Environments"
258+
},
259+
{
260+
"command": "python-envs.revealProjectInExplorer",
261+
"title": "%python-envs.revealProjectInExplorer.title%",
262+
"category": "Python Envs",
263+
"icon": "$(folder-opened)"
258264
}
259265
],
260266
"menus": {
@@ -326,6 +332,10 @@
326332
{
327333
"command": "python-envs.createAny",
328334
"when": "false"
335+
},
336+
{
337+
"command": "python-envs.revealProjectInExplorer",
338+
"when": "false"
329339
}
330340
],
331341
"view/item/context": [
@@ -395,6 +405,10 @@
395405
"group": "inline",
396406
"when": "view == python-projects && viewItem =~ /.*python-workspace.*/"
397407
},
408+
{
409+
"command": "python-envs.revealProjectInExplorer",
410+
"when": "view == python-projects && viewItem =~ /.*python-workspace.*/"
411+
},
398412
{
399413
"command": "python-envs.uninstallPackage",
400414
"group": "inline",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
"python-envs.createNewProjectFromTemplate.title": "Create New Project from Template",
3535
"python-envs.terminal.activate.title": "Activate Environment in Current Terminal",
3636
"python-envs.terminal.deactivate.title": "Deactivate Environment in Current Terminal",
37-
"python-envs.uninstallPackage.title": "Uninstall Package"
37+
"python-envs.uninstallPackage.title": "Uninstall Package",
38+
"python-envs.revealProjectInExplorer.title": "Reveal Project in Explorer"
3839
}

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
refreshPackagesCommand,
3333
removeEnvironmentCommand,
3434
removePythonProject,
35+
revealProjectInExplorer,
3536
runAsTaskCommand,
3637
runInDedicatedTerminalCommand,
3738
runInTerminalCommand,
@@ -356,6 +357,9 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
356357
commands.registerCommand('python-envs.copyProjectPath', async (item) => {
357358
await copyPathToClipboard(item);
358359
}),
360+
commands.registerCommand('python-envs.revealProjectInExplorer', async (item) => {
361+
await revealProjectInExplorer(item);
362+
}),
359363
commands.registerCommand('python-envs.terminal.activate', async () => {
360364
const terminal = activeTerminal();
361365
if (terminal) {

src/features/envCommands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,3 +649,12 @@ export async function copyPathToClipboard(item: unknown): Promise<void> {
649649
traceVerbose(`Invalid context for copy path to clipboard: ${item}`);
650650
}
651651
}
652+
653+
export async function revealProjectInExplorer(item: unknown): Promise<void> {
654+
if (item instanceof ProjectItem) {
655+
const projectUri = item.project.uri;
656+
await commands.executeCommand('revealInExplorer', projectUri);
657+
} else {
658+
traceVerbose(`Invalid context for reveal project in explorer: ${item}`);
659+
}
660+
}

0 commit comments

Comments
 (0)