From 3c88f27697f4a4b1251146b27b34c56c454ff9c7 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 24 Oct 2023 13:13:20 -0700 Subject: [PATCH] Improve notification texts for terminal activation (#22323) Closes https://github.com/microsoft/vscode-python/issues/22316 --- src/client/common/utils/localize.ts | 4 ++-- .../envCollectionActivation/indicatorPrompt.ts | 14 ++++++++------ .../activation/indicatorPrompt.unit.test.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 538795e022e5..95252b361c76 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -197,12 +197,12 @@ export namespace Interpreters { export const activatingTerminals = l10n.t('Reactivating terminals...'); export const activateTerminalDescription = l10n.t('Activated environment for'); export const terminalEnvVarCollectionPrompt = l10n.t( - 'The selected Python environment indicator{0} may not be present in the terminal prompt. Rest assured, all terminals are still activated. [Learn more](https://aka.ms/vscodePythonTerminalActivation).', + '{0} environment was successfully activated, even though {1} may not be present in the terminal prompt. [Learn more](https://aka.ms/vscodePythonTerminalActivation).', ); export const terminalDeactivateProgress = l10n.t('Editing {0}...'); export const restartingTerminal = l10n.t('Restarting terminal and deactivating...'); export const terminalDeactivatePrompt = l10n.t( - 'Deactivating virtual environments may not work by default due to a technical limitation in our activation approach, but it can be resolved by appending a line to "{0}". Be sure to restart the shell afterward. [Learn more](https://aka.ms/AAmx2ft).', + 'Deactivating virtual environments may not work by default. To make it work, edit your "{0}" and then restart your shell. [Learn more](https://aka.ms/AAmx2ft).', ); export const activatedCondaEnvLaunch = l10n.t( 'We noticed VS Code was launched from an activated conda environment, would you like to select it?', diff --git a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts index 090ab54c342a..3e463e386545 100644 --- a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts +++ b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { Uri, l10n } from 'vscode'; +import { Uri } from 'vscode'; import * as path from 'path'; import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types'; import { @@ -20,6 +20,7 @@ import { PythonEnvironment } from '../../pythonEnvironments/info'; import { ITerminalEnvVarCollectionService } from '../types'; import { sleep } from '../../common/utils/async'; import { isTestExecution } from '../../common/constants'; +import { PythonEnvType } from '../../pythonEnvironments/base/info'; export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY'; @@ -85,12 +86,13 @@ export class TerminalIndicatorPrompt implements IExtensionSingleActivationServic } const prompts = [Common.doNotShowAgain]; const interpreter = await this.interpreterService.getActiveInterpreter(resource); - if (!interpreter) { + if (!interpreter || !interpreter.type) { return; } const terminalPromptName = getPromptName(interpreter); + const environmentType = interpreter.type === PythonEnvType.Conda ? 'Selected conda' : 'Python virtual'; const selection = await this.appShell.showInformationMessage( - Interpreters.terminalEnvVarCollectionPrompt.format(terminalPromptName), + Interpreters.terminalEnvVarCollectionPrompt.format(environmentType, terminalPromptName), ...prompts, ); if (!selection) { @@ -104,10 +106,10 @@ export class TerminalIndicatorPrompt implements IExtensionSingleActivationServic function getPromptName(interpreter: PythonEnvironment) { if (interpreter.envName) { - return `, ${l10n.t('i.e')} "(${interpreter.envName})"`; + return `"(${interpreter.envName})"`; } if (interpreter.envPath) { - return `, ${l10n.t('i.e')} "(${path.basename(interpreter.envPath)})"`; + return `"(${path.basename(interpreter.envPath)})"`; } - return ''; + return 'environment indicator'; } diff --git a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts index 5d4da49ebb45..2214057fc952 100644 --- a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts +++ b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts @@ -4,7 +4,7 @@ 'use strict'; import { mock, when, anything, instance, verify, reset } from 'ts-mockito'; -import { EventEmitter, Terminal, Uri, l10n } from 'vscode'; +import { EventEmitter, Terminal, Uri } from 'vscode'; import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../../client/common/application/types'; import { IConfigurationService, @@ -20,8 +20,9 @@ import { sleep } from '../../core'; import { IInterpreterService } from '../../../client/interpreter/contracts'; import { PythonEnvironment } from '../../../client/pythonEnvironments/info'; import { ITerminalEnvVarCollectionService } from '../../../client/terminals/types'; +import { PythonEnvType } from '../../../client/pythonEnvironments/base/info'; -suite('Terminal Environment Variable Collection Prompt', () => { +suite('Terminal Activation Indicator Prompt', () => { let shell: IApplicationShell; let terminalManager: ITerminalManager; let experimentService: IExperimentService; @@ -35,7 +36,8 @@ suite('Terminal Environment Variable Collection Prompt', () => { let interpreterService: IInterpreterService; const prompts = [Common.doNotShowAgain]; const envName = 'env'; - const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(`, ${l10n.t('i.e')} "(${envName})"`); + const type = PythonEnvType.Virtual; + const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format('Python virtual', `"(${envName})"`); setup(async () => { shell = mock(); @@ -43,6 +45,7 @@ suite('Terminal Environment Variable Collection Prompt', () => { interpreterService = mock(); when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ envName, + type, } as unknown) as PythonEnvironment); experimentService = mock(); activeResourceService = mock();