@@ -25,7 +25,7 @@ async function findWithXcrun(executable: string): Promise<string | undefined> {
2525 if ( stdout ) {
2626 return stdout . toString ( ) . trimEnd ( ) ;
2727 }
28- } catch ( error ) { }
28+ } catch ( error ) { }
2929 }
3030 return undefined ;
3131}
@@ -93,13 +93,33 @@ async function getDAPExecutable(
9393 return undefined ;
9494}
9595
96+ function getDAPArguments ( session : vscode . DebugSession ) : string [ ] {
97+ // Check the debug configuration for arguments first
98+ const debugConfigArgs = session . configuration . debugAdapterArgs ;
99+ if (
100+ Array . isArray ( debugConfigArgs ) &&
101+ debugConfigArgs . findIndex ( ( entry ) => typeof entry !== "string" ) === - 1
102+ ) {
103+ return debugConfigArgs ;
104+ }
105+ // Fall back on the workspace configuration
106+ return vscode . workspace
107+ . getConfiguration ( "lldb-dap" )
108+ . get < string [ ] > ( "arguments" , [ ] ) ;
109+ }
110+
96111/**
97112 * This class defines a factory used to find the lldb-dap binary to use
98113 * depending on the session configuration.
99114 */
100115export class LLDBDapDescriptorFactory
101- implements vscode . DebugAdapterDescriptorFactory , vscode . Disposable {
102- private server ?: Promise < { process : child_process . ChildProcess , host : string , port : number } > ;
116+ implements vscode . DebugAdapterDescriptorFactory , vscode . Disposable
117+ {
118+ private server ?: Promise < {
119+ process : child_process . ChildProcess ;
120+ host : string ;
121+ port : number ;
122+ } > ;
103123
104124 dispose ( ) {
105125 this . server ?. then ( ( { process } ) => {
@@ -109,7 +129,7 @@ export class LLDBDapDescriptorFactory
109129
110130 async createDebugAdapterDescriptor (
111131 session : vscode . DebugSession ,
112- executable : vscode . DebugAdapterExecutable | undefined ,
132+ _executable : vscode . DebugAdapterExecutable | undefined ,
113133 ) : Promise < vscode . DebugAdapterDescriptor | undefined > {
114134 const config = vscode . workspace . getConfiguration (
115135 "lldb-dap" ,
@@ -123,7 +143,7 @@ export class LLDBDapDescriptorFactory
123143 }
124144 const configEnvironment =
125145 config . get < { [ key : string ] : string } > ( "environment" ) || { } ;
126- const dapPath = ( await getDAPExecutable ( session ) ) ?? executable ?. command ;
146+ const dapPath = await getDAPExecutable ( session ) ;
127147
128148 if ( ! dapPath ) {
129149 LLDBDapDescriptorFactory . showLLDBDapNotFoundMessage ( ) ;
@@ -137,54 +157,60 @@ export class LLDBDapDescriptorFactory
137157
138158 const dbgOptions = {
139159 env : {
140- ...executable ?. options ?. env ,
141160 ...configEnvironment ,
142161 ...env ,
143162 } ,
144163 } ;
145- const dbgArgs = executable ?. args ?? [ ] ;
164+ const dbgArgs = getDAPArguments ( session ) ;
146165
147- const serverMode = config . get < boolean > ( ' serverMode' , false ) ;
166+ const serverMode = config . get < boolean > ( " serverMode" , false ) ;
148167 if ( serverMode ) {
149- const { host, port } = await this . startServer ( dapPath , dbgArgs , dbgOptions ) ;
168+ const { host, port } = await this . startServer (
169+ dapPath ,
170+ dbgArgs ,
171+ dbgOptions ,
172+ ) ;
150173 return new vscode . DebugAdapterServer ( port , host ) ;
151174 }
152175
153176 return new vscode . DebugAdapterExecutable ( dapPath , dbgArgs , dbgOptions ) ;
154177 }
155178
156- startServer ( dapPath : string , args : string [ ] , options : child_process . CommonSpawnOptions ) : Promise < { host : string , port : number } > {
157- if ( this . server ) return this . server ;
179+ startServer (
180+ dapPath : string ,
181+ args : string [ ] ,
182+ options : child_process . CommonSpawnOptions ,
183+ ) : Promise < { host : string ; port : number } > {
184+ if ( this . server ) {
185+ return this . server ;
186+ }
158187
159- this . server = new Promise ( resolve => {
160- args . push (
161- '--connection' ,
162- 'connect://localhost:0'
163- ) ;
188+ this . server = new Promise ( ( resolve ) => {
189+ args . push ( "--connection" , "connect://localhost:0" ) ;
164190 const server = child_process . spawn ( dapPath , args , options ) ;
165- server . stdout ! . setEncoding ( ' utf8' ) . once ( ' data' , ( data : string ) => {
191+ server . stdout ! . setEncoding ( " utf8" ) . once ( " data" , ( data : string ) => {
166192 const connection = / c o n n e c t i o n : \/ \/ \[ ( [ ^ \] ] + ) \] : ( \d + ) / . exec ( data ) ;
167193 if ( connection ) {
168194 const host = connection [ 1 ] ;
169195 const port = Number ( connection [ 2 ] ) ;
170196 resolve ( { process : server , host, port } ) ;
171197 }
172198 } ) ;
173- server . on ( ' exit' , ( ) => {
199+ server . on ( " exit" , ( ) => {
174200 this . server = undefined ;
175- } )
201+ } ) ;
176202 } ) ;
177203 return this . server ;
178204 }
179205
180206 /**
181207 * Shows a message box when the debug adapter's path is not found
182208 */
183- static async showLLDBDapNotFoundMessage ( path ?: string ) {
209+ static async showLLDBDapNotFoundMessage ( path ?: string | undefined ) {
184210 const message =
185- path
186- ? `Debug adapter path: ${ path } is not a valid file. `
187- : "Unable to find the path to the LLDB debug adapter executable." ;
211+ path !== undefined
212+ ? `Debug adapter path: ${ path } is not a valid file`
213+ : "Unable to find the LLDB debug adapter executable." ;
188214 const openSettingsAction = "Open Settings" ;
189215 const callbackValue = await vscode . window . showErrorMessage (
190216 message ,
0 commit comments