@@ -81,8 +81,9 @@ async function getDebugConfiguration(
81
81
if ( ! editor ) return ;
82
82
83
83
const knownEngines : Record < string , DebugConfigProvider > = {
84
- "vadimcn.vscode-lldb" : getLldbDebugConfig ,
85
- "ms-vscode.cpptools" : getCppvsDebugConfig ,
84
+ "ms-vscode.cpptools" : getCCppDebugConfig ,
85
+ "vadimcn.vscode-lldb" : getCodeLldbDebugConfig ,
86
+ "webfreak.debug" : getNativeDebugConfig ,
86
87
} ;
87
88
const debugOptions = ctx . config . debug ;
88
89
@@ -97,12 +98,14 @@ async function getDebugConfiguration(
97
98
}
98
99
99
100
if ( ! debugEngine ) {
101
+ const commandCCpp : string = createCommandLink ( "ms-vscode.cpptools" ) ;
100
102
const commandCodeLLDB : string = createCommandLink ( "vadimcn.vscode-lldb" ) ;
101
- const commandCpp : string = createCommandLink ( "ms-vscode.cpptools " ) ;
103
+ const commandNativeDebug : string = createCommandLink ( "webfreak.debug " ) ;
102
104
103
105
await vscode . window . showErrorMessage (
104
106
`Install [CodeLLDB](command:${ commandCodeLLDB } "Open CodeLLDB")` +
105
- ` or [C/C++](command:${ commandCpp } "Open C/C++") extension for debugging.` ,
107
+ `, [C/C++](command:${ commandCCpp } "Open C/C++") ` +
108
+ `or [Native Debug](command:${ commandNativeDebug } "Open Native Debug") for debugging.` ,
106
109
) ;
107
110
return ;
108
111
}
@@ -184,41 +187,76 @@ async function getDebugExecutableInfo(
184
187
return executableInfo ;
185
188
}
186
189
187
- function getLldbDebugConfig (
190
+ function getCCppDebugConfig (
188
191
runnable : ra . Runnable ,
189
192
executable : string ,
190
193
cargoWorkspace : string ,
191
194
env : Record < string , string > ,
192
195
sourceFileMap ?: Record < string , string > ,
193
196
) : vscode . DebugConfiguration {
194
197
return {
195
- type : "lldb ",
198
+ type : os . platform ( ) === "win32" ? "cppvsdbg" : "cppdbg ",
196
199
request : "launch" ,
197
200
name : runnable . label ,
198
201
program : executable ,
199
202
args : runnable . args . executableArgs ,
200
203
cwd : cargoWorkspace || runnable . args . workspaceRoot ,
201
- sourceMap : sourceFileMap ,
202
- sourceLanguages : [ "rust" ] ,
204
+ sourceFileMap,
203
205
env,
204
206
} ;
205
207
}
206
208
207
- function getCppvsDebugConfig (
209
+ function getCodeLldbDebugConfig (
208
210
runnable : ra . Runnable ,
209
211
executable : string ,
210
212
cargoWorkspace : string ,
211
213
env : Record < string , string > ,
212
214
sourceFileMap ?: Record < string , string > ,
213
215
) : vscode . DebugConfiguration {
214
216
return {
215
- type : os . platform ( ) === "win32" ? "cppvsdbg" : "cppdbg ",
217
+ type : "lldb ",
216
218
request : "launch" ,
217
219
name : runnable . label ,
218
220
program : executable ,
219
221
args : runnable . args . executableArgs ,
220
222
cwd : cargoWorkspace || runnable . args . workspaceRoot ,
221
- sourceFileMap,
223
+ sourceMap : sourceFileMap ,
224
+ sourceLanguages : [ "rust" ] ,
222
225
env,
223
226
} ;
224
227
}
228
+
229
+ function getNativeDebugConfig (
230
+ runnable : ra . Runnable ,
231
+ executable : string ,
232
+ cargoWorkspace : string ,
233
+ env : Record < string , string > ,
234
+ _sourceFileMap ?: Record < string , string > ,
235
+ ) : vscode . DebugConfiguration {
236
+ return {
237
+ type : "gdb" ,
238
+ request : "launch" ,
239
+ name : runnable . label ,
240
+ target : executable ,
241
+ // See https://github.com/WebFreak001/code-debug/issues/359
242
+ arguments : quote ( runnable . args . executableArgs ) ,
243
+ cwd : cargoWorkspace || runnable . args . workspaceRoot ,
244
+ env,
245
+ valuesFormatting : "prettyPrinters" ,
246
+ } ;
247
+ }
248
+
249
+ // Based on https://github.com/ljharb/shell-quote/blob/main/quote.js
250
+ function quote ( xs : string [ ] ) {
251
+ return xs
252
+ . map ( function ( s ) {
253
+ if ( / [ " \s ] / . test ( s ) && ! / ' / . test ( s ) ) {
254
+ return "'" + s . replace ( / ( [ ' \\ ] ) / g, "\\$1" ) + "'" ;
255
+ }
256
+ if ( / [ " ' \s ] / . test ( s ) ) {
257
+ return '"' + s . replace ( / ( [ " \\ $ ` ! ] ) / g, "\\$1" ) + '"' ;
258
+ }
259
+ return s . replace ( / ( [ A - Z a - z ] : ) ? ( [ # ! " $ & ' ( ) * , : ; < = > ? @ [ \\ \] ^ ` { | } ] ) / g, "$1\\$2" ) ;
260
+ } )
261
+ . join ( " " ) ;
262
+ }
0 commit comments