Skip to content

Commit fffcf9e

Browse files
author
Kartik Raj
authored
Add tip to reload window if user has attempted to install Python in the interpreter quickpick (#19446)
1 parent 8715c23 commit fffcf9e

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
{
147147
"id": "python.selectInterpreter",
148148
"title": "Select a Python Interpreter",
149-
"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). ",
149+
"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).",
150150
"media": {
151151
"svg": "resources/walkthrough/python-interpreter-v2.svg",
152152
"altText": "Selecting a python interpreter from the status bar"

src/client/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export namespace Octicons {
7373
export const Gear = '$(gear)';
7474
export const Warning = '$(warning)';
7575
export const Error = '$(error)';
76+
export const Lightbulb = '$(lightbulb)';
7677
}
7778

7879
export const DEFAULT_INTERPRETER_SETTING = 'python';

src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { IPlatformService } from '../../../../common/platform/types';
1515
import { IConfigurationService, IPathUtils, Resource } from '../../../../common/types';
1616
import { getIcon } from '../../../../common/utils/icons';
1717
import { Common, InterpreterQuickPickList } from '../../../../common/utils/localize';
18+
import { noop } from '../../../../common/utils/misc';
1819
import {
1920
IMultiStepInput,
2021
IMultiStepInputFactory,
@@ -80,6 +81,14 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
8081
alwaysShow: true,
8182
};
8283

84+
private wasNoPythonInstalledItemClicked = false;
85+
86+
private readonly tipToReloadWindow: ISpecialQuickPickItem = {
87+
label: `${Octicons.Lightbulb} Reload the window if you installed Python but don't see it`,
88+
detail: `Click to run \`Developer: Reload Window\` command`,
89+
alwaysShow: true,
90+
};
91+
8392
constructor(
8493
@inject(IApplicationShell) applicationShell: IApplicationShell,
8594
@inject(IPathUtils) pathUtils: IPathUtils,
@@ -171,7 +180,10 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
171180
sendTelemetryEvent(EventName.SELECT_INTERPRETER_ENTER_OR_FIND);
172181
return this._enterOrBrowseInterpreterPath(input, state, suggestions);
173182
} else if (selection.label === this.noPythonInstalled.label) {
174-
this.commandManager.executeCommand(Commands.InstallPython);
183+
this.commandManager.executeCommand(Commands.InstallPython).then(noop, noop);
184+
this.wasNoPythonInstalledItemClicked = true;
185+
} else if (selection.label === this.tipToReloadWindow.label) {
186+
this.commandManager.executeCommand('workbench.action.reloadWindow').then(noop, noop);
175187
} else {
176188
sendTelemetryEvent(EventName.SELECT_INTERPRETER_SELECTED, undefined, { action: 'selected' });
177189
state.path = (selection as IInterpreterQuickPickItem).path;
@@ -302,6 +314,12 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
302314
if (noPyIndex !== -1) {
303315
updatedItems.splice(noPyIndex, 1);
304316
}
317+
const tryReloadIndex = updatedItems.findIndex(
318+
(item) => isSpecialQuickPickItem(item) && item.label === this.tipToReloadWindow.label,
319+
);
320+
if (tryReloadIndex !== -1) {
321+
updatedItems.splice(tryReloadIndex, 1);
322+
}
305323
if (areItemsGrouped) {
306324
addSeparatorIfApplicable(
307325
updatedItems,
@@ -340,6 +358,9 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
340358
});
341359
} else {
342360
items.push(this.noPythonInstalled);
361+
if (this.wasNoPythonInstalledItemClicked) {
362+
items.push(this.tipToReloadWindow);
363+
}
343364
}
344365
}
345366
}

src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ suite('Set Interpreter Command', () => {
135135
alwaysShow: true,
136136
};
137137

138+
const tipToReloadWindow = {
139+
label: `${Octicons.Lightbulb} Reload the window if you installed Python but don't see it`,
140+
detail: `Click to run \`Developer: Reload Window\` command`,
141+
alwaysShow: true,
142+
};
143+
138144
const refreshedItem: IInterpreterQuickPickItem = {
139145
description: interpreterPath,
140146
detail: '',
@@ -322,6 +328,26 @@ suite('Set Interpreter Command', () => {
322328
commandManager.verifyAll();
323329
});
324330

331+
test('Picker should reload window if corresponding item is selected', async () => {
332+
const state: InterpreterStateArgs = { path: 'some path', workspace: undefined };
333+
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();
334+
multiStepInput
335+
.setup((i) => i.showQuickPick(TypeMoq.It.isAny()))
336+
.returns(() => Promise.resolve((tipToReloadWindow as unknown) as QuickPickItem));
337+
interpreterSelector.reset();
338+
interpreterSelector
339+
.setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
340+
.returns(() => []);
341+
commandManager
342+
.setup((c) => c.executeCommand('workbench.action.reloadWindow'))
343+
.returns(() => Promise.resolve())
344+
.verifiable(TypeMoq.Times.once());
345+
346+
await setInterpreterCommand._pickInterpreter(multiStepInput.object, state);
347+
348+
commandManager.verifyAll();
349+
});
350+
325351
test('Items displayed should be grouped if no refresh is going on', async () => {
326352
const state: InterpreterStateArgs = { path: 'some path', workspace: undefined };
327353
const multiStepInput = TypeMoq.Mock.ofType<IMultiStepInput<InterpreterStateArgs>>();

0 commit comments

Comments
 (0)