Skip to content

Commit 0110225

Browse files
authored
Fix bug with selecting global python (#39)
Fixes #38
1 parent e19579a commit 0110225

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/features/envCommands.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ProjectItem,
2929
ProjectEnvironment,
3030
ProjectPackageRootTreeItem,
31+
GlobalProjectItem,
3132
} from './views/treeViewItems';
3233
import { Common } from '../common/localize';
3334
import { pickEnvironment } from '../common/pickers/environments';
@@ -213,10 +214,15 @@ export async function setEnvironmentCommand(
213214
if (context instanceof PythonEnvTreeItem) {
214215
try {
215216
const view = context as PythonEnvTreeItem;
216-
const projects = await pickProjectMany(wm.getProjects());
217-
if (projects && projects.length > 0) {
218-
const uris = projects.map((p) => p.uri);
219-
await em.setEnvironments(uris, view.environment);
217+
const projects = wm.getProjects();
218+
if (projects.length > 0) {
219+
const selected = await pickProjectMany(projects);
220+
if (selected && selected.length > 0) {
221+
const uris = selected.map((p) => p.uri);
222+
await em.setEnvironments(uris, view.environment);
223+
}
224+
} else {
225+
await em.setEnvironments('global', view.environment);
220226
}
221227
} catch (ex) {
222228
if (ex === QuickInputButtons.Back) {
@@ -227,12 +233,14 @@ export async function setEnvironmentCommand(
227233
} else if (context instanceof ProjectItem) {
228234
const view = context as ProjectItem;
229235
await setEnvironmentCommand([view.project.uri], em, wm);
236+
} else if (context instanceof GlobalProjectItem) {
237+
await setEnvironmentCommand(undefined, em, wm);
230238
} else if (context instanceof Uri) {
231239
await setEnvironmentCommand([context], em, wm);
232240
} else if (context === undefined) {
233241
try {
234242
const projects = wm.getProjects();
235-
if (projects && projects.length > 0) {
243+
if (projects.length > 0) {
236244
const selected = await pickProjectMany(projects);
237245
if (selected && selected.length > 0) {
238246
const uris = selected.map((p) => p.uri);

0 commit comments

Comments
 (0)