Skip to content

Commit

Permalink
Improve notification texts for terminal activation (#22323)
Browse files Browse the repository at this point in the history
Closes #22316
  • Loading branch information
Kartik Raj authored Oct 24, 2023
1 parent 9e07503 commit 3c88f27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down
14 changes: 8 additions & 6 deletions src/client/terminals/envCollectionActivation/indicatorPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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';

Expand Down Expand Up @@ -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) {
Expand All @@ -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';
}
9 changes: 6 additions & 3 deletions src/test/interpreters/activation/indicatorPrompt.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -35,14 +36,16 @@ 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<IApplicationShell>();
terminalManager = mock<ITerminalManager>();
interpreterService = mock<IInterpreterService>();
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
envName,
type,
} as unknown) as PythonEnvironment);
experimentService = mock<IExperimentService>();
activeResourceService = mock<IActiveResourceService>();
Expand Down

0 comments on commit 3c88f27

Please sign in to comment.