@@ -3,7 +3,7 @@ import * as vscode from "vscode";
3
3
import * as path from "path" ;
4
4
import type * as ra from "./lsp_ext" ;
5
5
6
- import { Cargo , getRustcId , getSysroot } from "./toolchain" ;
6
+ import { Cargo , type ExecutableInfo , getRustcId , getSysroot } from "./toolchain" ;
7
7
import type { Ctx } from "./ctx" ;
8
8
import { prepareEnv } from "./run" ;
9
9
import { unwrapUndefinable } from "./undefinable" ;
@@ -12,6 +12,7 @@ const debugOutput = vscode.window.createOutputChannel("Debug");
12
12
type DebugConfigProvider = (
13
13
config : ra . Runnable ,
14
14
executable : string ,
15
+ cargoWorkspace : string ,
15
16
env : Record < string , string > ,
16
17
sourceFileMap ?: Record < string , string > ,
17
18
) => vscode . DebugConfiguration ;
@@ -130,7 +131,7 @@ async function getDebugConfiguration(
130
131
}
131
132
132
133
const env = prepareEnv ( runnable , ctx . config . runnablesExtraEnv ) ;
133
- const executable = await getDebugExecutable ( runnable , env ) ;
134
+ const { executable, workspace : cargoWorkspace } = await getDebugExecutableInfo ( runnable , env ) ;
134
135
let sourceFileMap = debugOptions . sourceFileMap ;
135
136
if ( sourceFileMap === "auto" ) {
136
137
// let's try to use the default toolchain
@@ -142,7 +143,13 @@ async function getDebugConfiguration(
142
143
}
143
144
144
145
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
+ ) ;
146
153
if ( debugConfig . type in debugOptions . engineSettings ) {
147
154
const settingsMap = ( debugOptions . engineSettings as any ) [ debugConfig . type ] ;
148
155
for ( var key in settingsMap ) {
@@ -164,20 +171,21 @@ async function getDebugConfiguration(
164
171
return debugConfig ;
165
172
}
166
173
167
- async function getDebugExecutable (
174
+ async function getDebugExecutableInfo (
168
175
runnable : ra . Runnable ,
169
176
env : Record < string , string > ,
170
- ) : Promise < string > {
177
+ ) : Promise < ExecutableInfo > {
171
178
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 ) ;
173
180
174
181
// if we are here, there were no compilation errors.
175
- return executable ;
182
+ return executableInfo ;
176
183
}
177
184
178
185
function getLldbDebugConfig (
179
186
runnable : ra . Runnable ,
180
187
executable : string ,
188
+ cargoWorkspace : string ,
181
189
env : Record < string , string > ,
182
190
sourceFileMap ?: Record < string , string > ,
183
191
) : vscode . DebugConfiguration {
@@ -187,7 +195,7 @@ function getLldbDebugConfig(
187
195
name : runnable . label ,
188
196
program : executable ,
189
197
args : runnable . args . executableArgs ,
190
- cwd : runnable . args . workspaceRoot ,
198
+ cwd : cargoWorkspace || runnable . args . workspaceRoot ,
191
199
sourceMap : sourceFileMap ,
192
200
sourceLanguages : [ "rust" ] ,
193
201
env,
@@ -197,6 +205,7 @@ function getLldbDebugConfig(
197
205
function getCppvsDebugConfig (
198
206
runnable : ra . Runnable ,
199
207
executable : string ,
208
+ cargoWorkspace : string ,
200
209
env : Record < string , string > ,
201
210
sourceFileMap ?: Record < string , string > ,
202
211
) : vscode . DebugConfiguration {
@@ -206,7 +215,7 @@ function getCppvsDebugConfig(
206
215
name : runnable . label ,
207
216
program : executable ,
208
217
args : runnable . args . executableArgs ,
209
- cwd : runnable . args . workspaceRoot ,
218
+ cwd : cargoWorkspace || runnable . args . workspaceRoot ,
210
219
sourceFileMap,
211
220
env,
212
221
} ;
0 commit comments