Skip to content

Commit 4d38469

Browse files
committed
feat: enhance handling of broken Python environments in tree view
1 parent 5250134 commit 4d38469

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publisher": "ms-python",
77
"preview": true,
88
"engines": {
9-
"vscode": "^1.110.0-20260204"
9+
"vscode": "^1.110.0-20260204"
1010
},
1111
"categories": [
1212
"Other"
@@ -457,6 +457,10 @@
457457
"command": "python-envs.remove",
458458
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*;remove;.*/"
459459
},
460+
{
461+
"command": "python-envs.remove",
462+
"when": "view == env-managers && viewItem =~ /.*pythonBrokenEnvironment.*;remove;.*/"
463+
},
460464
{
461465
"command": "python-envs.setEnv",
462466
"group": "inline",
@@ -491,6 +495,16 @@
491495
"group": "inline",
492496
"when": "view == env-managers && viewItem =~ /.*pythonEnvironment.*/ && viewItem =~ /.*copied.*/"
493497
},
498+
{
499+
"command": "python-envs.copyEnvPath",
500+
"group": "inline",
501+
"when": "view == env-managers && viewItem =~ /.*pythonBrokenEnvironment.*/ && viewItem =~ /^((?!copied).)*$/"
502+
},
503+
{
504+
"command": "python-envs.copyEnvPathCopied",
505+
"group": "inline",
506+
"when": "view == env-managers && viewItem =~ /.*pythonBrokenEnvironment.*/ && viewItem =~ /.*copied.*/"
507+
},
494508
{
495509
"command": "python-envs.uninstallPackage",
496510
"group": "inline",

src/features/views/treeViewItems.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ export class PythonEnvTreeItem implements EnvTreeItem {
9393
private getContextValue() {
9494
const isBroken = !!this.environment.error;
9595
const activatable = !isBroken && isActivatableEnvironment(this.environment) ? 'activatable' : '';
96-
const broken = isBroken ? 'broken' : '';
9796
let remove = '';
9897
if (this.parent.kind === EnvTreeItemKind.environmentGroup) {
9998
remove = this.parent.parent.manager.supportsRemove ? 'remove' : '';
10099
} else if (this.parent.kind === EnvTreeItemKind.manager) {
101100
remove = this.parent.manager.supportsRemove ? 'remove' : '';
102101
}
103-
const parts = ['pythonEnvironment', remove, activatable, broken].filter(Boolean);
102+
// Use different base context for broken environments so normal actions don't show
103+
const baseContext = isBroken ? 'pythonBrokenEnvironment' : 'pythonEnvironment';
104+
const parts = [baseContext, remove, activatable].filter(Boolean);
104105
return parts.join(';') + ';';
105106
}
106107
}

src/internal.api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ export class PythonEnvironmentImpl implements PythonEnvironment {
338338
public readonly execInfo: PythonEnvironmentExecutionInfo;
339339
public readonly sysPrefix: string;
340340
public readonly group?: string | EnvironmentGroupInfo;
341+
public readonly error?: string;
341342

342343
constructor(
343344
public readonly envId: PythonEnvironmentId,
@@ -355,6 +356,7 @@ export class PythonEnvironmentImpl implements PythonEnvironment {
355356
this.execInfo = info.execInfo;
356357
this.sysPrefix = info.sysPrefix;
357358
this.group = info.group;
359+
this.error = info.error;
358360
}
359361
}
360362

0 commit comments

Comments
 (0)