Skip to content

Add cancellation token support and link to logs. #19882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export namespace Common {
export const openLaunch = localize('Common.openLaunch', 'Open launch.json');
export const useCommandPrompt = localize('Common.useCommandPrompt', 'Use Command Prompt');
export const download = localize('Common.download', 'Download');
export const showLogs = localize('Common.showLogs', 'Show logs');
}

export namespace CommonSurvey {
Expand Down Expand Up @@ -269,7 +270,7 @@ export namespace Interpreters {
);
export const environmentPromptMessage = localize(
'Interpreters.environmentPromptMessage',
'We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?',
'We noticed a new environment has been created. Do you want to select it for the workspace folder?',
);
export const entireWorkspace = localize('Interpreters.entireWorkspace', 'Select at workspace level');
export const clearAtWorkspace = localize('Interpreters.clearAtWorkspace', 'Clear at workspace level');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as fsapi from 'fs-extra';
import * as path from 'path';
import { QuickPickItem, WorkspaceFolder } from 'vscode';
import { CancellationToken, QuickPickItem, WorkspaceFolder } from 'vscode';
import { showErrorMessage, showQuickPick } from '../../../common/vscodeApis/windowApis';
import { getWorkspaceFolders } from '../../../common/vscodeApis/workspaceApis';
import { CreateEnv } from '../../../common/utils/localize';
Expand All @@ -30,6 +30,7 @@ async function getWorkspacesForQuickPick(workspaces: readonly WorkspaceFolder[])

export interface PickWorkspaceFolderOptions {
allowMultiSelect?: boolean;
token?: CancellationToken;
}

export async function pickWorkspaceFolder(
Expand All @@ -47,11 +48,15 @@ export async function pickWorkspaceFolder(
}

// This is multi-root scenario.
const selected = await showQuickPick(getWorkspacesForQuickPick(workspaces), {
title: CreateEnv.pickWorkspaceTitle,
ignoreFocusOut: true,
canPickMany: options?.allowMultiSelect,
});
const selected = await showQuickPick(
getWorkspacesForQuickPick(workspaces),
{
title: CreateEnv.pickWorkspaceTitle,
ignoreFocusOut: true,
canPickMany: options?.allowMultiSelect,
},
options?.token,
);

if (selected) {
if (options?.allowMultiSelect) {
Expand Down
5 changes: 3 additions & 2 deletions src/client/pythonEnvironments/creation/createEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { CancellationToken, ProgressLocation } from 'vscode';
import { withProgress } from '../../common/vscodeApis/windowApis';
import { traceError } from '../../logging';
import { CreateEnvironmentOptions, CreateEnvironmentProgress, CreateEnvironmentProvider } from './types';
import { CreateEnv } from '../../common/utils/localize';
import { Common, CreateEnv } from '../../common/utils/localize';
import { Commands } from '../../common/constants';

export async function createEnvironment(
provider: CreateEnvironmentProvider,
Expand All @@ -17,7 +18,7 @@ export async function createEnvironment(
return withProgress(
{
location: ProgressLocation.Notification,
title: CreateEnv.statusTitle,
title: `${CreateEnv.statusTitle} ([${Common.showLogs}](command:${Commands.ViewOutput}))`,
cancellable: true,
},
async (progress: CreateEnvironmentProgress, token: CancellationToken) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async function createEnvironment(
progress?.report({
message: CreateEnv.Conda.waitingForWorkspace,
});
const workspace = (await pickWorkspaceFolder()) as WorkspaceFolder | undefined;
const workspace = (await pickWorkspaceFolder({ token })) as WorkspaceFolder | undefined;
if (!workspace) {
traceError('Workspace was not selected or found for creating virtual env.');
return undefined;
Expand All @@ -164,7 +164,7 @@ async function createEnvironment(
progress?.report({
message: CreateEnv.Conda.waitingForPython,
});
const version = await pickPythonVersion();
const version = await pickPythonVersion(token);
if (!version) {
traceError('Conda environments for use with python extension require Python.');
return undefined;
Expand Down
14 changes: 9 additions & 5 deletions src/client/pythonEnvironments/creation/provider/condaUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { QuickPickItem, Uri } from 'vscode';
import { CancellationToken, QuickPickItem, Uri } from 'vscode';
import { Common } from '../../../browser/localize';
import { CreateEnv } from '../../../common/utils/localize';
import { executeCommand } from '../../../common/vscodeApis/commandApis';
Expand All @@ -21,13 +21,17 @@ export async function getConda(): Promise<string | undefined> {
return conda.command;
}

export async function pickPythonVersion(): Promise<string | undefined> {
export async function pickPythonVersion(token?: CancellationToken): Promise<string | undefined> {
const items: QuickPickItem[] = ['3.7', '3.8', '3.9', '3.10'].map((v) => ({
label: `Python`,
description: v,
}));
const version = await showQuickPick(items, {
title: CreateEnv.Conda.selectPythonQuickPickTitle,
});
const version = await showQuickPick(
items,
{
title: CreateEnv.Conda.selectPythonQuickPickTitle,
},
token,
);
return version?.description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class VenvCreationProvider implements CreateEnvironmentProvider {
message: CreateEnv.Venv.waitingForWorkspace,
});

const workspace = (await pickWorkspaceFolder()) as WorkspaceFolder | undefined;
const workspace = (await pickWorkspaceFolder({ token })) as WorkspaceFolder | undefined;
if (workspace === undefined) {
traceError('Workspace was not selected or found for creating virtual environment.');
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import * as sinon from 'sinon';
import * as typemoq from 'typemoq';
import { assert, use as chaiUse } from 'chai';
import { ProgressLocation, ProgressOptions } from 'vscode';
import { CreateEnv } from '../../../client/common/utils/localize';
import { Common, CreateEnv } from '../../../client/common/utils/localize';
import * as windowApis from '../../../client/common/vscodeApis/windowApis';
import { createEnvironment } from '../../../client/pythonEnvironments/creation/createEnvironment';
import {
CreateEnvironmentProgress,
CreateEnvironmentProvider,
} from '../../../client/pythonEnvironments/creation/types';
import { Commands } from '../../../client/common/constants';

chaiUse(chaiAsPromised);

Expand All @@ -26,7 +27,7 @@ suite('Create Environments Tests', () => {
withProgressStub.callsFake(async (options: ProgressOptions, task) => {
assert.deepEqual(options, {
location: ProgressLocation.Notification,
title: CreateEnv.statusTitle,
title: `${CreateEnv.statusTitle} ([${Common.showLogs}](command:${Commands.ViewOutput}))`,
cancellable: true,
});

Expand Down