Skip to content

Fix: Don't use executeCommand on python sub-shell for WSL #24545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { traceVerbose } from '../../logging';
import { getConfiguration } from '../vscodeApis/workspaceApis';
import { isWindows } from '../utils/platform';
import { isWsl } from '../utils/envApis';

@injectable()
export class TerminalService implements ITerminalService, Disposable {
Expand Down Expand Up @@ -105,7 +106,7 @@ export class TerminalService implements ITerminalService, Disposable {

const config = getConfiguration('python');
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
if ((isPythonShell && !pythonrcSetting) || (isPythonShell && isWindows())) {
if (isPythonShell && (!pythonrcSetting || isWindows() || isWsl())) {
// If user has explicitly disabled SI for Python, use sendText for inside Terminal REPL.
terminal.sendText(commandLine);
return undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/client/common/utils/envApis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { env } from 'vscode';

export function isWsl(): boolean {
return env.remoteName === 'wsl';
}
1 change: 0 additions & 1 deletion src/client/common/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict';

import { EnvironmentVariables } from '../variables/types';

export enum Architecture {
Unknown = 1,
x86 = 2,
Expand Down
27 changes: 27 additions & 0 deletions src/test/common/terminals/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ITerminalAutoActivation } from '../../../client/terminals/types';
import { createPythonInterpreter } from '../../utils/interpreters';
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
import * as platform from '../../../client/common/utils/platform';
import * as envApis from '../../../client/common/utils/envApis';

suite('Terminal Service', () => {
let service: TerminalService;
Expand All @@ -44,6 +45,7 @@ suite('Terminal Service', () => {
let pythonConfig: TypeMoq.IMock<WorkspaceConfiguration>;
let editorConfig: TypeMoq.IMock<WorkspaceConfiguration>;
let isWindowsStub: sinon.SinonStub;
let isWslStub: sinon.SinonStub;

setup(() => {
terminal = TypeMoq.Mock.ofType<VSCodeTerminal>();
Expand Down Expand Up @@ -97,6 +99,7 @@ suite('Terminal Service', () => {
mockServiceContainer.setup((c) => c.get(ITerminalAutoActivation)).returns(() => terminalAutoActivator.object);
getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration');
isWindowsStub = sinon.stub(platform, 'isWindows');
isWslStub = sinon.stub(envApis, 'isWsl');
pythonConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
editorConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
getConfigurationStub.callsFake((section: string) => {
Expand All @@ -105,6 +108,7 @@ suite('Terminal Service', () => {
}
return editorConfig.object;
});
isWindowsStub.returns(false);
});
teardown(() => {
if (service) {
Expand Down Expand Up @@ -278,6 +282,29 @@ suite('Terminal Service', () => {
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
});

test('Ensure sendText IS called even when Python shell integration and terminal shell integration are both enabled - WSL', async () => {
isWindowsStub.returns(false);
isWslStub.returns(true);
pythonConfig
.setup((p) => p.get('terminal.shellIntegration.enabled'))
.returns(() => true)
.verifiable(TypeMoq.Times.once());

terminalHelper
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(undefined));
service = new TerminalService(mockServiceContainer.object);
const textToSend = 'Some Text';
terminalHelper.setup((h) => h.identifyTerminalShell(TypeMoq.It.isAny())).returns(() => TerminalShellType.bash);
terminalManager.setup((t) => t.createTerminal(TypeMoq.It.isAny())).returns(() => terminal.object);

service.ensureTerminal();
service.executeCommand(textToSend, true);

terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.exactly(1));
terminal.verify((t) => t.sendText(TypeMoq.It.isValue(textToSend)), TypeMoq.Times.exactly(1));
});

test('Ensure terminal is not shown if `hideFromUser` option is set to `true`', async () => {
terminalHelper
.setup((helper) => helper.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
Expand Down
1 change: 1 addition & 0 deletions src/test/vscode-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function initialize() {
const clipboard = new MockClipboard();
when(mockedVSCodeNamespaces.env!.clipboard).thenReturn(clipboard);
when(mockedVSCodeNamespaces.env!.appName).thenReturn('Insider');
when(mockedVSCodeNamespaces.env!.remoteName).thenReturn('Notwsl');

// This API is used in src/client/telemetry/telemetry.ts
const extension = mock<vscode.Extension<any>>();
Expand Down
Loading