@@ -21,6 +21,7 @@ import {
2121 TerminalShellType ,
2222} from './types' ;
2323import { traceVerbose } from '../../logging' ;
24+ import { getConfiguration } from '../vscodeApis/workspaceApis' ;
2425
2526@injectable ( )
2627export class TerminalService implements ITerminalService , Disposable {
@@ -69,17 +70,20 @@ export class TerminalService implements ITerminalService, Disposable {
6970 this . terminal ! . show ( true ) ;
7071 }
7172
72- return this . executeCommand ( text ) ;
73+ return this . executeCommand ( text , false ) ;
7374 }
7475 /** @deprecated */
7576 public async sendText ( text : string ) : Promise < void > {
7677 await this . ensureTerminal ( ) ;
7778 if ( ! this . options ?. hideFromUser ) {
7879 this . terminal ! . show ( true ) ;
7980 }
80- this . terminal ! . sendText ( text ) ;
81+ this . terminal ! . sendText ( text , false ) ;
8182 }
82- public async executeCommand ( commandLine : string ) : Promise < IExecuteCommandResult | undefined > {
83+ public async executeCommand (
84+ commandLine : string ,
85+ isPythonShell : boolean ,
86+ ) : Promise < IExecuteCommandResult | undefined > {
8387 const terminal = this . terminal ! ;
8488 if ( ! this . options ?. hideFromUser ) {
8589 terminal . show ( true ) ;
@@ -102,12 +106,18 @@ export class TerminalService implements ITerminalService, Disposable {
102106 } ) ;
103107 await promise ;
104108 }
105- // python in a shell , exit code is undefined . startCommand event happen, we call end command event
106- if ( terminal . shellIntegration ) {
109+ // If shell integration for python is disabled, use sendText inside REPL regardless of upstream shell integration setting.
110+ const config = getConfiguration ( 'python' ) ;
111+ const pythonrcSetting = config . get < boolean > ( 'terminal.shellIntegration.enabled' ) ;
112+ if ( isPythonShell && ! pythonrcSetting ) {
113+ terminal . sendText ( commandLine ) ;
114+ return undefined ;
115+ } else if ( terminal . shellIntegration ) {
116+ // python in a shell , exit code is undefined . startCommand event happen, we call end command event
107117 // TODO: Await the python REPL execute promise here. So we know python repl launched for sure before executing other python code.
108118 // So we would not be interrupted.
109119
110- await this . serviceContainer . get < ICodeExecutionService > ( ICodeExecutionService ) . replActive ;
120+ // await this.serviceContainer.get<ICodeExecutionService>(ICodeExecutionService).replActive; getting undefined
111121
112122 const execution = terminal . shellIntegration . executeCommand ( commandLine ) ;
113123 traceVerbose ( `Shell Integration is enabled, executeCommand: ${ commandLine } ` ) ;
0 commit comments