@@ -28,9 +28,19 @@ export function getCallingExtension(): string {
2828 const extensions = allExtensions ( ) ;
2929 const otherExts = extensions . filter ( ( ext ) => ! pythonExts . includes ( ext . id ) ) ;
3030 const frames = getFrameData ( ) ;
31- const filePaths : string [ ] = [ ] ;
3231
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 ) {
3444 if ( ! frame || ! frame . filePath ) {
3545 continue ;
3646 }
@@ -55,25 +65,24 @@ export function getCallingExtension(): string {
5565 }
5666 }
5767
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- ) ;
6268 const envExt = getExtension ( ENVS_EXTENSION_ID ) ;
63-
64- if ( ! envExt ) {
69+ const pythonExt = getExtension ( PYTHON_EXTENSION_ID ) ;
70+ if ( ! envExt || ! pythonExt ) {
6571 throw new Error ( 'Something went wrong with feature registration' ) ;
6672 }
6773 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 ) ) ) {
6976 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 ;
7583 }
7684 }
7785
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 ;
7988}
0 commit comments