@@ -28,9 +28,19 @@ export function getCallingExtension(): string {
28
28
const extensions = allExtensions ( ) ;
29
29
const otherExts = extensions . filter ( ( ext ) => ! pythonExts . includes ( ext . id ) ) ;
30
30
const frames = getFrameData ( ) ;
31
- const filePaths : string [ ] = [ ] ;
32
31
33
- for ( const frame of frames ) {
32
+ const registerEnvManagerFrameIndex = frames . findIndex (
33
+ ( frame ) =>
34
+ frame . functionName &&
35
+ ( frame . functionName . includes ( 'registerEnvironmentManager' ) ||
36
+ frame . functionName . includes ( 'registerPackageManager' ) ) ,
37
+ ) ;
38
+
39
+ const relevantFrames =
40
+ registerEnvManagerFrameIndex !== - 1 ? frames . slice ( registerEnvManagerFrameIndex + 1 ) : frames ;
41
+
42
+ const filePaths : string [ ] = [ ] ;
43
+ for ( const frame of relevantFrames ) {
34
44
if ( ! frame || ! frame . filePath ) {
35
45
continue ;
36
46
}
@@ -55,25 +65,24 @@ export function getCallingExtension(): string {
55
65
}
56
66
}
57
67
58
- // `ms-python.vscode-python-envs` extension in Development mode
59
- const candidates = filePaths . filter ( ( filePath ) =>
60
- otherExts . some ( ( s ) => filePath . includes ( normalizePath ( s . extensionPath ) ) ) ,
61
- ) ;
62
68
const envExt = getExtension ( ENVS_EXTENSION_ID ) ;
63
-
64
- if ( ! envExt ) {
69
+ const pythonExt = getExtension ( PYTHON_EXTENSION_ID ) ;
70
+ if ( ! envExt || ! pythonExt ) {
65
71
throw new Error ( 'Something went wrong with feature registration' ) ;
66
72
}
67
73
const envsExtPath = normalizePath ( envExt . extensionPath ) ;
68
- if ( candidates . length === 0 && filePaths . every ( ( filePath ) => filePath . startsWith ( envsExtPath ) ) ) {
74
+
75
+ if ( filePaths . every ( ( filePath ) => filePath . startsWith ( envsExtPath ) ) ) {
69
76
return PYTHON_EXTENSION_ID ;
70
- } else if ( candidates . length > 0 ) {
71
- // 3rd party extension in Development mode
72
- const candidateExt = otherExts . find ( ( ext ) => candidates [ 0 ] . includes ( ext . extensionPath ) ) ;
73
- if ( candidateExt ) {
74
- return candidateExt . id ;
77
+ }
78
+
79
+ for ( const ext of otherExts ) {
80
+ const extPath = normalizePath ( ext . extensionPath ) ;
81
+ if ( filePaths . some ( ( filePath ) => filePath . startsWith ( extPath ) ) ) {
82
+ return ext . id ;
75
83
}
76
84
}
77
85
78
- throw new Error ( 'Unable to determine calling extension id, registration failed' ) ;
86
+ // Fallback - we're likely being called from Python extension in conda registration
87
+ return PYTHON_EXTENSION_ID ;
79
88
}
0 commit comments