@@ -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,8 +93,23 @@ 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+
96111async function isServerModeSupported ( exe : string ) : Promise < boolean > {
97- const { stdout } = await exec ( exe , [ ' --help' ] ) ;
112+ const { stdout } = await exec ( exe , [ " --help" ] ) ;
98113 return / - - c o n n e c t i o n / . test ( stdout ) ;
99114}
100115
@@ -103,8 +118,13 @@ async function isServerModeSupported(exe: string): Promise<boolean> {
103118 * depending on the session configuration.
104119 */
105120export class LLDBDapDescriptorFactory
106- implements vscode . DebugAdapterDescriptorFactory , vscode . Disposable {
107- private server ?: Promise < { process : child_process . ChildProcess , host : string , port : number } > ;
121+ implements vscode . DebugAdapterDescriptorFactory , vscode . Disposable
122+ {
123+ private server ?: Promise < {
124+ process : child_process . ChildProcess ;
125+ host : string ;
126+ port : number ;
127+ } > ;
108128
109129 dispose ( ) {
110130 this . server ?. then ( ( { process } ) => {
@@ -114,7 +134,7 @@ export class LLDBDapDescriptorFactory
114134
115135 async createDebugAdapterDescriptor (
116136 session : vscode . DebugSession ,
117- executable : vscode . DebugAdapterExecutable | undefined ,
137+ _executable : vscode . DebugAdapterExecutable | undefined ,
118138 ) : Promise < vscode . DebugAdapterDescriptor | undefined > {
119139 const config = vscode . workspace . getConfiguration (
120140 "lldb-dap" ,
@@ -128,7 +148,7 @@ export class LLDBDapDescriptorFactory
128148 }
129149 const configEnvironment =
130150 config . get < { [ key : string ] : string } > ( "environment" ) || { } ;
131- const dapPath = ( await getDAPExecutable ( session ) ) ?? executable ?. command ;
151+ const dapPath = await getDAPExecutable ( session ) ;
132152
133153 if ( ! dapPath ) {
134154 LLDBDapDescriptorFactory . showLLDBDapNotFoundMessage ( ) ;
@@ -142,54 +162,60 @@ export class LLDBDapDescriptorFactory
142162
143163 const dbgOptions = {
144164 env : {
145- ...executable ?. options ?. env ,
146165 ...configEnvironment ,
147166 ...env ,
148167 } ,
149168 } ;
150- const dbgArgs = executable ?. args ?? [ ] ;
151-
152- const serverMode = config . get < boolean > ( 'serverMode' , false ) ;
153- if ( serverMode && await isServerModeSupported ( dapPath ) ) {
154- const { host, port } = await this . startServer ( dapPath , dbgArgs , dbgOptions ) ;
169+ const dbgArgs = getDAPArguments ( session ) ;
170+
171+ const serverMode = config . get < boolean > ( "serverMode" , false ) ;
172+ if ( serverMode && ( await isServerModeSupported ( dapPath ) ) ) {
173+ const { host, port } = await this . startServer (
174+ dapPath ,
175+ dbgArgs ,
176+ dbgOptions ,
177+ ) ;
155178 return new vscode . DebugAdapterServer ( port , host ) ;
156179 }
157180
158181 return new vscode . DebugAdapterExecutable ( dapPath , dbgArgs , dbgOptions ) ;
159182 }
160183
161- startServer ( dapPath : string , args : string [ ] , options : child_process . CommonSpawnOptions ) : Promise < { host : string , port : number } > {
162- if ( this . server ) return this . server ;
184+ startServer (
185+ dapPath : string ,
186+ args : string [ ] ,
187+ options : child_process . CommonSpawnOptions ,
188+ ) : Promise < { host : string ; port : number } > {
189+ if ( this . server ) {
190+ return this . server ;
191+ }
163192
164- this . server = new Promise ( resolve => {
165- args . push (
166- '--connection' ,
167- 'connect://localhost:0'
168- ) ;
193+ this . server = new Promise ( ( resolve ) => {
194+ args . push ( "--connection" , "connect://localhost:0" ) ;
169195 const server = child_process . spawn ( dapPath , args , options ) ;
170- server . stdout ! . setEncoding ( ' utf8' ) . once ( ' data' , ( data : string ) => {
196+ server . stdout ! . setEncoding ( " utf8" ) . once ( " data" , ( data : string ) => {
171197 const connection = / c o n n e c t i o n : \/ \/ \[ ( [ ^ \] ] + ) \] : ( \d + ) / . exec ( data ) ;
172198 if ( connection ) {
173199 const host = connection [ 1 ] ;
174200 const port = Number ( connection [ 2 ] ) ;
175201 resolve ( { process : server , host, port } ) ;
176202 }
177203 } ) ;
178- server . on ( ' exit' , ( ) => {
204+ server . on ( " exit" , ( ) => {
179205 this . server = undefined ;
180- } )
206+ } ) ;
181207 } ) ;
182208 return this . server ;
183209 }
184210
185211 /**
186212 * Shows a message box when the debug adapter's path is not found
187213 */
188- static async showLLDBDapNotFoundMessage ( path ?: string ) {
214+ static async showLLDBDapNotFoundMessage ( path ?: string | undefined ) {
189215 const message =
190- path
191- ? `Debug adapter path: ${ path } is not a valid file. `
192- : "Unable to find the path to the LLDB debug adapter executable." ;
216+ path !== undefined
217+ ? `Debug adapter path: ${ path } is not a valid file`
218+ : "Unable to find the LLDB debug adapter executable." ;
193219 const openSettingsAction = "Open Settings" ;
194220 const callbackValue = await vscode . window . showErrorMessage (
195221 message ,
0 commit comments