Skip to content

Add tip to reload window if user has attempted to install Python in the interpreter quickpick #19446

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 1 commit into from
Jul 11, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
{
"id": "python.selectInterpreter",
"title": "Select a Python Interpreter",
"description": "Choose which Python interpreter/environment you want to use for your Python project.\n[Select Python Interpreter](command:python.setInterpreter)\n**Tip**: Run the ``Python: Select Interpreter`` command in the [Command Palette](command:workbench.action.showCommands).\nReload the window if you installed Python but don't see it in the list (``Developer: Reload Window`` command). ",
"description": "Choose which Python interpreter/environment you want to use for your Python project.\n[Select Python Interpreter](command:python.setInterpreter)\n**Tip**: Run the ``Python: Select Interpreter`` command in the [Command Palette](command:workbench.action.showCommands).",
"media": {
"svg": "resources/walkthrough/python-interpreter-v2.svg",
"altText": "Selecting a python interpreter from the status bar"
Expand Down
1 change: 1 addition & 0 deletions src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export namespace Octicons {
export const Gear = '$(gear)';
export const Warning = '$(warning)';
export const Error = '$(error)';
export const Lightbulb = '$(lightbulb)';
}

export const DEFAULT_INTERPRETER_SETTING = 'python';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IPlatformService } from '../../../../common/platform/types';
import { IConfigurationService, IPathUtils, Resource } from '../../../../common/types';
import { getIcon } from '../../../../common/utils/icons';
import { Common, InterpreterQuickPickList } from '../../../../common/utils/localize';
import { noop } from '../../../../common/utils/misc';
import {
IMultiStepInput,
IMultiStepInputFactory,
Expand Down Expand Up @@ -80,6 +81,14 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
alwaysShow: true,
};

private wasNoPythonInstalledItemClicked = false;

private readonly tipToReloadWindow: ISpecialQuickPickItem = {
label: `${Octicons.Lightbulb} Reload the window if you installed Python but don't see it`,
detail: `Click to run \`Developer: Reload Window\` command`,
alwaysShow: true,
};

constructor(
@inject(IApplicationShell) applicationShell: IApplicationShell,
@inject(IPathUtils) pathUtils: IPathUtils,
Expand Down Expand Up @@ -171,7 +180,10 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
sendTelemetryEvent(EventName.SELECT_INTERPRETER_ENTER_OR_FIND);
return this._enterOrBrowseInterpreterPath(input, state, suggestions);
} else if (selection.label === this.noPythonInstalled.label) {
this.commandManager.executeCommand(Commands.InstallPython);
this.commandManager.executeCommand(Commands.InstallPython).then(noop, noop);
this.wasNoPythonInstalledItemClicked = true;
} else if (selection.label === this.tipToReloadWindow.label) {
this.commandManager.executeCommand('workbench.action.reloadWindow').then(noop, noop);
} else {
sendTelemetryEvent(EventName.SELECT_INTERPRETER_SELECTED, undefined, { action: 'selected' });
state.path = (selection as IInterpreterQuickPickItem).path;
Expand Down Expand Up @@ -302,6 +314,12 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
if (noPyIndex !== -1) {
updatedItems.splice(noPyIndex, 1);
}
const tryReloadIndex = updatedItems.findIndex(
(item) => isSpecialQuickPickItem(item) && item.label === this.tipToReloadWindow.label,
);
if (tryReloadIndex !== -1) {
updatedItems.splice(tryReloadIndex, 1);
}
if (areItemsGrouped) {
addSeparatorIfApplicable(
updatedItems,
Expand Down Expand Up @@ -340,6 +358,9 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
});
} else {
items.push(this.noPythonInstalled);
if (this.wasNoPythonInstalledItemClicked) {
items.push(this.tipToReloadWindow);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ suite('Set Interpreter Command', () => {
alwaysShow: true,
};

const tipToReloadWindow = {
label: `${Octicons.Lightbulb} Reload the window if you installed Python but don't see it`,
detail: `Click to run \`Developer: Reload Window\` command`,
alwaysShow: true,
};

const refreshedItem: IInterpreterQuickPickItem = {
description: interpreterPath,
detail: '',
Expand Down Expand Up @@ -322,6 +328,26 @@ suite('Set Interpreter Command', () => {
commandManager.verifyAll();
});

test('Picker should reload window if corresponding item is selected', async () => {
const state: InterpreterStateArgs = { path: 'some path', workspace: undefined };
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
multiStepInput
.setup((i) => i.showQuickPick(TypeMoq.It.isAny()))
.returns(() => Promise.resolve((tipToReloadWindow as unknown) as QuickPickItem));
interpreterSelector.reset();
interpreterSelector
.setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => []);
commandManager
.setup((c) => c.executeCommand('workbench.action.reloadWindow'))
.returns(() => Promise.resolve())
.verifiable(TypeMoq.Times.once());

await setInterpreterCommand._pickInterpreter(multiStepInput.object, state);

commandManager.verifyAll();
});

test('Items displayed should be grouped if no refresh is going on', async () => {
const state: InterpreterStateArgs = { path: 'some path', workspace: undefined };
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
Expand Down