Skip to content

Commit b97444c

Browse files
author
Akos Kitta
committed
Can customize the launch.json location.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent d670fed commit b97444c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/extension.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { promises as fs } from 'fs';
21
import * as path from 'path';
2+
import { promises as fs } from 'fs';
33
import { spawnSync } from 'child_process';
44
import deepEqual from 'deep-equal';
55
import WebRequest from 'web-request';
@@ -34,6 +34,11 @@ interface DebugConfig {
3434
readonly name?: string;
3535
}
3636
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;
3742
}
3843

3944
interface DebugInfo {
@@ -143,9 +148,6 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
143148
customDebugConfig = JSON.parse(raw);
144149
} catch { }
145150
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();
149151
const launchConfig = {
150152
version: '0.2.0',
151153
'configurations': [
@@ -154,7 +156,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
154156
}
155157
]
156158
};
157-
await configuration.update('launch', launchConfig, false);
159+
await updateLaunchConfig(config, launchConfig);
158160
return vscode.debug.startDebugging(undefined, mergedDebugConfig);
159161
}
160162

@@ -247,3 +249,16 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
247249
}
248250
);
249251
}
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

Comments
 (0)