Skip to content
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

Add description on hover to interpreter status bar item #20411

Merged
merged 3 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions src/client/common/application/applicationShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ export class ApplicationShell implements IApplicationShell {
return window.setStatusBarMessage(text, arg);
}

public createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem {
return window.createStatusBarItem(alignment, priority);
public createStatusBarItem(
alignment?: StatusBarAlignment,
priority?: number,
id?: string | undefined,
): StatusBarItem {
return window.createStatusBarItem(id, alignment, priority);
}
public showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined> {
return window.showWorkspaceFolderPick(options);
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export interface IApplicationShell {
* @param priority The priority of the item. Higher values mean the item should be shown more to the left.
* @return A new status bar item.
*/
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem;
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number, id?: string): StatusBarItem;
/**
* Shows a selection list of [workspace folders](#workspace.workspaceFolders) to pick from.
* Returns `undefined` if no folder is open.
Expand Down
4 changes: 4 additions & 0 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ export namespace Interpreters {
'Interpreters.changePythonInterpreter',
'Change Python Interpreter',
);
export const selectedPythonInterpreter = localize(
'Interpreters.selectedPythonInterpreter',
'Selected Python Interpreter',
);
}

export namespace InterpreterQuickPickList {
Expand Down
6 changes: 4 additions & 2 deletions src/client/interpreter/display/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IApplicationShell, IWorkspaceService } from '../../common/application/t
import { Commands, PYTHON_LANGUAGE } from '../../common/constants';
import '../../common/extensions';
import { IDisposableRegistry, IPathUtils, Resource } from '../../common/types';
import { InterpreterQuickPickList } from '../../common/utils/localize';
import { InterpreterQuickPickList, Interpreters } from '../../common/utils/localize';
import { IServiceContainer } from '../../ioc/types';
import { traceLog } from '../../logging';
import { PythonEnvironment } from '../../pythonEnvironments/info';
Expand All @@ -32,6 +32,7 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
* This is to ensure the item appears right after the Python language status item.
*/
const STATUS_BAR_ITEM_PRIORITY = 100.09999;

@injectable()
export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingleActivationService {
public supportedWorkspaceTypes: { untrustedWorkspace: boolean; virtualWorkspace: boolean } = {
Expand Down Expand Up @@ -81,9 +82,10 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
this.disposableRegistry.push(this.languageStatus);
} else {
const [alignment, priority] = [StatusBarAlignment.Right, STATUS_BAR_ITEM_PRIORITY];
this.statusBar = application.createStatusBarItem(alignment, priority);
this.statusBar = application.createStatusBarItem(alignment, priority, 'python.selectedInterpreterDisplay');
this.statusBar.command = Commands.Set_Interpreter;
this.disposableRegistry.push(this.statusBar);
this.statusBar.name = Interpreters.selectedPythonInterpreter;
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/test/interpreters/display.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ suite('Interpreters Display', () => {
let traceLogStub: sinon.SinonStub;
async function createInterpreterDisplay(filters: IInterpreterStatusbarVisibilityFilter[] = []) {
interpreterDisplay = new InterpreterDisplay(serviceContainer.object);
await interpreterDisplay.activate();
try {
await interpreterDisplay.activate();
} catch {}
filters.forEach((f) => interpreterDisplay.registerVisibilityFilter(f));
}

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

Expand All @@ -95,7 +98,13 @@ suite('Interpreters Display', () => {
serviceContainer.setup((c) => c.get(TypeMoq.It.isValue(IPathUtils))).returns(() => pathUtils.object);
if (!useLanguageStatus) {
applicationShell
.setup((a) => a.createStatusBarItem(TypeMoq.It.isValue(StatusBarAlignment.Right), TypeMoq.It.isAny()))
.setup((a) =>
a.createStatusBarItem(
TypeMoq.It.isValue(StatusBarAlignment.Right),
TypeMoq.It.isAny(),
TypeMoq.It.isAny(),
),
)
.returns(() => statusBar.object);
} else {
applicationShell
Expand Down Expand Up @@ -144,10 +153,7 @@ suite('Interpreters Display', () => {
);
expect(disposableRegistry).contain(languageStatusItem.object);
} else {
statusBar.verify(
(s) => (s.command = TypeMoq.It.isValue('python.setInterpreter')),
TypeMoq.Times.once(),
);
statusBar.verify((s) => (s.command = TypeMoq.It.isAny()), TypeMoq.Times.once());
expect(disposableRegistry).contain(statusBar.object);
}
expect(disposableRegistry).to.be.lengthOf.above(0);
Expand Down