@@ -64,29 +64,20 @@ export function runSingle(ctx: Ctx): Cmd {
6464 } ;
6565}
6666
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 {
6868 return {
6969 type : "lldb" ,
7070 request : "launch" ,
7171 name : config . label ,
72- cargo : {
73- args : config . args ,
74- } ,
72+ program : executable ,
7573 args : config . extraArgs ,
7674 cwd : config . cwd ,
77- sourceMap : sourceFileMap
75+ sourceMap : sourceFileMap ,
76+ sourceLanguages : [ "rust" ]
7877 } ;
7978}
8079
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 {
9081 return {
9182 type : ( os . platform ( ) === "win32" ) ? "cppvsdbg" : 'cppdbg' ,
9283 request : "launch" ,
@@ -98,39 +89,62 @@ async function getCppvsDebugConfig(config: ra.Runnable, sourceFileMap: Record<st
9889 } ;
9990}
10091
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+
101104export function debugSingle ( ctx : Ctx ) : Cmd {
102105 return async ( config : ra . Runnable ) => {
103106 const editor = ctx . activeRustEditor ;
104107 if ( ! editor ) return ;
105108
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 ;
108114
109- const debugEngineId = ctx . config . debug . engine ;
110115 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 ;
115120 }
116121 }
117122 else {
118- debugEngine = vscode . extensions . getExtension ( debugEngineId ) ;
123+ debugEngine = vscode . extensions . getExtension ( debugOptions . engine ) ;
119124 }
120125
121126 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.` ) ;
127129 return ;
128130 }
129131
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+ }
133145
146+ debugOutput . appendLine ( "Launching debug configuration:" ) ;
147+ debugOutput . appendLine ( JSON . stringify ( debugConfig , null , 2 ) ) ;
134148 return vscode . debug . startDebugging ( undefined , debugConfig ) ;
135149 } ;
136150}
0 commit comments