1
- import { promises as fs } from 'fs' ;
2
1
import * as path from 'path' ;
2
+ import { promises as fs } from 'fs' ;
3
3
import { spawnSync } from 'child_process' ;
4
4
import deepEqual from 'deep-equal' ;
5
5
import WebRequest from 'web-request' ;
@@ -34,6 +34,11 @@ interface DebugConfig {
34
34
readonly name ?: string ;
35
35
}
36
36
readonly sketchPath : string ;
37
+ /**
38
+ * Location where the `launch.config` will be created on the fly before starting every debug session.
39
+ * If not defined, it falls back to `sketchPath/.vscode/launch.json`.
40
+ */
41
+ readonly configPath ?: string ;
37
42
}
38
43
39
44
interface DebugInfo {
@@ -143,9 +148,6 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
143
148
customDebugConfig = JSON . parse ( raw ) ;
144
149
} catch { }
145
150
const mergedDebugConfig = deepmerge ( defaultDebugConfig , customDebugConfig ) ;
146
-
147
- // Create the `launch.json` if it does not exist. Otherwise, update the existing.
148
- const configuration = vscode . workspace . getConfiguration ( ) ;
149
151
const launchConfig = {
150
152
version : '0.2.0' ,
151
153
'configurations' : [
@@ -154,7 +156,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
154
156
}
155
157
]
156
158
} ;
157
- await configuration . update ( 'launch' , launchConfig , false ) ;
159
+ await updateLaunchConfig ( config , launchConfig ) ;
158
160
return vscode . debug . startDebugging ( undefined , mergedDebugConfig ) ;
159
161
}
160
162
@@ -247,3 +249,16 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
247
249
}
248
250
) ;
249
251
}
252
+
253
+ /**
254
+ * Instead of writing the `launch.json` to the workspace, the file is written to the temporary binary output location.
255
+ */
256
+ async function updateLaunchConfig ( debugConfig : DebugConfig , launchConfig : object ) : Promise < void > {
257
+ if ( debugConfig . configPath ) {
258
+ await fs . mkdir ( debugConfig . configPath , { recursive : true } ) ;
259
+ await fs . writeFile ( path . join ( debugConfig . configPath , 'launch.json' ) , JSON . stringify ( launchConfig , null , 2 ) ) ;
260
+ } else {
261
+ const configuration = vscode . workspace . getConfiguration ( ) ;
262
+ await configuration . update ( 'launch' , launchConfig , false ) ;
263
+ }
264
+ }
0 commit comments