Skip to content

Commit 142555b

Browse files
committed
fix: use inspect() to check for explicit setting values
The previous code used config.get() which may return defaultValue from other extensions' package.json (like ms-python.python setting useEnvironmentsExtension to false) even when those extensions aren't installed. Now we use inspect() to check if the setting has been explicitly set by the user (globalValue, workspaceValue, or workspaceFolderValue). If not explicitly set, we default to true, allowing the extension to activate properly in test environments and clean VS Code instances.
1 parent 2b8619f commit 142555b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/extension.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,25 @@ import { registerPoetryFeatures } from './managers/poetry/main';
8787
import { registerPyenvFeatures } from './managers/pyenv/main';
8888

8989
export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi | undefined> {
90-
// In smoke/e2e/integration tests, skip the useEnvironmentsExtension check since ms-python.python isn't installed
90+
// Check for explicit test environment (set via .vscode-test.mjs env vars)
9191
const isTestEnvironment = process.env.VSC_PYTHON_SMOKE_TEST === '1' ||
9292
process.env.VSC_PYTHON_E2E_TEST === '1' ||
9393
process.env.VSC_PYTHON_INTEGRATION_TEST === '1';
9494

95+
// Use inspect() to check if the setting has been explicitly set by the user.
96+
// This is important because config.get() may return a defaultValue from other
97+
// extensions' package.json (like ms-python.python setting it to false), even
98+
// when those extensions aren't installed.
99+
const config = getConfiguration('python');
100+
const inspection = config.inspect<boolean>('useEnvironmentsExtension');
101+
102+
// If no one has explicitly set this setting, default to true
103+
const hasExplicitValue = inspection?.globalValue !== undefined ||
104+
inspection?.workspaceValue !== undefined ||
105+
inspection?.workspaceFolderValue !== undefined;
106+
95107
const useEnvironmentsExtension = isTestEnvironment ||
96-
getConfiguration('python').get<boolean>('useEnvironmentsExtension', true);
108+
(hasExplicitValue ? config.get<boolean>('useEnvironmentsExtension', true) : true);
97109
traceInfo(`Experiment Status: useEnvironmentsExtension setting set to ${useEnvironmentsExtension}`);
98110
if (!useEnvironmentsExtension) {
99111
traceWarn(

0 commit comments

Comments
 (0)