@@ -7,10 +7,12 @@ import { Cargo, type ExecutableInfo, getRustcId, getSysroot } from "./toolchain"
77import type { Ctx } from "./ctx" ;
88import { prepareEnv } from "./run" ;
99import { unwrapUndefinable } from "./undefinable" ;
10+ import { isCargoRunnableArgs } from "./util" ;
1011
1112const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
1213type DebugConfigProvider = (
13- config : ra . Runnable ,
14+ runnable : ra . Runnable ,
15+ runnableArgs : ra . CargoRunnableArgs ,
1416 executable : string ,
1517 cargoWorkspace : string ,
1618 env : Record < string , string > ,
@@ -77,6 +79,11 @@ async function getDebugConfiguration(
7779 ctx : Ctx ,
7880 runnable : ra . Runnable ,
7981) : Promise < vscode . DebugConfiguration | undefined > {
82+ if ( ! isCargoRunnableArgs ( runnable . args ) ) {
83+ return ;
84+ }
85+ const runnableArgs : ra . CargoRunnableArgs = runnable . args ;
86+
8087 const editor = ctx . activeRustEditor ;
8188 if ( ! editor ) return ;
8289
@@ -120,9 +127,9 @@ async function getDebugConfiguration(
120127 const isMultiFolderWorkspace = workspaceFolders . length > 1 ;
121128 const firstWorkspace = workspaceFolders [ 0 ] ;
122129 const maybeWorkspace =
123- ! isMultiFolderWorkspace || ! runnable . args . workspaceRoot
130+ ! isMultiFolderWorkspace || ! runnableArgs . workspaceRoot
124131 ? firstWorkspace
125- : workspaceFolders . find ( ( w ) => runnable . args . workspaceRoot ?. includes ( w . uri . fsPath ) ) ||
132+ : workspaceFolders . find ( ( w ) => runnableArgs . workspaceRoot ?. includes ( w . uri . fsPath ) ) ||
126133 firstWorkspace ;
127134
128135 const workspace = unwrapUndefinable ( maybeWorkspace ) ;
@@ -133,8 +140,11 @@ async function getDebugConfiguration(
133140 return path . normalize ( p ) . replace ( wsFolder , "${workspaceFolder" + workspaceQualifier + "}" ) ;
134141 }
135142
136- const env = prepareEnv ( runnable , ctx . config . runnablesExtraEnv ) ;
137- const { executable, workspace : cargoWorkspace } = await getDebugExecutableInfo ( runnable , env ) ;
143+ const env = prepareEnv ( runnable . label , runnableArgs , ctx . config . runnablesExtraEnv ) ;
144+ const { executable, workspace : cargoWorkspace } = await getDebugExecutableInfo (
145+ runnableArgs ,
146+ env ,
147+ ) ;
138148 let sourceFileMap = debugOptions . sourceFileMap ;
139149 if ( sourceFileMap === "auto" ) {
140150 // let's try to use the default toolchain
@@ -150,6 +160,7 @@ async function getDebugConfiguration(
150160 const provider = unwrapUndefinable ( knownEngines [ debugEngine . id ] ) ;
151161 const debugConfig = provider (
152162 runnable ,
163+ runnableArgs ,
153164 simplifyPath ( executable ) ,
154165 cargoWorkspace ,
155166 env ,
@@ -177,18 +188,19 @@ async function getDebugConfiguration(
177188}
178189
179190async function getDebugExecutableInfo (
180- runnable : ra . Runnable ,
191+ runnableArgs : ra . CargoRunnableArgs ,
181192 env : Record < string , string > ,
182193) : Promise < ExecutableInfo > {
183- const cargo = new Cargo ( runnable . args . workspaceRoot || "." , debugOutput , env ) ;
184- const executableInfo = await cargo . executableInfoFromArgs ( runnable . args . cargoArgs ) ;
194+ const cargo = new Cargo ( runnableArgs . workspaceRoot || "." , debugOutput , env ) ;
195+ const executableInfo = await cargo . executableInfoFromArgs ( runnableArgs . cargoArgs ) ;
185196
186197 // if we are here, there were no compilation errors.
187198 return executableInfo ;
188199}
189200
190201function getCCppDebugConfig (
191202 runnable : ra . Runnable ,
203+ runnableArgs : ra . CargoRunnableArgs ,
192204 executable : string ,
193205 cargoWorkspace : string ,
194206 env : Record < string , string > ,
@@ -199,15 +211,16 @@ function getCCppDebugConfig(
199211 request : "launch" ,
200212 name : runnable . label ,
201213 program : executable ,
202- args : runnable . args . executableArgs ,
203- cwd : cargoWorkspace || runnable . args . workspaceRoot ,
214+ args : runnableArgs . executableArgs ,
215+ cwd : cargoWorkspace || runnableArgs . workspaceRoot ,
204216 sourceFileMap,
205217 env,
206218 } ;
207219}
208220
209221function getCodeLldbDebugConfig (
210222 runnable : ra . Runnable ,
223+ runnableArgs : ra . CargoRunnableArgs ,
211224 executable : string ,
212225 cargoWorkspace : string ,
213226 env : Record < string , string > ,
@@ -218,8 +231,8 @@ function getCodeLldbDebugConfig(
218231 request : "launch" ,
219232 name : runnable . label ,
220233 program : executable ,
221- args : runnable . args . executableArgs ,
222- cwd : cargoWorkspace || runnable . args . workspaceRoot ,
234+ args : runnableArgs . executableArgs ,
235+ cwd : cargoWorkspace || runnableArgs . workspaceRoot ,
223236 sourceMap : sourceFileMap ,
224237 sourceLanguages : [ "rust" ] ,
225238 env,
@@ -228,6 +241,7 @@ function getCodeLldbDebugConfig(
228241
229242function getNativeDebugConfig (
230243 runnable : ra . Runnable ,
244+ runnableArgs : ra . CargoRunnableArgs ,
231245 executable : string ,
232246 cargoWorkspace : string ,
233247 env : Record < string , string > ,
@@ -239,8 +253,8 @@ function getNativeDebugConfig(
239253 name : runnable . label ,
240254 target : executable ,
241255 // See https://github.com/WebFreak001/code-debug/issues/359
242- arguments : quote ( runnable . args . executableArgs ) ,
243- cwd : cargoWorkspace || runnable . args . workspaceRoot ,
256+ arguments : quote ( runnableArgs . executableArgs ) ,
257+ cwd : cargoWorkspace || runnableArgs . workspaceRoot ,
244258 env,
245259 valuesFormatting : "prettyPrinters" ,
246260 } ;
0 commit comments