@@ -64,29 +64,19 @@ export function runSingle(ctx: Ctx): Cmd {
64
64
} ;
65
65
}
66
66
67
- function getLldbDebugConfig ( config : ra . Runnable , sourceFileMap : Record < string , string > ) : vscode . DebugConfiguration {
67
+ function getLldbDebugConfig ( config : ra . Runnable , executable : string , sourceFileMap ? : Record < string , string > ) : vscode . DebugConfiguration {
68
68
return {
69
69
type : "lldb" ,
70
70
request : "launch" ,
71
71
name : config . label ,
72
- cargo : {
73
- args : config . args ,
74
- } ,
72
+ program : executable ,
75
73
args : config . extraArgs ,
76
74
cwd : config . cwd ,
77
75
sourceMap : sourceFileMap
78
76
} ;
79
77
}
80
78
81
- const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
82
-
83
- async function getCppvsDebugConfig ( config : ra . Runnable , sourceFileMap : Record < string , string > ) : Promise < vscode . DebugConfiguration > {
84
- debugOutput . clear ( ) ;
85
-
86
- const cargo = new Cargo ( config . cwd || '.' , debugOutput ) ;
87
- const executable = await cargo . executableFromArgs ( config . args ) ;
88
-
89
- // if we are here, there were no compilation errors.
79
+ function getCppvsDebugConfig ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
90
80
return {
91
81
type : ( os . platform ( ) === "win32" ) ? "cppvsdbg" : 'cppdbg' ,
92
82
request : "launch" ,
@@ -98,36 +88,53 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
98
88
} ;
99
89
}
100
90
91
+ const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
92
+
93
+ async function getDebugExecutable ( config : ra . Runnable ) : Promise < string > {
94
+ debugOutput . clear ( ) ;
95
+
96
+ const cargo = new Cargo ( config . cwd || '.' , debugOutput ) ;
97
+ const executable = await cargo . executableFromArgs ( config . args ) ;
98
+
99
+ // if we are here, there were no compilation errors.
100
+ return executable ;
101
+ }
102
+
103
+ type DebugConfigProvider = ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) => vscode . DebugConfiguration ;
104
+
101
105
export function debugSingle ( ctx : Ctx ) : Cmd {
102
106
return async ( config : ra . Runnable ) => {
103
107
const editor = ctx . activeRustEditor ;
104
108
if ( ! editor ) return ;
105
109
106
- const lldbId = "vadimcn.vscode-lldb" ;
107
- const cpptoolsId = "ms-vscode.cpptools" ;
110
+ const knownEngines : Record < string , DebugConfigProvider > = {
111
+ "vadimcn.vscode-lldb" : getLldbDebugConfig ,
112
+ "ms-vscode.cpptools" : getCppvsDebugConfig
113
+ } ;
114
+ const debugOptions = ctx . config . debug ;
108
115
109
- const debugEngineId = ctx . config . debug . engine ;
110
116
let debugEngine = null ;
111
- if ( debugEngineId === "auto" ) {
112
- debugEngine = vscode . extensions . getExtension ( lldbId ) ;
113
- if ( ! debugEngine ) {
114
- debugEngine = vscode . extensions . getExtension ( cpptoolsId ) ;
117
+ if ( debugOptions . engine === "auto" ) {
118
+ for ( var engineId in knownEngines ) {
119
+ debugEngine = vscode . extensions . getExtension ( engineId ) ;
120
+ if ( debugEngine ) break ;
115
121
}
116
122
}
117
123
else {
118
- debugEngine = vscode . extensions . getExtension ( debugEngineId ) ;
124
+ debugEngine = vscode . extensions . getExtension ( debugOptions . engine ) ;
119
125
}
120
126
121
127
if ( ! debugEngine ) {
122
- vscode . window . showErrorMessage ( `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${ lldbId } )`
123
- + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${ cpptoolsId } ) extension for debugging.` ) ;
128
+ vscode . window . showErrorMessage ( `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb )`
129
+ + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools ) extension for debugging.` ) ;
124
130
return ;
125
131
}
126
132
127
- const debugConfig = lldbId === debugEngine . id
128
- ? getLldbDebugConfig ( config , ctx . config . debug . sourceFileMap )
129
- : await getCppvsDebugConfig ( config , ctx . config . debug . sourceFileMap ) ;
133
+ const executable = await getDebugExecutable ( config ) ;
134
+ const debugConfig = knownEngines [ debugEngine . id ] ( config , executable , debugOptions . sourceFileMap ) ;
130
135
136
+ debugOutput . appendLine ( "Launching debug configuration:" ) ;
137
+ debugOutput . appendLine ( JSON . stringify ( debugConfig , null , 2 ) ) ;
131
138
return vscode . debug . startDebugging ( undefined , debugConfig ) ;
132
139
} ;
133
140
}
0 commit comments