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
76 changes: 75 additions & 1 deletion src/features/settings/settingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { PythonProject } from '../../api';
import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants';
import { traceError, traceInfo, traceWarn } from '../../common/logging';
import { getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis';
import { getConfiguration, getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis';
import { PythonProjectManager, PythonProjectSettings } from '../../internal.api';

function getSettings(
Expand Down Expand Up @@ -393,3 +393,77 @@ export async function removePythonProjectSetting(edits: EditProjectSettings[]):
});
await Promise.all(promises);
}

/**
* Gets user-configured setting for window-scoped settings.
* Priority order: globalRemoteValue > globalLocalValue > globalValue
* @param section - The configuration section (e.g., 'python-envs')
* @param key - The configuration key (e.g., 'terminal.autoActivationType')
* @returns The user-configured value or undefined if not set by user
*/
export function getSettingWindowScope<T>(section: string, key: string): T | undefined {
const config = getConfiguration(section);
const inspect = config.inspect<T>(key);
if (!inspect) {
return undefined;
}

const inspectRecord = inspect as Record<string, unknown>;
if ('globalRemoteValue' in inspect && inspectRecord.globalRemoteValue !== undefined) {
return inspectRecord.globalRemoteValue as T;
}
if ('globalLocalValue' in inspect && inspectRecord.globalLocalValue !== undefined) {
return inspectRecord.globalLocalValue as T;
}
if (inspect.globalValue !== undefined) {
return inspect.globalValue;
}
return undefined;
}

/**
* Gets user-configured setting for workspace-scoped settings.
* Priority order: workspaceFolderValue > workspaceValue > globalValue
* @param section - The configuration section (e.g., 'python')
* @param key - The configuration key (e.g., 'pipenvPath')
* @param scope - Optional URI scope for workspace folder-specific settings
* @returns The user-configured value or undefined if not set by user
*/
export function getSettingWorkspaceScope<T>(section: string, key: string, scope?: Uri): T | undefined {
const config = getConfiguration(section, scope);
const inspect = config.inspect<T>(key);
if (!inspect) {
return undefined;
}

if (inspect.workspaceFolderValue !== undefined) {
return inspect.workspaceFolderValue;
}
if (inspect.workspaceValue !== undefined) {
return inspect.workspaceValue;
}
if (inspect.globalValue !== undefined) {
return inspect.globalValue;
}
return undefined;
}

/**
* Gets user-configured setting for user-scoped settings.
* Only checks globalValue (ignores defaultValue).
* @param section - The configuration section (e.g., 'python')
* @param key - The configuration key (e.g., 'pipenvPath')
* @returns The user-configured value or undefined if not set by user
*/
export function getSettingUserScope<T>(section: string, key: string): T | undefined {
const config = getConfiguration(section);
const inspect = config.inspect<T>(key);
if (!inspect) {
return undefined;
}

if (inspect.globalValue !== undefined) {
return inspect.globalValue;
}
return undefined;
}
10 changes: 9 additions & 1 deletion src/managers/pipenv/pipenvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { ENVS_EXTENSION_ID } from '../../common/constants';
import { traceError, traceInfo } from '../../common/logging';
import { getWorkspacePersistentState } from '../../common/persistentState';
import { getSettingWorkspaceScope } from '../../features/settings/settingHelpers';
import {
isNativeEnvInfo,
NativeEnvInfo,
Expand Down Expand Up @@ -46,6 +47,11 @@ export async function clearPipenvCache(): Promise<void> {
pipenvPath = undefined;
}

function getPipenvPathFromSettings(): Uri[] {
const pipenvPath = getSettingWorkspaceScope<string>('python', 'pipenvPath');
return pipenvPath ? [Uri.file(pipenvPath)] : [];
}

export async function getPipenv(native?: NativePythonFinder): Promise<string | undefined> {
if (pipenvPath) {
return pipenvPath;
Expand Down Expand Up @@ -140,7 +146,9 @@ export async function refreshPipenv(
manager: EnvironmentManager,
): Promise<PythonEnvironment[]> {
traceInfo('Refreshing pipenv environments');
const data = await nativeFinder.refresh(hardRefresh);

const searchUris = getPipenvPathFromSettings();
const data = await nativeFinder.refresh(hardRefresh, searchUris.length > 0 ? searchUris : undefined);

let pipenv = await getPipenv();

Expand Down
Loading