Skip to content

Commit 46f6a0e

Browse files
committed
fix: prevent duplicate setting error dialogs when global scope is deferred
Add a module-level warnedSettings Set in notifyUserOfSettingErrors to skip settings that have already been warned about. This handles the edge case where a user-level misconfiguration (e.g. defaultEnvManager) produces errors in both workspace and deferred global scope resolution. Addresses review feedback from StellaHuang95 on PR #1456.
1 parent aab1027 commit 46f6a0e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/features/interpreterSelection.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,26 @@ export async function applyInitialEnvironmentSelection(
407407
/**
408408
* Notify the user when their configured settings could not be applied.
409409
* Shows a warning message with an option to open settings.
410+
* Tracks already-warned settings to avoid duplicate dialogs (e.g., when
411+
* the same user-level misconfiguration is hit by both workspace and
412+
* deferred global scope resolution).
410413
*/
414+
const warnedSettings = new Set<string>();
415+
416+
export function resetSettingWarnings(): void {
417+
warnedSettings.clear();
418+
}
419+
411420
async function notifyUserOfSettingErrors(errors: SettingResolutionError[]): Promise<void> {
412421
// Group errors by setting type to avoid spamming the user
413422
const uniqueSettings = [...new Set(errors.map((e) => e.setting))];
414423

415424
for (const setting of uniqueSettings) {
425+
if (warnedSettings.has(setting)) {
426+
continue;
427+
}
428+
warnedSettings.add(setting);
429+
416430
const settingErrors = errors.filter((e) => e.setting === setting);
417431
const firstError = settingErrors[0];
418432

src/test/features/interpreterSelection.unit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as workspaceApis from '../../common/workspace.apis';
1111
import {
1212
applyInitialEnvironmentSelection,
1313
registerInterpreterSettingsChangeListener,
14+
resetSettingWarnings,
1415
resolveEnvironmentByPriority,
1516
resolveGlobalEnvironmentByPriority,
1617
} from '../../features/interpreterSelection';
@@ -552,6 +553,7 @@ suite('Interpreter Selection - applyInitialEnvironmentSelection', () => {
552553

553554
setup(() => {
554555
sandbox = sinon.createSandbox();
556+
resetSettingWarnings();
555557

556558
mockVenvManager = {
557559
id: 'ms-python.python:venv',

0 commit comments

Comments
 (0)