in src/launchConfigManager.ts [76:109]
async configureLaunchJson(): Promise<void> {
if (!vscode.workspace.workspaceFolders) {
void vscode.window.showErrorMessage('Cannot configure launch.json for an empty workspace. Please open a folder in the editor.');
return;
}
// Create ./.vscode/launch.json if it doesn't already exist
const workspaceUri = vscode.workspace.workspaceFolders[0].uri;
const relativePath = '/.vscode/launch.json';
fse.ensureFileSync(workspaceUri.fsPath + relativePath);
// Append a supported debug config to their list of configurations and update workspace configuration
const launchJson = vscode.workspace.getConfiguration('launch', workspaceUri);
const configs = launchJson.get('configurations') as vscode.DebugConfiguration[];
configs.push(providedDebugConfig);
await launchJson.update('configurations', configs) as unknown as Promise<void>;
// Insert instruction comment
let launchText = fse.readFileSync(workspaceUri.fsPath + relativePath).toString();
const re = new RegExp(`{(.|\\n|\\s)*(${providedDebugConfig.type})(.|\\n|\\s)*(${providedDebugConfig.url}")`, 'm');
const match = re.exec(launchText);
const instructions = ' // Provide your project\'s url to finish configuring';
launchText = launchText.replace(re, `${match ? match[0] : ''}${instructions}`);
fse.writeFileSync(workspaceUri.fsPath + relativePath, launchText);
// Open launch.json in editor
void vscode.commands.executeCommand('vscode.open', vscode.Uri.joinPath(workspaceUri, relativePath));
this.updateLaunchConfig();
}
isValidLaunchConfig(): boolean {
return this.isValidConfig;
}
}