From 001450b87d612ee0ac39be1680c2fbc2c0f02f57 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 24 Oct 2023 19:28:51 +0000 Subject: [PATCH 1/4] Improve notification texts for terminal activation --- src/client/common/utils/localize.ts | 4 ++-- .../terminals/envCollectionActivation/indicatorPrompt.ts | 6 +++--- .../interpreters/activation/indicatorPrompt.unit.test.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 538795e022e5..e86cef5fa908 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).', + 'Selected Python environment was successfully activated, even though {0} 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..a6bfe44e14a6 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 { @@ -104,10 +104,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 ''; } diff --git a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts index 5d4da49ebb45..65f96a4942ad 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, @@ -35,7 +35,7 @@ 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 expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(`"(${envName})"`); setup(async () => { shell = mock(); From bac0e7843a6ee737271313cd455c6d2439a61149 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 24 Oct 2023 19:50:55 +0000 Subject: [PATCH 2/4] Improve --- src/client/common/utils/localize.ts | 2 +- .../envCollectionActivation/indicatorPrompt.ts | 10 ++++++---- .../activation/indicatorPrompt.unit.test.ts | 7 +++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index e86cef5fa908..95252b361c76 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -197,7 +197,7 @@ export namespace Interpreters { export const activatingTerminals = l10n.t('Reactivating terminals...'); export const activateTerminalDescription = l10n.t('Activated environment for'); export const terminalEnvVarCollectionPrompt = l10n.t( - 'Selected Python environment was successfully activated, even though {0} may not be present in the terminal prompt. [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...'); diff --git a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts index a6bfe44e14a6..ee03f0b69554 100644 --- a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts +++ b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts @@ -16,10 +16,11 @@ import { Common, Interpreters } from '../../common/utils/localize'; import { IExtensionSingleActivationService } from '../../activation/types'; import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers'; import { IInterpreterService } from '../../interpreter/contracts'; -import { PythonEnvironment } from '../../pythonEnvironments/info'; +import { EnvironmentType, 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) { @@ -109,5 +111,5 @@ function getPromptName(interpreter: PythonEnvironment) { if (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 65f96a4942ad..2214057fc952 100644 --- a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts +++ b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts @@ -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(`"(${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(); From 43dfef61a030e2058b9e79e24c4f2b1581e73509 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 24 Oct 2023 19:52:34 +0000 Subject: [PATCH 3/4] Lint --- .../terminals/envCollectionActivation/indicatorPrompt.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts index ee03f0b69554..4ae7efac09e4 100644 --- a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts +++ b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts @@ -16,7 +16,7 @@ import { Common, Interpreters } from '../../common/utils/localize'; import { IExtensionSingleActivationService } from '../../activation/types'; import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers'; import { IInterpreterService } from '../../interpreter/contracts'; -import { EnvironmentType, PythonEnvironment } from '../../pythonEnvironments/info'; +import { PythonEnvironment } from '../../pythonEnvironments/info'; import { ITerminalEnvVarCollectionService } from '../types'; import { sleep } from '../../common/utils/async'; import { isTestExecution } from '../../common/constants'; @@ -69,7 +69,7 @@ export class TerminalIndicatorPrompt implements IExtensionSingleActivationServic } if (this.terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)) { // No need to show notification if terminal prompt already indicates when env is activated. - return; + // return; } await this.notifyUsers(resource); }), From f9a6b05a286157492d71894b99519dd22620d81c Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 24 Oct 2023 19:52:57 +0000 Subject: [PATCH 4/4] z --- src/client/terminals/envCollectionActivation/indicatorPrompt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts index 4ae7efac09e4..3e463e386545 100644 --- a/src/client/terminals/envCollectionActivation/indicatorPrompt.ts +++ b/src/client/terminals/envCollectionActivation/indicatorPrompt.ts @@ -69,7 +69,7 @@ export class TerminalIndicatorPrompt implements IExtensionSingleActivationServic } if (this.terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)) { // No need to show notification if terminal prompt already indicates when env is activated. - // return; + return; } await this.notifyUsers(resource); }),