{"meta":{"title":"Syncing documentation with code changes","intro":"Copilot Chat can help with keeping code documentation up-to-date.","product":"GitHub Copilot","breadcrumbs":[{"href":"/en/copilot","title":"GitHub Copilot"},{"href":"/en/copilot/tutorials","title":"Tutorials"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook","title":"GitHub Copilot Chat Cookbook"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook/document-code","title":"Document code"},{"href":"/en/copilot/tutorials/copilot-chat-cookbook/document-code/sync-documentation","title":"Sync documentation"}],"documentType":"article"},"body":"# Syncing documentation with code changes\n\nCopilot Chat can help with keeping code documentation up-to-date.\n\nIt can be difficult to keep documentation up to date with changes to code. However, good documentation is essential for maintaining codebases and ensuring that developers can work effectively with the code. Copilot Chat can assist in updating existing code documentation.\n\n## Example scenario\n\nImagine a scenario where you have a TypeScript function that retrieves products by category name, but the documentation is out of date.\n\n```typescript id=fetch-products-by-category\n/**\n * Retrieves all products belonging to a specific category.\n *\n * @param categoryId - The unique identifier of the product category\n * @returns Promise that resolves to an array of Product objects\n *\n * @example\n * const products = await getByCategoryName(5);\n * // Returns: [{id: 1, name: \"Product 1\", categoryId: 5}, ...]\n *\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## Example prompt\n\nYou can ask Copilot Chat to update the documentation according to the current code.\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## Example response\n\n> \\[!NOTE] The following response is an example. Copilot Chat responses are non-deterministic, so you may get a different response from the one shown here.\n\nCopilot explains it will create the updated documentation for the `getByCategoryName` function. It then provides the updated documentation, which now includes the `page` and `pageSize` parameters, as well as the `PrismaClientKnownRequestError` error that can be thrown.\n\nFor example:\n\n```typescript\n/**\n * Retrieves all products belonging to a specific category with pagination and recent reviews.\n *\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 *\n * @example\n * const products = await getByCategoryName(5, 2, 20);\n * // Returns: [{id: 1, name: \"Product 1\", categoryId: 5, reviews: [...5 recent reviews]}, ...]\n *\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## Further reading\n\n* [Prompt engineering for GitHub Copilot Chat](/en/copilot/using-github-copilot/prompt-engineering-for-github-copilot)\n* [Best practices for using GitHub Copilot](/en/copilot/using-github-copilot/best-practices-for-using-github-copilot)"}