Skip to content

Commit 6d0aaa7

Browse files
author
Kartik Raj
authored
Add description on hover to interpreter status bar item (microsoft#20411)
Closes microsoft#16480
1 parent 804e656 commit 6d0aaa7

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

src/client/common/application/applicationShell.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ export class ApplicationShell implements IApplicationShell {
122122
return window.setStatusBarMessage(text, arg);
123123
}
124124

125-
public createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem {
126-
return window.createStatusBarItem(alignment, priority);
125+
public createStatusBarItem(
126+
alignment?: StatusBarAlignment,
127+
priority?: number,
128+
id?: string | undefined,
129+
): StatusBarItem {
130+
return id
131+
? window.createStatusBarItem(id, alignment, priority)
132+
: window.createStatusBarItem(alignment, priority);
127133
}
128134
public showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined> {
129135
return window.showWorkspaceFolderPick(options);

src/client/common/application/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export interface IApplicationShell {
355355
* @param priority The priority of the item. Higher values mean the item should be shown more to the left.
356356
* @return A new status bar item.
357357
*/
358-
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem;
358+
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number, id?: string): StatusBarItem;
359359
/**
360360
* Shows a selection list of [workspace folders](#workspace.workspaceFolders) to pick from.
361361
* Returns `undefined` if no folder is open.

src/client/common/utils/localize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ export namespace Interpreters {
283283
'Interpreters.changePythonInterpreter',
284284
'Change Python Interpreter',
285285
);
286+
export const selectedPythonInterpreter = localize(
287+
'Interpreters.selectedPythonInterpreter',
288+
'Selected Python Interpreter',
289+
);
286290
}
287291

288292
export namespace InterpreterQuickPickList {

src/client/interpreter/display/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IApplicationShell, IWorkspaceService } from '../../common/application/t
1313
import { Commands, PYTHON_LANGUAGE } from '../../common/constants';
1414
import '../../common/extensions';
1515
import { IDisposableRegistry, IPathUtils, Resource } from '../../common/types';
16-
import { InterpreterQuickPickList } from '../../common/utils/localize';
16+
import { InterpreterQuickPickList, Interpreters } from '../../common/utils/localize';
1717
import { IServiceContainer } from '../../ioc/types';
1818
import { traceLog } from '../../logging';
1919
import { PythonEnvironment } from '../../pythonEnvironments/info';
@@ -32,6 +32,7 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
3232
* This is to ensure the item appears right after the Python language status item.
3333
*/
3434
const STATUS_BAR_ITEM_PRIORITY = 100.09999;
35+
3536
@injectable()
3637
export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingleActivationService {
3738
public supportedWorkspaceTypes: { untrustedWorkspace: boolean; virtualWorkspace: boolean } = {
@@ -81,9 +82,10 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
8182
this.disposableRegistry.push(this.languageStatus);
8283
} else {
8384
const [alignment, priority] = [StatusBarAlignment.Right, STATUS_BAR_ITEM_PRIORITY];
84-
this.statusBar = application.createStatusBarItem(alignment, priority);
85+
this.statusBar = application.createStatusBarItem(alignment, priority, 'python.selectedInterpreterDisplay');
8586
this.statusBar.command = Commands.Set_Interpreter;
8687
this.disposableRegistry.push(this.statusBar);
88+
this.statusBar.name = Interpreters.selectedPythonInterpreter;
8789
}
8890
}
8991

src/test/interpreters/display.unit.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ suite('Interpreters Display', () => {
6060
let traceLogStub: sinon.SinonStub;
6161
async function createInterpreterDisplay(filters: IInterpreterStatusbarVisibilityFilter[] = []) {
6262
interpreterDisplay = new InterpreterDisplay(serviceContainer.object);
63-
await interpreterDisplay.activate();
63+
try {
64+
await interpreterDisplay.activate();
65+
} catch {}
6466
filters.forEach((f) => interpreterDisplay.registerVisibilityFilter(f));
6567
}
6668

@@ -73,6 +75,7 @@ suite('Interpreters Display', () => {
7375
interpreterHelper = TypeMoq.Mock.ofType<IInterpreterHelper>();
7476
disposableRegistry = [];
7577
statusBar = TypeMoq.Mock.ofType<StatusBarItem>();
78+
statusBar.setup((s) => s.name).returns(() => '');
7679
languageStatusItem = TypeMoq.Mock.ofType<LanguageStatusItem>();
7780
pathUtils = TypeMoq.Mock.ofType<IPathUtils>();
7881

@@ -95,7 +98,13 @@ suite('Interpreters Display', () => {
9598
serviceContainer.setup((c) => c.get(TypeMoq.It.isValue(IPathUtils))).returns(() => pathUtils.object);
9699
if (!useLanguageStatus) {
97100
applicationShell
98-
.setup((a) => a.createStatusBarItem(TypeMoq.It.isValue(StatusBarAlignment.Right), TypeMoq.It.isAny()))
101+
.setup((a) =>
102+
a.createStatusBarItem(
103+
TypeMoq.It.isValue(StatusBarAlignment.Right),
104+
TypeMoq.It.isAny(),
105+
TypeMoq.It.isAny(),
106+
),
107+
)
99108
.returns(() => statusBar.object);
100109
} else {
101110
applicationShell
@@ -144,10 +153,7 @@ suite('Interpreters Display', () => {
144153
);
145154
expect(disposableRegistry).contain(languageStatusItem.object);
146155
} else {
147-
statusBar.verify(
148-
(s) => (s.command = TypeMoq.It.isValue('python.setInterpreter')),
149-
TypeMoq.Times.once(),
150-
);
156+
statusBar.verify((s) => (s.command = TypeMoq.It.isAny()), TypeMoq.Times.once());
151157
expect(disposableRegistry).contain(statusBar.object);
152158
}
153159
expect(disposableRegistry).to.be.lengthOf.above(0);

0 commit comments

Comments
 (0)