Skip to content

Commit 701928a

Browse files
committed
feat(init): generate VS Code debug config
1 parent 7f59215 commit 701928a

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

src/project/initProjectWizard.ts

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { detectProjectType } from './projectType.js';
1010
export async function initProjectWizard(rootDir: string, opts: { diagramFile?: string }) {
1111
const configPath = path.join(rootDir, 'wokwi.toml');
1212
const diagramFilePath = path.resolve(rootDir, opts.diagramFile ?? 'diagram.json');
13+
const launchJsonPath = path.join(rootDir, '.vscode', 'launch.json');
1314

1415
intro(`Wokwi CLI - Project Initialization Wizard`);
1516

@@ -94,21 +95,72 @@ export async function initProjectWizard(rootDir: string, opts: { diagramFile?: s
9495
elfPath = elfPathResponse;
9596
}
9697

98+
let vsCodeDebug: boolean = false;
99+
if (projectType === 'esp-idf') {
100+
const vsCodeDebugAnswer = await confirm({
101+
message: `Setup VS Code debugging for ESP-IDF project?`,
102+
initialValue: true,
103+
});
104+
if (isCancel(vsCodeDebugAnswer)) {
105+
cancel('Operation cancelled.');
106+
process.exit(0);
107+
}
108+
if (vsCodeDebugAnswer) {
109+
vsCodeDebug = true;
110+
}
111+
112+
if (vsCodeDebug && existsSync(launchJsonPath)) {
113+
const shouldContinue = await confirm({
114+
message: `VS Code debugging configuration already exists in .vscode/launch.json. This operation will overwrite it. Continue?`,
115+
initialValue: false,
116+
});
117+
if (!shouldContinue || isCancel(shouldContinue)) {
118+
cancel('Operation cancelled.');
119+
process.exit(0);
120+
}
121+
}
122+
}
123+
124+
const tomlContent = [
125+
`# Wokwi Configuration File`,
126+
`# Reference: https://docs.wokwi.com/vscode/project-config`,
127+
`[wokwi]`,
128+
`version = 1`,
129+
`firmware = '${firmwarePath}'`,
130+
`elf = '${elfPath}'`,
131+
];
132+
if (vsCodeDebug) {
133+
tomlContent.push(`gdbServerPort=3333`);
134+
}
135+
97136
log.info(`Writing wokwi.toml...`);
98-
writeFileSync(
99-
configPath,
100-
`# Wokwi Configuration File
101-
# Reference: https://docs.wokwi.com/vscode/project-config
102-
103-
[wokwi]
104-
version = 1
105-
firmware = '${firmwarePath}'
106-
elf = '${elfPath}'
107-
`,
108-
);
137+
writeFileSync(configPath, tomlContent.join('\n') + '\n');
109138

110139
log.info(`Writing diagram.json...`);
111140
writeFileSync(diagramFilePath, JSON.stringify(createDiagram(boardType as string), null, 2));
112141

142+
if (vsCodeDebug) {
143+
log.info(`Writing .vscode/launch.json...`);
144+
const vsCodeLaunchJson = {
145+
version: '0.2.0',
146+
configurations: [
147+
{
148+
name: 'Wokwi GDB',
149+
type: 'cppdbg',
150+
request: 'launch',
151+
// eslint-disable-next-line no-template-curly-in-string
152+
program: '${workspaceFolder}/' + elfPath,
153+
// eslint-disable-next-line no-template-curly-in-string
154+
cwd: '${workspaceFolder}',
155+
MIMode: 'gdb',
156+
// eslint-disable-next-line no-template-curly-in-string
157+
miDebuggerPath: '${command:espIdf.getToolchainGdb}',
158+
miDebuggerServerAddress: 'localhost:3333',
159+
},
160+
],
161+
};
162+
writeFileSync(launchJsonPath, JSON.stringify(vsCodeLaunchJson, null, 2));
163+
}
164+
113165
outro(`You're all set!`);
114166
}

0 commit comments

Comments
 (0)