export async function executeCreateCode(context: vscode.ExtensionContext) {
    try {
        // 開かれているエディタ画面において選択されたテキストを取得
        const editor = vscode.window.activeTextEditor;
        
        if (!editor) {
            vscode.window.showErrorMessage('どのエディタも開かれていません。');
            return;
        }
        const selection = editor.selection;
        const userPrompt = editor.document.getText(selection);
        if (!userPrompt.trim()) {
            vscode.window.showWarningMessage('選択されたテキストがありません。');
            return;
        }
        // プログラム仕様書として記録
        const programSpecification = userPrompt;
        // toolsのgetCreateCodePrompt関数を利用してシステムプロンプトを取得
        const systemPrompt = getCreateCodePrompt();
        // generateCode 関数に、プログラム仕様書とシステムプロンプトを渡し、プログラムコードを作成
        const generatedCode = await generateCode(systemPrompt, programSpecification);
        if (!generatedCode) {
            vscode.window.showErrorMessage('コードの生成に失敗しました。');
            return;
        }
        // 新しいエディタウィンドウで生成されたコードを表示
        const newEditor = await vscode.workspace.openTextDocument({ content: generatedCode });
        await vscode.window.showTextDocument(newEditor);
    } catch (error) {
        console.error('executeCreateCode関数内でエラーが発生しました:', error);
        vscode.window.showErrorMessage('コード生成中に予期しないエラーが発生しました。');
    }
}