Skip to content

Commit c62a353

Browse files
committed
[lldb-dap] expand tilde in dap executable path
Users may have multiple devices and would like to resolve the homepath based on the machine they are on.
1 parent 8c9c91f commit c62a353

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as os from "os";
12
import * as path from "path";
23
import * as util from "util";
34
import * as vscode from "vscode";
@@ -9,6 +10,16 @@ import { LogFilePathProvider, LogType } from "./logging";
910

1011
const exec = util.promisify(child_process.execFile);
1112

13+
/**
14+
* Expands the character `~` to the user's home directory
15+
*/
16+
function expandUser(file_path: string): string {
17+
if (file_path.startsWith("~")) {
18+
return os.homedir() + file_path.slice(1);
19+
}
20+
return file_path;
21+
}
22+
1223
async function isExecutable(path: string): Promise<Boolean> {
1324
try {
1425
await fs.access(path, fs.constants.X_OK);
@@ -116,8 +127,9 @@ async function getDAPExecutable(
116127
configuration: vscode.DebugConfiguration,
117128
): Promise<string> {
118129
// Check if the executable was provided in the launch configuration.
119-
const launchConfigPath = configuration["debugAdapterExecutable"];
130+
let launchConfigPath = configuration["debugAdapterExecutable"];
120131
if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) {
132+
launchConfigPath = expandUser(launchConfigPath);
121133
if (!(await isExecutable(launchConfigPath))) {
122134
throw new ErrorWithNotification(
123135
`Debug adapter path "${launchConfigPath}" is not a valid file. The path comes from your launch configuration.`,
@@ -129,7 +141,7 @@ async function getDAPExecutable(
129141

130142
// Check if the executable was provided in the extension's configuration.
131143
const config = vscode.workspace.getConfiguration("lldb-dap", workspaceFolder);
132-
const configPath = config.get<string>("executable-path");
144+
const configPath = expandUser(config.get<string>("executable-path") ?? "");
133145
if (configPath && configPath.length !== 0) {
134146
if (!(await isExecutable(configPath))) {
135147
throw new ErrorWithNotification(

0 commit comments

Comments
 (0)