@@ -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 { isWsl , shellIntegrationForActiveTerminal } from './shells/common/shellUtils' ;
19+ import { getShellIntegrationEnabledCache , isWsl , shellIntegrationForActiveTerminal } from './shells/common/shellUtils' ;
2020import { ShellEnvsProvider , ShellSetupState , ShellStartupScriptProvider } from './shells/startupProvider' ;
2121import { handleSettingUpShellProfile } from './shellStartupSetupHandlers' ;
2222import {
@@ -137,6 +137,20 @@ export class TerminalManagerImpl implements TerminalManager {
137137 this . shellSetup . clear ( ) ;
138138 }
139139 }
140+ if ( e . affectsConfiguration ( 'terminal.integrated.shellIntegration.enabled' ) ) {
141+ traceInfo ( 'Shell integration setting changed, invalidating cache' ) ;
142+ const updatedShellIntegrationSetting = await getShellIntegrationEnabledCache ( ) ;
143+ if ( ! updatedShellIntegrationSetting ) {
144+ const shells = new Set (
145+ terminals ( )
146+ . map ( ( t ) => identifyTerminalShell ( t ) )
147+ . filter ( ( t ) => t !== 'unknown' ) ,
148+ ) ;
149+ if ( shells . size > 0 ) {
150+ await this . handleSetupCheck ( shells ) ;
151+ }
152+ }
153+ }
140154 } ) ,
141155 onDidChangeWindowState ( ( e ) => {
142156 this . hasFocus = e . focused ;
@@ -152,27 +166,19 @@ export class TerminalManagerImpl implements TerminalManager {
152166 await Promise . all (
153167 providers . map ( async ( p ) => {
154168 const state = await p . isSetup ( ) ;
155- const currentSetup = state === ShellSetupState . Setup ;
156- // Check if we already processed this shell and the state hasn't changed
157- if ( this . shellSetup . has ( p . shellType ) ) {
158- const cachedSetup = this . shellSetup . get ( p . shellType ) ;
159- if ( currentSetup === cachedSetup ) {
160- traceVerbose ( `Shell profile for ${ p . shellType } already checked, state unchanged.` ) ;
161- return ;
162- }
163- traceVerbose (
164- `Shell profile for ${ p . shellType } state changed from ${ cachedSetup } to ${ currentSetup } , re-evaluating.` ,
165- ) ;
166- }
167- traceVerbose ( `Checking shell profile for ${ p . shellType } .` ) ;
169+ const shellIntegrationEnabled = await getShellIntegrationEnabledCache ( ) ;
170+ traceVerbose ( `Checking shell profile for ${ p . shellType } , with state: ${ state } ` ) ;
168171 if ( state === ShellSetupState . NotSetup ) {
169172 traceVerbose (
170- `WSL detected: ${ isWsl ( ) } , Shell integration available: ${ await shellIntegrationForActiveTerminal (
173+ `WSL detected: ${ isWsl ( ) } , Shell integration available from setting, or active terminal: ${ shellIntegrationEnabled } , or ${ await shellIntegrationForActiveTerminal (
171174 p . name ,
172175 ) } `,
173176 ) ;
174177
175- if ( ( await shellIntegrationForActiveTerminal ( p . name ) ) && ! isWsl ( ) ) {
178+ if (
179+ ( shellIntegrationEnabled || ( await shellIntegrationForActiveTerminal ( p . name ) ) ) &&
180+ ! isWsl ( )
181+ ) {
176182 // Shell integration available and NOT in WSL - skip setup
177183 await p . teardownScripts ( ) ;
178184 this . shellSetup . set ( p . shellType , true ) ;
@@ -188,7 +194,10 @@ export class TerminalManagerImpl implements TerminalManager {
188194 ) ;
189195 }
190196 } else if ( state === ShellSetupState . Setup ) {
191- if ( ( await shellIntegrationForActiveTerminal ( p . name ) ) && ! isWsl ( ) ) {
197+ if (
198+ ( shellIntegrationEnabled || ( await shellIntegrationForActiveTerminal ( p . name ) ) ) &&
199+ ! isWsl ( )
200+ ) {
192201 await p . teardownScripts ( ) ;
193202 traceVerbose (
194203 `Shell integration available for ${ p . shellType } , removed profile script in favor of shell integration.` ,
@@ -213,10 +222,42 @@ export class TerminalManagerImpl implements TerminalManager {
213222 return ;
214223 }
215224
216- setImmediate ( async ( ) => {
217- // Avoid blocking this setup on user interaction.
218- await handleSettingUpShellProfile ( shellsToSetup , ( p , v ) => this . shellSetup . set ( p . shellType , v ) ) ;
219- } ) ;
225+ if ( ! ( await getShellIntegrationEnabledCache ( ) ) ) {
226+ // Shell integration is disabled - prompt for ALL shells
227+ setImmediate ( async ( ) => {
228+ // Avoid blocking this setup on user interaction.
229+ await handleSettingUpShellProfile ( shellsToSetup , ( p , v ) => this . shellSetup . set ( p . shellType , v ) ) ;
230+ } ) ;
231+ traceVerbose ( 'Shell integration is not available, prompting for shell modifications' ) ;
232+ } else {
233+ // // Shell integration is enabled - only prompt for CMD shells
234+ // // (CMD doesn't support shell integration well, so we still need profile modification)
235+ // const cmdShellsToSetup = shellsToSetup.filter((p) => p.shellType === ShellConstants.CMD);
236+ // const nonCmdShells = shellsToSetup.filter((p) => p.shellType !== ShellConstants.CMD);
237+
238+ // // Mark non-CMD shells as setup complete since they'll use shell integration
239+ // nonCmdShells.forEach((p) => {
240+ // this.shellSetup.set(p.shellType, true);
241+ // traceVerbose(
242+ // `Shell integration is enabled for ${p.shellType}, marking as setup complete (will use shell integration instead of profile modification).`,
243+ // );
244+ // });
245+
246+ // if (cmdShellsToSetup.length > 0) {
247+ // setImmediate(async () => {
248+ // await handleSettingUpShellProfile(cmdShellsToSetup, (p, v) =>
249+ // this.shellSetup.set(p.shellType, v),
250+ // );
251+ // });
252+ // } else {
253+ // traceVerbose('Shell integration is enabled and no CMD shells need setup.');
254+ // }
255+ setImmediate ( async ( ) => {
256+ // Avoid blocking this setup on user interaction.
257+ await handleSettingUpShellProfile ( shellsToSetup , ( p , v ) => this . shellSetup . set ( p . shellType , v ) ) ;
258+ } ) ;
259+ traceVerbose ( 'Shell integration is available, prompt for shell modification if needed' ) ;
260+ }
220261 }
221262 }
222263
0 commit comments