Skip to content
Open
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
22 changes: 22 additions & 0 deletions src/bashDebug.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createRunInTerminalArgs } from "./bashDebug";

describe("bashDebug - createRunInTerminalArgs", () => {

it("preserves shell interpretation for runInTerminal commands", () => {

expect(createRunInTerminalArgs("integrated", "wsl.exe", "bash", "while [[ ! -p fifo ]]; do sleep 0.25; done"))
.toEqual({
kind: "integrated",
title: "Bash Debug Console",
cwd: ".",
args: ["wsl.exe", "bash", "-c", "while [[ ! -p fifo ]]; do sleep 0.25; done"],
argsCanBeInterpretedByShell: true,
});
});

it("omits the extra bash path argument when it is not needed", () => {

expect(createRunInTerminalArgs("external", "/bin/bash", "", "echo ok").args)
.toEqual(["/bin/bash", "-c", "echo ok"]);
});
});
31 changes: 25 additions & 6 deletions src/bashDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
trace?: boolean;
}

interface RunInTerminalRequestArgumentsWithShellInterpretation extends DebugProtocol.RunInTerminalRequestArguments {
argsCanBeInterpretedByShell?: boolean;
}

export function createRunInTerminalArgs(
kind: 'integrated' | 'external',
currentShell: string,
optionalBashPathArgument: string,
command: string
): RunInTerminalRequestArgumentsWithShellInterpretation {
return {
kind,
title: "Bash Debug Console",
cwd: ".",
args: [currentShell, optionalBashPathArgument, `-c`, command].filter(arg => arg !== ""),
// Keep the -c payload intact so the client does not escape shell operators like '!'.
argsCanBeInterpretedByShell: true,
};
}

export class BashDebugSession extends LoggingDebugSession {

private static THREAD_ID = 42;
Expand Down Expand Up @@ -164,12 +184,11 @@ export class BashDebugSession extends LoggingDebugSession {
else {
const currentShell = (process.platform === "win32") ? getWSLLauncherPath(true) : args.pathBash;
const optionalBashPathArgument = (currentShell !== args.pathBash) ? args.pathBash : "";
const termArgs: DebugProtocol.RunInTerminalRequestArguments = {
kind: this.launchArgs.terminalKind,
title: "Bash Debug Console",
cwd: ".",
args: [currentShell, optionalBashPathArgument, `-c`, command].filter(arg => arg !== ""),
};
const termArgs = createRunInTerminalArgs(
this.launchArgs.terminalKind,
currentShell,
optionalBashPathArgument,
command);

this.runInTerminalRequest(termArgs, 10000, (response) => {
if (!response.success) {
Expand Down