Skip to content

Commit 448763e

Browse files
committed
Updates for WSL
1 parent 7250861 commit 448763e

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

Extension/src/Debugger/configurations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function createLaunchString(name: string, type: string, executable: string): str
9797
"stopAtEntry": false,
9898
"cwd": "$\{fileDirname\}",
9999
"environment": [],
100-
${ type === "cppdbg" ? `"externalConsole": false` : `"console": "externalTerminal"` }
100+
${ type === "cppdbg" ? `"externalConsole": false` : `"console": "integratedTerminal"` }
101101
`;
102102
}
103103

Extension/src/Debugger/runWithoutDebuggingAdapter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as cp from 'child_process';
77
import * as os from 'os';
88
import * as path from 'path';
99
import * as vscode from 'vscode';
10+
import { sessionIsWsl } from '../common';
1011

1112
/**
1213
* A minimal inline Debug Adapter that runs the target program directly without a debug adapter
@@ -56,13 +57,14 @@ export class RunWithoutDebuggingAdapter implements vscode.DebugAdapter {
5657
cwd?: string;
5758
environment?: { name: string; value: string; }[];
5859
console?: string;
60+
externalConsole?: boolean;
5961
};
6062

6163
const program: string = config.program ?? '';
6264
const args: string[] = config.args ?? [];
6365
const cwd: string | undefined = config.cwd;
6466
const environment: { name: string; value: string; }[] = config.environment ?? [];
65-
const consoleMode: string = config.console ?? 'integratedTerminal';
67+
const consoleMode: string = config.console ?? (config.externalConsole ? 'externalTerminal' : 'integratedTerminal');
6668

6769
// Merge the launch config's environment variables on top of the inherited process environment.
6870
const env: NodeJS.ProcessEnv = { ...process.env };
@@ -112,8 +114,10 @@ export class RunWithoutDebuggingAdapter implements vscode.DebugAdapter {
112114
cp.spawn('cmd.exe', ['/c', 'start', 'cmd.exe', '/K', cmdLine], { cwd, env, detached: true, stdio: 'ignore' }).unref();
113115
} else if (platform === 'darwin') {
114116
cp.spawn('osascript', ['-e', `tell application "Terminal" to do script "${cmdLine.replace(/"/g, '\\"')}"`], { cwd, env, detached: true, stdio: 'ignore' }).unref();
115-
} else {
116-
cp.spawn('x-terminal-emulator', ['-e', cmdLine], { cwd, env, detached: true, stdio: 'ignore' }).unref();
117+
} else if (platform === 'linux' && sessionIsWsl()) {
118+
cp.spawn('/mnt/c/Windows/System32/cmd.exe', ['/c', 'start', 'bash', '-c', `${cmdLine};read -p 'Press enter to continue...'`], { env, detached: true, stdio: 'ignore' }).unref();
119+
} else { // platform === 'linux'
120+
cp.spawn('bash', ['-c', `${cmdLine};read -p 'Press enter to continue...'`], { cwd, env, detached: true, stdio: 'ignore' }).unref();
117121
}
118122
this.sendEvent('terminated');
119123
}

Extension/src/common.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,3 +1850,14 @@ export function getVSCodeLanguageModel(): any | undefined {
18501850
}
18511851
return vscodelm;
18521852
}
1853+
1854+
export function sessionIsWsl(): boolean {
1855+
if (process.env.WSL_DISTRO_NAME) {
1856+
return true;
1857+
}
1858+
try {
1859+
return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');
1860+
} catch {
1861+
return false;
1862+
}
1863+
}

0 commit comments

Comments
 (0)