1+ import * as os from "os" ;
12import * as path from "path" ;
23import * as util from "util" ;
34import * as vscode from "vscode" ;
@@ -9,6 +10,16 @@ import { LogFilePathProvider, LogType } from "./logging";
910
1011const 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+
1223async 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