Skip to content

Use status bar to indicate whether selected Python interpreter is invalid #19510

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 20, 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
15 changes: 13 additions & 2 deletions src/client/interpreter/display/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { inject, injectable } from 'inversify';
import { Disposable, LanguageStatusItem, LanguageStatusSeverity, StatusBarAlignment, StatusBarItem, Uri } from 'vscode';
import {
Disposable,
LanguageStatusItem,
LanguageStatusSeverity,
StatusBarAlignment,
StatusBarItem,
ThemeColor,
Uri,
} from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
import { Commands, PYTHON_LANGUAGE } from '../../common/constants';
Expand Down Expand Up @@ -133,6 +141,7 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
} else {
this.statusBar.tooltip = '';
this.statusBar.color = '';
this.statusBar.backgroundColor = new ThemeColor('statusBarItem.warningBackground');
this.statusBar.text = `$(alert) ${InterpreterQuickPickList.browsePath.openButtonLabel}`;
this.currentlySelectedInterpreterDisplay = undefined;
}
Expand All @@ -153,8 +162,10 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
text = text.startsWith('Python') ? text.substring('Python'.length).trim() : text;
this.languageStatus.text = text;
this.currentlySelectedInterpreterDisplay = interpreter.detailedDisplayName;
this.languageStatus.severity = LanguageStatusSeverity.Information;
} else {
this.languageStatus.text = '$(alert) No Interpreter Selected';
this.languageStatus.severity = LanguageStatusSeverity.Warning;
this.languageStatus.text = `$(alert) ${InterpreterQuickPickList.browsePath.openButtonLabel}`;
this.languageStatus.detail = undefined;
this.currentlySelectedInterpreterDisplay = undefined;
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/interpreters/display.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { InterpreterDisplay } from '../../client/interpreter/display';
import { IServiceContainer } from '../../client/ioc/types';
import * as logging from '../../client/logging';
import { EnvironmentType, PythonEnvironment } from '../../client/pythonEnvironments/info';
import { ThemeColor } from '../mocks/vsc';

const info: PythonEnvironment = {
architecture: Architecture.Unknown,
Expand Down Expand Up @@ -274,6 +275,11 @@ suite('Interpreters Display', () => {
TypeMoq.Times.once(),
);
} else {
statusBar.verify(
(s) =>
(s.backgroundColor = TypeMoq.It.isValue(new ThemeColor('statusBarItem.warningBackground'))),
TypeMoq.Times.once(),
);
statusBar.verify((s) => (s.color = TypeMoq.It.isValue('')), TypeMoq.Times.once());
statusBar.verify(
(s) =>
Expand Down
4 changes: 4 additions & 0 deletions src/test/mocks/vsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function escapeCodicons(text: string): string {
return text.replace(escapeCodiconsRegex, (match, escaped) => (escaped ? match : `\\${match}`));
}

export class ThemeColor {
constructor(public readonly id: string) {}
}

export enum ExtensionKind {
/**
* Extension runs where the UI runs.
Expand Down
1 change: 1 addition & 0 deletions src/test/vscode-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function initialize() {
};
}

mockedVSCode.ThemeColor = vscodeMocks.ThemeColor;
mockedVSCode.MarkdownString = vscodeMocks.MarkdownString;
mockedVSCode.Hover = vscodeMocks.Hover;
mockedVSCode.Disposable = vscodeMocks.Disposable as any;
Expand Down