Add "Don't Show Again" to env file notification by Copilot · Pull Request #1393 · microsoft/vscode-python-environments · GitHub
Skip to content
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
4 changes: 4 additions & 0 deletions src/common/localize.ts
31 changes: 26 additions & 5 deletions src/features/terminal/terminalEnvVarInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import {
Disposable,
EnvironmentVariableScope,
GlobalEnvironmentVariableCollection,
window,
workspace,
WorkspaceFolder,
} from 'vscode';
import { traceError, traceVerbose } from '../../common/logging';
import { ActivationStrings, Common } from '../../common/localize';
import { traceError, traceLog, traceVerbose } from '../../common/logging';
import { getGlobalPersistentState } from '../../common/persistentState';
import { resolveVariables } from '../../common/utils/internalVariables';
import { showInformationMessage } from '../../common/window.apis';
import { getConfiguration, getWorkspaceFolder } from '../../common/workspace.apis';
import { EnvVarManager } from '../execution/envVariableManager';

export const ENV_FILE_NOTIFICATION_DONT_SHOW_KEY = 'python-envs:terminal:ENV_FILE_NOTIFICATION_DONT_SHOW';

/**
* Manages injection of workspace-specific environment variables into VS Code terminals
* using the GlobalEnvironmentVariableCollection API.
Expand Down Expand Up @@ -65,9 +69,9 @@ export class TerminalEnvVarInjector implements Disposable {

// Only show notification when env vars change and we have an env file but injection is disabled
if (!useEnvFile && envFilePath) {
window.showInformationMessage(
'An environment file is configured but terminal environment injection is disabled. Enable "python.terminal.useEnvFile" to use environment variables from .env files in terminals.',
);
this.showEnvFileNotification().catch((error) => {
traceError('Failed to show env file notification:', error);
});
}

if (args.changeType === 2) {
Expand Down Expand Up @@ -208,6 +212,23 @@ export class TerminalEnvVarInjector implements Disposable {
}
}

/**
* Show a notification about env file injection being disabled, with a "Don't Show Again" option.
*/
private async showEnvFileNotification(): Promise<void> {
const state = await getGlobalPersistentState();
const dontShow = await state.get<boolean>(ENV_FILE_NOTIFICATION_DONT_SHOW_KEY);
if (dontShow) {
return;
}

const result = await showInformationMessage(ActivationStrings.envFileInjectionDisabled, Common.dontShowAgain);
if (result === Common.dontShowAgain) {
await state.set(ENV_FILE_NOTIFICATION_DONT_SHOW_KEY, true);
traceLog(`User selected "Don't Show Again" for env file notification`);
}
}

/**
* Dispose of the injector and clean up resources.
*/
Expand Down
129 changes: 128 additions & 1 deletion src/test/features/terminalEnvVarInjector.unit.test.ts
Loading