@@ -9,40 +9,53 @@ import { Ctx } from "./ctx";
9
9
const debugOutput = vscode . window . createOutputChannel ( "Debug" ) ;
10
10
type DebugConfigProvider = ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) => vscode . DebugConfiguration ;
11
11
12
- function getLldbDebugConfig ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
13
- return {
14
- type : "lldb" ,
15
- request : "launch" ,
16
- name : config . label ,
17
- program : executable ,
18
- args : config . extraArgs ,
19
- cwd : config . cwd ,
20
- sourceMap : sourceFileMap ,
21
- sourceLanguages : [ "rust" ]
22
- } ;
23
- }
12
+ export async function makeDebugConfig ( ctx : Ctx , runnable : ra . Runnable ) : Promise < void > {
13
+ const scope = ctx . activeRustEditor ?. document . uri ;
14
+ if ( ! scope ) return ;
24
15
25
- function getCppvsDebugConfig ( config : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
26
- return {
27
- type : ( os . platform ( ) === "win32" ) ? "cppvsdbg" : "cppdbg" ,
28
- request : "launch" ,
29
- name : config . label ,
30
- program : executable ,
31
- args : config . extraArgs ,
32
- cwd : config . cwd ,
33
- sourceFileMap : sourceFileMap ,
34
- } ;
16
+ const debugConfig = await getDebugConfiguration ( ctx , runnable ) ;
17
+ if ( ! debugConfig ) return ;
18
+
19
+ const wsLaunchSection = vscode . workspace . getConfiguration ( "launch" , scope ) ;
20
+ const configurations = wsLaunchSection . get < any [ ] > ( "configurations" ) || [ ] ;
21
+
22
+ const index = configurations . findIndex ( c => c . name === debugConfig . name ) ;
23
+ if ( index !== - 1 ) {
24
+ const answer = await vscode . window . showErrorMessage ( `Launch configuration '${ debugConfig . name } ' already exists!` , 'Cancel' , 'Update' ) ;
25
+ if ( answer === "Cancel" ) return ;
26
+
27
+ configurations [ index ] = debugConfig ;
28
+ } else {
29
+ configurations . push ( debugConfig ) ;
30
+ }
31
+
32
+ await wsLaunchSection . update ( "configurations" , configurations ) ;
35
33
}
36
34
37
- async function getDebugExecutable ( config : ra . Runnable ) : Promise < string > {
38
- const cargo = new Cargo ( config . cwd || '.' , debugOutput ) ;
39
- const executable = await cargo . executableFromArgs ( config . args ) ;
35
+ export async function startDebugSession ( ctx : Ctx , runnable : ra . Runnable ) : Promise < boolean > {
36
+ let debugConfig : vscode . DebugConfiguration | undefined = undefined ;
37
+ let message = "" ;
40
38
41
- // if we are here, there were no compilation errors.
42
- return executable ;
39
+ const wsLaunchSection = vscode . workspace . getConfiguration ( "launch" ) ;
40
+ const configurations = wsLaunchSection . get < any [ ] > ( "configurations" ) || [ ] ;
41
+
42
+ const index = configurations . findIndex ( c => c . name === runnable . label ) ;
43
+ if ( - 1 !== index ) {
44
+ debugConfig = configurations [ index ] ;
45
+ message = " (from launch.json)" ;
46
+ debugOutput . clear ( ) ;
47
+ } else {
48
+ debugConfig = await getDebugConfiguration ( ctx , runnable ) ;
49
+ }
50
+
51
+ if ( ! debugConfig ) return false ;
52
+
53
+ debugOutput . appendLine ( `Launching debug configuration${ message } :` ) ;
54
+ debugOutput . appendLine ( JSON . stringify ( debugConfig , null , 2 ) ) ;
55
+ return vscode . debug . startDebugging ( undefined , debugConfig ) ;
43
56
}
44
57
45
- export async function getDebugConfiguration ( ctx : Ctx , config : ra . Runnable ) : Promise < vscode . DebugConfiguration | undefined > {
58
+ async function getDebugConfiguration ( ctx : Ctx , runnable : ra . Runnable ) : Promise < vscode . DebugConfiguration | undefined > {
46
59
const editor = ctx . activeRustEditor ;
47
60
if ( ! editor ) return ;
48
61
@@ -78,8 +91,8 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
78
91
return path . normalize ( p ) . replace ( wsFolder , '${workspaceRoot}' ) ;
79
92
}
80
93
81
- const executable = await getDebugExecutable ( config ) ;
82
- const debugConfig = knownEngines [ debugEngine . id ] ( config , simplifyPath ( executable ) , debugOptions . sourceFileMap ) ;
94
+ const executable = await getDebugExecutable ( runnable ) ;
95
+ const debugConfig = knownEngines [ debugEngine . id ] ( runnable , simplifyPath ( executable ) , debugOptions . sourceFileMap ) ;
83
96
if ( debugConfig . type in debugOptions . engineSettings ) {
84
97
const settingsMap = ( debugOptions . engineSettings as any ) [ debugConfig . type ] ;
85
98
for ( var key in settingsMap ) {
@@ -100,25 +113,35 @@ export async function getDebugConfiguration(ctx: Ctx, config: ra.Runnable): Prom
100
113
return debugConfig ;
101
114
}
102
115
103
- export async function startDebugSession ( ctx : Ctx , config : ra . Runnable ) : Promise < boolean > {
104
- let debugConfig : vscode . DebugConfiguration | undefined = undefined ;
105
- let message = "" ;
106
-
107
- const wsLaunchSection = vscode . workspace . getConfiguration ( "launch" ) ;
108
- const configurations = wsLaunchSection . get < any [ ] > ( "configurations" ) || [ ] ;
116
+ async function getDebugExecutable ( runnable : ra . Runnable ) : Promise < string > {
117
+ const cargo = new Cargo ( runnable . cwd || '.' , debugOutput ) ;
118
+ const executable = await cargo . executableFromArgs ( runnable . args ) ;
109
119
110
- const index = configurations . findIndex ( c => c . name === config . label ) ;
111
- if ( - 1 !== index ) {
112
- debugConfig = configurations [ index ] ;
113
- message = " (from launch.json)" ;
114
- debugOutput . clear ( ) ;
115
- } else {
116
- debugConfig = await getDebugConfiguration ( ctx , config ) ;
117
- }
120
+ // if we are here, there were no compilation errors.
121
+ return executable ;
122
+ }
118
123
119
- if ( ! debugConfig ) return false ;
124
+ function getLldbDebugConfig ( runnable : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
125
+ return {
126
+ type : "lldb" ,
127
+ request : "launch" ,
128
+ name : runnable . label ,
129
+ program : executable ,
130
+ args : runnable . extraArgs ,
131
+ cwd : runnable . cwd ,
132
+ sourceMap : sourceFileMap ,
133
+ sourceLanguages : [ "rust" ]
134
+ } ;
135
+ }
120
136
121
- debugOutput . appendLine ( `Launching debug configuration${ message } :` ) ;
122
- debugOutput . appendLine ( JSON . stringify ( debugConfig , null , 2 ) ) ;
123
- return vscode . debug . startDebugging ( undefined , debugConfig ) ;
137
+ function getCppvsDebugConfig ( runnable : ra . Runnable , executable : string , sourceFileMap ?: Record < string , string > ) : vscode . DebugConfiguration {
138
+ return {
139
+ type : ( os . platform ( ) === "win32" ) ? "cppvsdbg" : "cppdbg" ,
140
+ request : "launch" ,
141
+ name : runnable . label ,
142
+ program : executable ,
143
+ args : runnable . extraArgs ,
144
+ cwd : runnable . cwd ,
145
+ sourceFileMap : sourceFileMap ,
146
+ } ;
124
147
}
0 commit comments