Skip to content

Commit 2044f83

Browse files
committed
figure out if we are inside Python REPL
1 parent c7a1504 commit 2044f83

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/client/common/terminal/service.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
TerminalShellType,
2222
} from './types';
2323
import { traceVerbose } from '../../logging';
24+
import { getConfiguration } from '../vscodeApis/workspaceApis';
2425

2526
@injectable()
2627
export 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}`);

src/client/common/terminal/syncTerminalService.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ export class SynchronousTerminalService implements ITerminalService, Disposable
145145
public sendText(text: string): Promise<void> {
146146
return this.terminalService.sendText(text);
147147
}
148-
public async executeCommand(commandLine: string): Promise<IExecuteCommandResult | undefined> {
149-
return this.terminalService.executeCommand(commandLine);
148+
public async executeCommand(
149+
commandLine: string,
150+
isPythonShell: boolean,
151+
): Promise<IExecuteCommandResult | undefined> {
152+
return this.terminalService.executeCommand(commandLine, isPythonShell);
150153
}
151154
public show(preserveFocus?: boolean | undefined): Promise<void> {
152155
return this.terminalService.show(preserveFocus);

src/client/common/terminal/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface ITerminalService extends IDisposable {
5454
): Promise<IExecuteCommandResult | undefined>;
5555
/** @deprecated */
5656
sendText(text: string): Promise<void>;
57-
executeCommand(commandLine: string): Promise<IExecuteCommandResult | undefined>;
57+
executeCommand(commandLine: string, isPythonShell: boolean): Promise<IExecuteCommandResult | undefined>;
5858
show(preserveFocus?: boolean): Promise<void>;
5959
}
6060

src/client/terminals/codeExecution/terminalCodeExecution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
5959
this.configurationService.updateSetting('REPL.enableREPLSmartSend', false, resource);
6060
}
6161
} else {
62-
await this.getTerminalService(resource).executeCommand(code);
62+
await this.getTerminalService(resource).executeCommand(code, true);
6363
}
6464
}
6565

0 commit comments

Comments
 (0)