Skip to content
Open
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
16 changes: 14 additions & 2 deletions lldb/tools/lldb-dap/src-ts/debug-adapter-factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import * as path from "path";
import * as util from "util";
import * as vscode from "vscode";
Expand All @@ -9,6 +10,16 @@ import { LogFilePathProvider, LogType } from "./logging";

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

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use this package https://www.npmjs.com/package/untildify
there are some interesting cases related to ~, so better rely on a library

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also copy and simplify the code of that library and add it as a utility in lldb-dap

* Expands the character `~` to the user's home directory
*/
function expandUser(file_path: string): string {
if (file_path.startsWith("~")) {
return os.homedir() + file_path.slice(1);
}
return file_path;
}

async function isExecutable(path: string): Promise<Boolean> {
try {
await fs.access(path, fs.constants.X_OK);
Expand Down Expand Up @@ -116,8 +127,9 @@ async function getDAPExecutable(
configuration: vscode.DebugConfiguration,
): Promise<string> {
// Check if the executable was provided in the launch configuration.
const launchConfigPath = configuration["debugAdapterExecutable"];
let launchConfigPath = configuration["debugAdapterExecutable"];
if (typeof launchConfigPath === "string" && launchConfigPath.length !== 0) {
launchConfigPath = expandUser(launchConfigPath);
if (!(await isExecutable(launchConfigPath))) {
throw new ErrorWithNotification(
`Debug adapter path "${launchConfigPath}" is not a valid file. The path comes from your launch configuration.`,
Expand All @@ -129,7 +141,7 @@ async function getDAPExecutable(

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