@@ -3,7 +3,7 @@ import * as vscode from "vscode";
33import * as path from "path" ;
44import type * as ra from "./lsp_ext" ;
55
6- import { Cargo , getRustcId , getSysroot } from "./toolchain" ;
6+ import { Cargo , type ExecutableInfo , getRustcId , getSysroot } from "./toolchain" ;
77import type { Ctx } from "./ctx" ;
88import { prepareEnv } from "./run" ;
99import { unwrapUndefinable } from "./undefinable" ;
@@ -12,6 +12,7 @@ const debugOutput = vscode.window.createOutputChannel("Debug");
1212type DebugConfigProvider = (
1313 config : ra . Runnable ,
1414 executable : string ,
15+ cargoWorkspace : string ,
1516 env : Record < string , string > ,
1617 sourceFileMap ?: Record < string , string > ,
1718) => vscode . DebugConfiguration ;
@@ -130,7 +131,7 @@ async function getDebugConfiguration(
130131 }
131132
132133 const env = prepareEnv ( runnable , ctx . config . runnablesExtraEnv ) ;
133- const executable = await getDebugExecutable ( runnable , env ) ;
134+ const { executable, workspace : cargoWorkspace } = await getDebugExecutableInfo ( runnable , env ) ;
134135 let sourceFileMap = debugOptions . sourceFileMap ;
135136 if ( sourceFileMap === "auto" ) {
136137 // let's try to use the default toolchain
@@ -142,7 +143,13 @@ async function getDebugConfiguration(
142143 }
143144
144145 const provider = unwrapUndefinable ( knownEngines [ debugEngine . id ] ) ;
145- const debugConfig = provider ( runnable , simplifyPath ( executable ) , env , sourceFileMap ) ;
146+ const debugConfig = provider (
147+ runnable ,
148+ simplifyPath ( executable ) ,
149+ cargoWorkspace ,
150+ env ,
151+ sourceFileMap ,
152+ ) ;
146153 if ( debugConfig . type in debugOptions . engineSettings ) {
147154 const settingsMap = ( debugOptions . engineSettings as any ) [ debugConfig . type ] ;
148155 for ( var key in settingsMap ) {
@@ -164,20 +171,21 @@ async function getDebugConfiguration(
164171 return debugConfig ;
165172}
166173
167- async function getDebugExecutable (
174+ async function getDebugExecutableInfo (
168175 runnable : ra . Runnable ,
169176 env : Record < string , string > ,
170- ) : Promise < string > {
177+ ) : Promise < ExecutableInfo > {
171178 const cargo = new Cargo ( runnable . args . workspaceRoot || "." , debugOutput , env ) ;
172- const executable = await cargo . executableFromArgs ( runnable . args . cargoArgs ) ;
179+ const executableInfo = await cargo . executableInfoFromArgs ( runnable . args . cargoArgs ) ;
173180
174181 // if we are here, there were no compilation errors.
175- return executable ;
182+ return executableInfo ;
176183}
177184
178185function getLldbDebugConfig (
179186 runnable : ra . Runnable ,
180187 executable : string ,
188+ cargoWorkspace : string ,
181189 env : Record < string , string > ,
182190 sourceFileMap ?: Record < string , string > ,
183191) : vscode . DebugConfiguration {
@@ -187,7 +195,7 @@ function getLldbDebugConfig(
187195 name : runnable . label ,
188196 program : executable ,
189197 args : runnable . args . executableArgs ,
190- cwd : runnable . args . workspaceRoot ,
198+ cwd : cargoWorkspace || runnable . args . workspaceRoot ,
191199 sourceMap : sourceFileMap ,
192200 sourceLanguages : [ "rust" ] ,
193201 env,
@@ -197,6 +205,7 @@ function getLldbDebugConfig(
197205function getCppvsDebugConfig (
198206 runnable : ra . Runnable ,
199207 executable : string ,
208+ cargoWorkspace : string ,
200209 env : Record < string , string > ,
201210 sourceFileMap ?: Record < string , string > ,
202211) : vscode . DebugConfiguration {
@@ -206,7 +215,7 @@ function getCppvsDebugConfig(
206215 name : runnable . label ,
207216 program : executable ,
208217 args : runnable . args . executableArgs ,
209- cwd : runnable . args . workspaceRoot ,
218+ cwd : cargoWorkspace || runnable . args . workspaceRoot ,
210219 sourceFileMap,
211220 env,
212221 } ;
0 commit comments