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
39 changes: 24 additions & 15 deletions src/common/utils/frameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ export function getCallingExtension(): string {
const extensions = allExtensions();
const otherExts = extensions.filter((ext) => !pythonExts.includes(ext.id));
const frames = getFrameData();
const filePaths: string[] = [];

for (const frame of frames) {
const registerEnvManagerFrameIndex = frames.findIndex(
(frame) =>
frame.functionName &&
(frame.functionName.includes('registerEnvironmentManager') ||
frame.functionName.includes('registerPackageManager')),
);

const relevantFrames =
registerEnvManagerFrameIndex !== -1 ? frames.slice(registerEnvManagerFrameIndex + 1) : frames;

const filePaths: string[] = [];
for (const frame of relevantFrames) {
if (!frame || !frame.filePath) {
continue;
}
Expand All @@ -55,25 +65,24 @@ export function getCallingExtension(): string {
}
}

// `ms-python.vscode-python-envs` extension in Development mode
const candidates = filePaths.filter((filePath) =>
otherExts.some((s) => filePath.includes(normalizePath(s.extensionPath))),
);
const envExt = getExtension(ENVS_EXTENSION_ID);

if (!envExt) {
const pythonExt = getExtension(PYTHON_EXTENSION_ID);
if (!envExt || !pythonExt) {
throw new Error('Something went wrong with feature registration');
}
const envsExtPath = normalizePath(envExt.extensionPath);
if (candidates.length === 0 && filePaths.every((filePath) => filePath.startsWith(envsExtPath))) {

if (filePaths.every((filePath) => filePath.startsWith(envsExtPath))) {
return PYTHON_EXTENSION_ID;
} else if (candidates.length > 0) {
// 3rd party extension in Development mode
const candidateExt = otherExts.find((ext) => candidates[0].includes(ext.extensionPath));
if (candidateExt) {
return candidateExt.id;
}

for (const ext of otherExts) {
const extPath = normalizePath(ext.extensionPath);
if (filePaths.some((filePath) => filePath.startsWith(extPath))) {
return ext.id;
}
}

throw new Error('Unable to determine calling extension id, registration failed');
// Fallback - we're likely being called from Python extension in conda registration
return PYTHON_EXTENSION_ID;
}
7 changes: 5 additions & 2 deletions src/features/envManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ export class PythonEnvironmentManagers implements EnvironmentManagers {
const manager = this.getEnvironmentManager(customScope);
if (!manager) {
traceError(
`No environment manager found for: ${
`No environment manager found for scope: ${
customScope instanceof Uri ? customScope.fsPath : customScope?.environmentPath?.fsPath
}`,
);

traceError(this.managers.map((m) => m.id).join(', '));
return;
}
await manager.set(scope, environment);
Expand Down Expand Up @@ -297,10 +299,11 @@ export class PythonEnvironmentManagers implements EnvironmentManagers {
const manager = this.managers.find((m) => m.id === environment.envId.managerId);
if (!manager) {
traceError(
`No environment manager found for: ${
`No environment manager found for [${environment.envId.managerId}]: ${
environment.environmentPath ? environment.environmentPath.fsPath : ''
}`,
);
traceError(this.managers.map((m) => m.id).join(', '));
return;
}

Expand Down