From d670fed567f180367edb4c9d57cb9484bfd04bb2 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 1 Mar 2021 13:20:39 +0100 Subject: [PATCH 1/2] GH-18: Use promisified `fs` functions. Closes: #18 Signed-off-by: Akos Kitta --- src/extension.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 36ddf20..1ef8bc5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,5 @@ -import * as fs from 'fs'; +import { promises as fs } from 'fs'; import * as path from 'path'; -import { promisify } from 'util'; import { spawnSync } from 'child_process'; import deepEqual from 'deep-equal'; import WebRequest from 'web-request'; @@ -140,7 +139,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise Date: Wed, 3 Mar 2021 13:08:30 +0100 Subject: [PATCH 2/2] Can customize the `launch.json` location. Signed-off-by: Akos Kitta --- src/extension.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 1ef8bc5..68b12fc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ -import { promises as fs } from 'fs'; import * as path from 'path'; +import { promises as fs } from 'fs'; import { spawnSync } from 'child_process'; import deepEqual from 'deep-equal'; import WebRequest from 'web-request'; @@ -34,6 +34,11 @@ interface DebugConfig { readonly name?: string; } readonly sketchPath: string; + /** + * Location where the `launch.config` will be created on the fly before starting every debug session. + * If not defined, it falls back to `sketchPath/.vscode/launch.json`. + */ + readonly configPath?: string; } interface DebugInfo { @@ -143,9 +148,6 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise { + if (debugConfig.configPath) { + await fs.mkdir(debugConfig.configPath, { recursive: true }); + await fs.writeFile(path.join(debugConfig.configPath, 'launch.json'), JSON.stringify(launchConfig, null, 2)); + } else { + const configuration = vscode.workspace.getConfiguration(); + await configuration.update('launch', launchConfig, false); + } +}