@@ -16,7 +16,7 @@ import { getConfiguration, onDidChangeConfiguration } from '../../common/workspa
1616import { isActivatableEnvironment } from '../common/activation' ;
1717import { identifyTerminalShell } from '../common/shellDetector' ;
1818import { getPythonApi } from '../pythonApi' ;
19- import { shellIntegrationForActiveTerminal } from './shells/common/shellUtils' ;
19+ import { isWsl , shellIntegrationForActiveTerminal } from './shells/common/shellUtils' ;
2020import { ShellEnvsProvider , ShellSetupState , ShellStartupScriptProvider } from './shells/startupProvider' ;
2121import { handleSettingUpShellProfile } from './shellStartupSetupHandlers' ;
2222import {
@@ -129,7 +129,9 @@ export class TerminalManagerImpl implements TerminalManager {
129129 await this . handleSetupCheck ( shells ) ;
130130 }
131131 } else {
132- traceVerbose ( `Auto activation type changed to ${ actType } ` ) ;
132+ traceVerbose ( `Auto activation type changed to ${ actType } , we are cleaning up shell startup setup` ) ;
133+ // Teardown scripts when switching away from shell startup activation
134+ await Promise . all ( this . startupScriptProviders . map ( ( p ) => p . teardownScripts ( ) ) ) ;
133135 this . shellSetup . clear ( ) ;
134136 }
135137 }
@@ -143,41 +145,42 @@ export class TerminalManagerImpl implements TerminalManager {
143145 private async handleSetupCheck ( shellType : string | Set < string > ) : Promise < void > {
144146 const shellTypes = typeof shellType === 'string' ? new Set ( [ shellType ] ) : shellType ;
145147 const providers = this . startupScriptProviders . filter ( ( p ) => shellTypes . has ( p . shellType ) ) ;
146- if ( providers . length > 0 ) {
148+ if ( providers . length > 0 ) {
147149 const shellsToSetup : ShellStartupScriptProvider [ ] = [ ] ;
148150 await Promise . all (
149151 providers . map ( async ( p ) => {
150152 const state = await p . isSetup ( ) ;
153+ const currentSetup = ( state === ShellSetupState . Setup ) ;
154+ // Check if we already processed this shell and the state hasn't changed
151155 if ( this . shellSetup . has ( p . shellType ) ) {
152- // This ensures modified scripts are detected even after initial setup
153156 const cachedSetup = this . shellSetup . get ( p . shellType ) ;
154- if ( ( state === ShellSetupState . Setup ) !== cachedSetup ) {
155- traceVerbose ( `Shell profile for ${ p . shellType } state changed, updating cache.` ) ;
156- // State changed - clear cache and re-evaluate
157- this . shellSetup . delete ( p . shellType ) ;
158- } else {
159- traceVerbose ( `Shell profile for ${ p . shellType } already checked.` ) ;
157+ if ( currentSetup === cachedSetup ) {
158+ traceVerbose ( `Shell profile for ${ p . shellType } already checked, state unchanged.` ) ;
160159 return ;
161160 }
161+ traceVerbose ( `Shell profile for ${ p . shellType } state changed from ${ cachedSetup } to ${ currentSetup } , re-evaluating.` ) ;
162162 }
163163 traceVerbose ( `Checking shell profile for ${ p . shellType } .` ) ;
164164 if ( state === ShellSetupState . NotSetup ) {
165- if ( shellIntegrationForActiveTerminal ( p . name ) ) {
165+ traceVerbose ( `WSL detected: ${ isWsl ( ) } , Shell integration available: ${ shellIntegrationForActiveTerminal ( p . name ) } ` ) ;
166+
167+ if ( shellIntegrationForActiveTerminal ( p . name ) && ! isWsl ( ) ) {
168+ // Shell integration available and NOT in WSL - skip setup
166169 await p . teardownScripts ( ) ;
167170 this . shellSetup . set ( p . shellType , true ) ;
168171 traceVerbose (
169- `Shell integration available for ${ p . shellType } , skipping prompt, and profile modification.` ,
172+ `Shell integration available for ${ p . shellType } (not WSL) , skipping prompt, and profile modification.` ,
170173 ) ;
171174 } else {
172- // No shell integration, mark for setup
175+ // WSL (regardless of integration) OR no shell integration - needs setup
173176 this . shellSetup . set ( p . shellType , false ) ;
174177 shellsToSetup . push ( p ) ;
175178 traceVerbose (
176- `Shell integration is NOT avaoiable . Shell profile for ${ p . shellType } is not setup.` ,
179+ `Shell integration is NOT available . Shell profile for ${ p . shellType } is not setup.` ,
177180 ) ;
178181 }
179182 } else if ( state === ShellSetupState . Setup ) {
180- if ( shellIntegrationForActiveTerminal ( p . name ) ) {
183+ if ( shellIntegrationForActiveTerminal ( p . name ) && ! isWsl ( ) ) {
181184 await p . teardownScripts ( ) ;
182185 traceVerbose (
183186 `Shell integration available for ${ p . shellType } , removed profile script in favor of shell integration.` ,
0 commit comments