From 3f3f2a3287c39a0c9cb1ab54ca4bcd8d37eaef17 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 15 Feb 2018 11:07:38 -0800 Subject: [PATCH] Ensure display name is set in statusbar for environments not detected (#791) if environment is a virtual env then suffix with envname Fixes #690 --- src/client/interpreter/index.ts | 6 ++++++ src/test/interpreters/display.test.ts | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/client/interpreter/index.ts b/src/client/interpreter/index.ts index db28b1a5df99..f6d048622f3c 100644 --- a/src/client/interpreter/index.ts +++ b/src/client/interpreter/index.ts @@ -9,6 +9,7 @@ import * as utils from '../common/utils'; import { IServiceContainer } from '../ioc/types'; import { IPythonPathUpdaterServiceManager } from './configuration/types'; import { IInterpreterDisplay, IInterpreterHelper, IInterpreterLocatorService, IInterpreterService, IInterpreterVersionService, INTERPRETER_LOCATOR_SERVICE, InterpreterType, PythonInterpreter, WORKSPACE_VIRTUAL_ENV_SERVICE } from './contracts'; +import { IVirtualEnvironmentManager } from './virtualEnvs/types'; @injectable() export class InterpreterManager implements Disposable, IInterpreterService { @@ -84,7 +85,12 @@ export class InterpreterManager implements Disposable, IInterpreterService { } const pythonExecutableName = path.basename(fullyQualifiedPath); const versionInfo = await this.serviceContainer.get(IInterpreterVersionService).getVersion(fullyQualifiedPath, pythonExecutableName); + const virtualEnvManager = this.serviceContainer.get(IVirtualEnvironmentManager); + const virtualEnvName = await virtualEnvManager.detect(fullyQualifiedPath).then(env => env ? env.name : ''); + const dislayNameSuffix = virtualEnvName.length > 0 ? ` (${virtualEnvName})` : ''; + const displayName = `${versionInfo}${dislayNameSuffix}`; return { + displayName, path: fullyQualifiedPath, type: InterpreterType.Unknown, version: versionInfo diff --git a/src/test/interpreters/display.test.ts b/src/test/interpreters/display.test.ts index b5bd44751919..e83ad98ee6cd 100644 --- a/src/test/interpreters/display.test.ts +++ b/src/test/interpreters/display.test.ts @@ -104,7 +104,7 @@ suite('Interpreters Display', () => { statusBar.verify(s => s.text = TypeMoq.It.isValue(activeInterpreter.displayName)!, TypeMoq.Times.once()); statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(expectedTooltip)!, TypeMoq.Times.once()); }); - test('If interpreter is not idenfied then tooltip should point to python Path', async () => { + test('If interpreter is not idenfied then tooltip should point to python Path and text containing the folder name', async () => { const resource = Uri.file('x'); const pythonPath = path.join('user', 'development', 'env', 'bin', 'python'); const workspaceFolder = Uri.file('workspace'); @@ -114,10 +114,30 @@ suite('Interpreters Display', () => { configurationService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object); pythonSettings.setup(p => p.pythonPath).returns(() => pythonPath); virtualEnvMgr.setup(v => v.detect(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve(undefined)); + versionProvider.setup(v => v.getVersion(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny())).returns((_path, defaultDisplayName) => Promise.resolve(defaultDisplayName)); await interpreterDisplay.refresh(resource); statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(pythonPath), TypeMoq.Times.once()); + statusBar.verify(s => s.text = TypeMoq.It.isValue(`${path.basename(pythonPath)} [Environment]`), TypeMoq.Times.once()); + }); + test('If virtual environment interpreter is not idenfied then text should contain the type of virtual environment', async () => { + const resource = Uri.file('x'); + const pythonPath = path.join('user', 'development', 'env', 'bin', 'python'); + const workspaceFolder = Uri.file('workspace'); + setupWorkspaceFolder(resource, workspaceFolder); + interpreterService.setup(i => i.getInterpreters(TypeMoq.It.isValue(workspaceFolder))).returns(() => Promise.resolve([])); + interpreterService.setup(i => i.getActiveInterpreter(TypeMoq.It.isValue(workspaceFolder))).returns(() => Promise.resolve(undefined)); + configurationService.setup(c => c.getSettings(TypeMoq.It.isAny())).returns(() => pythonSettings.object); + pythonSettings.setup(p => p.pythonPath).returns(() => pythonPath); + // tslint:disable-next-line:no-any + virtualEnvMgr.setup(v => v.detect(TypeMoq.It.isValue(pythonPath))).returns(() => Promise.resolve({ name: 'Mock Name' } as any)); + versionProvider.setup(v => v.getVersion(TypeMoq.It.isValue(pythonPath), TypeMoq.It.isAny())).returns((_path, defaultDisplayName) => Promise.resolve(defaultDisplayName)); + + await interpreterDisplay.refresh(resource); + + statusBar.verify(s => s.tooltip = TypeMoq.It.isValue(pythonPath), TypeMoq.Times.once()); + statusBar.verify(s => s.text = TypeMoq.It.isValue(`${path.basename(pythonPath)} [Environment] (Mock Name)`), TypeMoq.Times.once()); }); test('If interpreter file does not exist then update status bar accordingly', async () => { const resource = Uri.file('x');