From ea16618a8d219e40999534c15c4b2a1b650fc950 Mon Sep 17 00:00:00 2001 From: ahogappa Date: Sun, 4 May 2025 19:12:46 +0900 Subject: [PATCH] feat: add init command --- package.json | 5 +++++ src/extension.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/package.json b/package.json index a0799de..aed8095 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,11 @@ "command": "typeprof.restart", "title": "Restart", "category": "TypeProf" + }, + { + "command": "typeprof.init", + "title": "Generate a TypeProf configuration file", + "category": "TypeProf" } ], "configuration": [ diff --git a/src/extension.ts b/src/extension.ts index 95432c7..e82914e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -378,10 +378,39 @@ function addRestartCommand(context: vscode.ExtensionContext) { context.subscriptions.push(disposable); } +function addInitCommand(context: vscode.ExtensionContext) { + const disposable = vscode.commands.registerCommand('typeprof.init', () => { + if (!vscode.workspace.workspaceFolders) { + return; + } + + for (const folder of vscode.workspace.workspaceFolders) { + if (folder.uri.scheme === 'file') { + let typeprof = executeTypeProf(folder, '--init'); + typeprof.stdout.on('data', (data) => { + let mes = ('' + data).trim(); + if (mes === 'invalid option: --init') { + vscode.window.showErrorMessage( + 'The version of TypeProf does not support the `--init` option. Please check the version of TypeProf and update it.', + ); + } + }); + typeprof.stderr.on('data', (data) => { + vscode.window.showErrorMessage(`Failed to generate TypeProf config file: ${data}`); + }); + + break; + } + } + }); + context.subscriptions.push(disposable); +} + let outputChannel: vscode.OutputChannel; let traceOutputChannel: vscode.OutputChannel | undefined; export function activate(context: vscode.ExtensionContext) { outputChannel = vscode.window.createOutputChannel('Ruby TypeProf'); + addInitCommand(context); addToggleButton(context); addJumpToOutputChannel(context); addJumpToRBS(context);