Skip to content
Merged
Changes from 2 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
17 changes: 10 additions & 7 deletions src/features/terminal/runInTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Terminal, TerminalShellExecution } from 'vscode';
import { PythonEnvironment, PythonTerminalExecutionOptions } from '../../api';
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
import { createDeferred } from '../../common/utils/deferred';
import { quoteArgs } from '../execution/execUtils';
import { identifyTerminalShell } from '../common/shellDetector';
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
import { ShellConstants } from '../common/shellConstants';
import { identifyTerminalShell } from '../common/shellDetector';
import { quoteArgs } from '../execution/execUtils';

export async function runInTerminal(
environment: PythonEnvironment,
Expand All @@ -15,11 +15,10 @@ export async function runInTerminal(
terminal.show();
}

const executable =
environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
const allArgs = [...args, ...(options.args ?? [])];

const shellType = identifyTerminalShell(terminal);
if (terminal.shellIntegration) {
let execution: TerminalShellExecution | undefined;
const deferred = createDeferred<void>();
Expand All @@ -29,10 +28,14 @@ export async function runInTerminal(
deferred.resolve();
}
});
if (shellType === ShellConstants.PWSH && !executable.startsWith('&')) {
executable = quoteArgs([executable, ...allArgs]).join(' ');
// PowerShell requires commands to be prefixed with '&' to run them.
executable = `& ${executable}`;
}
execution = terminal.shellIntegration.executeCommand(executable, allArgs);
await deferred.promise;
} else {
const shellType = identifyTerminalShell(terminal);
let text = quoteArgs([executable, ...allArgs]).join(' ');
if (shellType === ShellConstants.PWSH && !text.startsWith('&')) {
// PowerShell requires commands to be prefixed with '&' to run them.
Expand Down