Skip to content

Commit

Permalink
Add tip to reload window if user has attempted to install Python in t…
Browse files Browse the repository at this point in the history
…he interpreter quickpick (microsoft/vscode-python#19446)
  • Loading branch information
Kartik Raj authored and wesm committed Mar 28, 2024
1 parent 89fca20 commit c8cc0a1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion extensions/positron-python/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 extensions/positron-python/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

0 comments on commit c8cc0a1

Please sign in to comment.