Skip to content

Commit 7afffd3

Browse files
committed
do not use shell integration for Python subshell if Python setting is disabled
1 parent b1cb5c2 commit 7afffd3

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

src/client/common/terminal/service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
TerminalShellType,
2121
} from './types';
2222
import { traceVerbose } from '../../logging';
23+
import { getConfiguration } from '../vscodeApis/workspaceApis';
2324

2425
@injectable()
2526
export class TerminalService implements ITerminalService, Disposable {
@@ -64,7 +65,7 @@ export class TerminalService implements ITerminalService, Disposable {
6465
this.terminal!.show(true);
6566
}
6667

67-
await this.executeCommand(text);
68+
await this.executeCommand(text, false);
6869
}
6970
/** @deprecated */
7071
public async sendText(text: string): Promise<void> {
@@ -74,7 +75,10 @@ export class TerminalService implements ITerminalService, Disposable {
7475
}
7576
this.terminal!.sendText(text);
7677
}
77-
public async executeCommand(commandLine: string): Promise<TerminalShellExecution | undefined> {
78+
public async executeCommand(
79+
commandLine: string,
80+
isPythonShell: boolean,
81+
): Promise<TerminalShellExecution | undefined> {
7882
const terminal = this.terminal!;
7983
if (!this.options?.hideFromUser) {
8084
terminal.show(true);
@@ -98,7 +102,13 @@ export class TerminalService implements ITerminalService, Disposable {
98102
await promise;
99103
}
100104

101-
if (terminal.shellIntegration) {
105+
const config = getConfiguration('python');
106+
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
107+
if (isPythonShell && !pythonrcSetting) {
108+
// If user has explicitly disabled SI for Python, use sendText for inside Terminal REPL.
109+
terminal.sendText(commandLine);
110+
return undefined;
111+
} else if (terminal.shellIntegration) {
102112
const execution = terminal.shellIntegration.executeCommand(commandLine);
103113
traceVerbose(`Shell Integration is enabled, executeCommand: ${commandLine}`);
104114
return execution;

src/client/common/terminal/syncTerminalService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export class SynchronousTerminalService implements ITerminalService, Disposable
145145
public sendText(text: string): Promise<void> {
146146
return this.terminalService.sendText(text);
147147
}
148-
public executeCommand(commandLine: string): Promise<TerminalShellExecution | undefined> {
149-
return this.terminalService.executeCommand(commandLine);
148+
public executeCommand(commandLine: string, isPythonShell: boolean): Promise<TerminalShellExecution | undefined> {
149+
return this.terminalService.executeCommand(commandLine, isPythonShell);
150150
}
151151
public show(preserveFocus?: boolean | undefined): Promise<void> {
152152
return this.terminalService.show(preserveFocus);

src/client/common/terminal/types.ts

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

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 1 addition & 1 deletion
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

src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,10 @@ suite('Terminal - Code Execution', () => {
643643
terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs);
644644

645645
await executor.execute('cmd1');
646-
terminalService.verify(async (t) => t.executeCommand('cmd1'), TypeMoq.Times.once());
646+
terminalService.verify(async (t) => t.executeCommand('cmd1', false), TypeMoq.Times.once());
647647

648648
await executor.execute('cmd2');
649-
terminalService.verify(async (t) => t.executeCommand('cmd2'), TypeMoq.Times.once());
649+
terminalService.verify(async (t) => t.executeCommand('cmd2', false), TypeMoq.Times.once());
650650
});
651651

652652
test('Ensure code is sent to the same terminal for a particular resource', async () => {
@@ -668,10 +668,10 @@ suite('Terminal - Code Execution', () => {
668668
terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs);
669669

670670
await executor.execute('cmd1', resource);
671-
terminalService.verify(async (t) => t.executeCommand('cmd1'), TypeMoq.Times.once());
671+
terminalService.verify(async (t) => t.executeCommand('cmd1', false), TypeMoq.Times.once());
672672

673673
await executor.execute('cmd2', resource);
674-
terminalService.verify(async (t) => t.executeCommand('cmd2'), TypeMoq.Times.once());
674+
terminalService.verify(async (t) => t.executeCommand('cmd2', false), TypeMoq.Times.once());
675675
});
676676
});
677677
});

0 commit comments

Comments
 (0)