{"meta":{"title":"ドキュメントとコードの変更の同期","intro":"コパイロットチャット は、コードのドキュメントを最新の状態に保つのに役立ちます。","product":"GitHub Copilot","breadcrumbs":[{"href":"/ja/copilot","title":"GitHub Copilot"},{"href":"/ja/copilot/tutorials","title":"チュートリアル"},{"href":"/ja/copilot/tutorials/copilot-chat-cookbook","title":"GitHub Copilot チャットクックブック"},{"href":"/ja/copilot/tutorials/copilot-chat-cookbook/document-code","title":"コードを文書化する"},{"href":"/ja/copilot/tutorials/copilot-chat-cookbook/document-code/sync-documentation","title":"ドキュメントを同期する"}],"documentType":"article"},"body":"# ドキュメントとコードの変更の同期\n\nコパイロットチャット は、コードのドキュメントを最新の状態に保つのに役立ちます。\n\nコードに対する変更でドキュメントを最新の状態に保つのは難しい場合があります。 しかし、コードベースを維持し、開発者がコードを効果的に操作できるようにするためには、適切なドキュメントが不可欠です。 コパイロットチャット は、既存のコード ドキュメントの更新を支援できます。\n\n## シナリオ例\n\nカテゴリ名で製品を取得する TypeScript 関数があり、しかしドキュメントが古くなっているシナリオを想像してみてください。\n\n```typescript id=fetch-products-by-category\n/**\n * Retrieves all products belonging to a specific category.\n * * @param categoryId - The unique identifier of the product category\n * @returns Promise that resolves to an array of Product objects\n * * @example\n * const products = await getByCategoryName(5);\n * // Returns: [{id: 1, name: \"Product 1\", categoryId: 5}, ...]\n * * @throws {PrismaClientKnownRequestError} If database query fails\n * @see {@link https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany}\n */\nasync getByCategoryName(categoryId: number, page = 1, pageSize = 10): Promise<Products[]> {\n  return await prisma.products.findMany({\n    where: { categoryId },\n    skip: (page - 1) * pageSize,\n    take: pageSize,\n    include: {\n      reviews: {\n        orderBy: { date: 'desc' },\n        take: 5,\n      },\n    },\n  });\n}\n```\n\n## プロンプトの例\n\n現在のコードに従ってドキュメントを更新するよう、コパイロットチャット に依頼できます。\n\n```copilot copy prompt ref=fetch-products-by-category\nUpdate the existing documentation for the getByCategoryName function to reflect the current implementation.\n```\n\n## 応答の例\n\n> \\[!NOTE] 次の応答は例です。 コパイロットチャット の応答は非決定的であるため、ここで示したものとは異なる応答が返される可能性があります。\n\nCopilot は、`getByCategoryName` 関数の更新されたドキュメントを作成することを説明します。 次に、更新されたドキュメントを提供します。それには、`page` と `pageSize` パラメーター、およびスローされる可能性がある `PrismaClientKnownRequestError` エラーが含まれるようになりました。\n\n次に例を示します。\n\n```typescript\n/**\n * Retrieves all products belonging to a specific category with pagination and recent reviews.\n * * @param categoryId - The unique identifier of the product category\n * @param page - The page number for pagination (default: 1)\n * @param pageSize - Number of products per page (default: 10)\n * @returns Promise that resolves to an array of Product objects with their 5 most recent reviews\n * * @example\n * const products = await getByCategoryName(5, 2, 20);\n * // Returns: [{id: 1, name: \"Product 1\", categoryId: 5, reviews: [...5 recent reviews]}, ...]\n * * @throws {PrismaClientKnownRequestError} If database query fails\n * @see {@link https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany}\n */\n```\n\n## 参考資料\n\n* [GitHub Copilot Chat のプロンプト エンジニアリング](/ja/copilot/using-github-copilot/prompt-engineering-for-github-copilot)\n* [GitHub Copilot の使用に関するベスト プラクティス](/ja/copilot/using-github-copilot/best-practices-for-using-github-copilot)"}