@@ -64,29 +64,20 @@ 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
- sourceMap : sourceFileMap
75
+ sourceMap : sourceFileMap ,
76
+ sourceLanguages : [ "rust" ]
78
77
} ;
79
78
}
80
79
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.
80
+ function getCppvsDebugConfig ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
90
81
return {
91
82
type : ( os . platform ( ) === "win32" ) ? "cppvsdbg" : 'cppdbg' ,
92
83
request : "launch" ,
@@ -98,39 +89,62 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
98
89
} ;
99
90
}
100
91
92
+ const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
93
+
94
+ async function getDebugExecutable ( config : ra . Runnable ) : Promise < string > {
95
+ const cargo = new Cargo ( config . cwd || '.' , debugOutput ) ;
96
+ const executable = await cargo . executableFromArgs ( config . args ) ;
97
+
98
+ // if we are here, there were no compilation errors.
99
+ return executable ;
100
+ }
101
+
102
+ type DebugConfigProvider = ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) => vscode . DebugConfiguration ;
103
+
101
104
export function debugSingle ( ctx : Ctx ) : Cmd {
102
105
return async ( config : ra . Runnable ) => {
103
106
const editor = ctx . activeRustEditor ;
104
107
if ( ! editor ) return ;
105
108
106
- const lldbId = "vadimcn.vscode-lldb" ;
107
- const cpptoolsId = "ms-vscode.cpptools" ;
109
+ const knownEngines : Record < string , DebugConfigProvider > = {
110
+ "vadimcn.vscode-lldb" : getLldbDebugConfig ,
111
+ "ms-vscode.cpptools" : getCppvsDebugConfig
112
+ } ;
113
+ const debugOptions = ctx . config . debug ;
108
114
109
- const debugEngineId = ctx . config . debug . engine ;
110
115
let debugEngine = null ;
111
- if ( debugEngineId === "auto" ) {
112
- debugEngine = vscode . extensions . getExtension ( lldbId ) ;
113
- if ( ! debugEngine ) {
114
- debugEngine = vscode . extensions . getExtension ( cpptoolsId ) ;
116
+ if ( debugOptions . engine === "auto" ) {
117
+ for ( var engineId in knownEngines ) {
118
+ debugEngine = vscode . extensions . getExtension ( engineId ) ;
119
+ if ( debugEngine ) break ;
115
120
}
116
121
}
117
122
else {
118
- debugEngine = vscode . extensions . getExtension ( debugEngineId ) ;
123
+ debugEngine = vscode . extensions . getExtension ( debugOptions . engine ) ;
119
124
}
120
125
121
126
if ( ! debugEngine ) {
122
- vscode . window . showErrorMessage (
123
- `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=${ lldbId } ) ` +
124
- `or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=${ cpptoolsId } ) ` +
125
- `extension for debugging.`
126
- ) ;
127
+ vscode . window . showErrorMessage ( `Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
128
+ + ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.` ) ;
127
129
return ;
128
130
}
129
131
130
- const debugConfig = lldbId === debugEngine . id
131
- ? getLldbDebugConfig ( config , ctx . config . debug . sourceFileMap )
132
- : await getCppvsDebugConfig ( config , ctx . config . debug . sourceFileMap ) ;
132
+ debugOutput . clear ( ) ;
133
+ if ( ctx . config . debug . openUpDebugPane ) {
134
+ debugOutput . show ( true ) ;
135
+ }
136
+
137
+ const executable = await getDebugExecutable ( config ) ;
138
+ const debugConfig = knownEngines [ debugEngine . id ] ( config , executable , debugOptions . sourceFileMap ) ;
139
+ if ( debugConfig . type in debugOptions . engineSettings ) {
140
+ const settingsMap = ( debugOptions . engineSettings as any ) [ debugConfig . type ] ;
141
+ for ( var key in settingsMap ) {
142
+ debugConfig [ key ] = settingsMap [ key ] ;
143
+ }
144
+ }
133
145
146
+ debugOutput . appendLine ( "Launching debug configuration:" ) ;
147
+ debugOutput . appendLine ( JSON . stringify ( debugConfig , null , 2 ) ) ;
134
148
return vscode . debug . startDebugging ( undefined , debugConfig ) ;
135
149
} ;
136
150
}
0 commit comments