1
- import * as fs from 'fs' ;
2
1
import * as path from 'path' ;
3
- import { promisify } from 'util ' ;
2
+ import { promises as fs } from 'fs ' ;
4
3
import { spawnSync } from 'child_process' ;
5
4
import deepEqual from 'deep-equal' ;
6
5
import WebRequest from 'web-request' ;
@@ -35,6 +34,11 @@ interface DebugConfig {
35
34
readonly name ?: string ;
36
35
}
37
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 ;
38
42
}
39
43
40
44
interface DebugInfo {
@@ -140,13 +144,10 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
140
144
141
145
let customDebugConfig = { } ;
142
146
try {
143
- const raw = await promisify ( fs . readFile ) ( path . join ( config . sketchPath , 'debug_custom.json' ) , { encoding : 'utf8' } ) ;
147
+ const raw = await fs . readFile ( path . join ( config . sketchPath , 'debug_custom.json' ) , { encoding : 'utf8' } ) ;
144
148
customDebugConfig = JSON . parse ( raw ) ;
145
149
} catch { }
146
150
const mergedDebugConfig = deepmerge ( defaultDebugConfig , customDebugConfig ) ;
147
-
148
- // Create the `launch.json` if it does not exist. Otherwise, update the existing.
149
- const configuration = vscode . workspace . getConfiguration ( ) ;
150
151
const launchConfig = {
151
152
version : '0.2.0' ,
152
153
'configurations' : [
@@ -155,7 +156,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
155
156
}
156
157
]
157
158
} ;
158
- await configuration . update ( 'launch' , launchConfig , false ) ;
159
+ await updateLaunchConfig ( config , launchConfig ) ;
159
160
return vscode . debug . startDebugging ( undefined , mergedDebugConfig ) ;
160
161
}
161
162
@@ -199,7 +200,7 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
199
200
let logPath : string | undefined = undefined ;
200
201
if ( typeof log === 'string' ) {
201
202
try {
202
- const stats = await promisify ( fs . stat ) ( log ) ;
203
+ const stats = await fs . stat ( log ) ;
203
204
if ( stats . isDirectory ( ) ) {
204
205
logPath = log ;
205
206
}
@@ -248,3 +249,16 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
248
249
}
249
250
) ;
250
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