Document a project with GitHub Copilot

Use GitHub Copilot to draft code comments, a README or API documentation in VS Code.

Format
10 minEnglish
Updated 10 min

What you will create

Prepare documentation that explains how a small part of your project actually behaves: its purpose, inputs, outputs and limits. The goal is not a comment on every line, but enough clarity for someone else to use the code without guessing its rules.

Before you start

Open a project you are authorized to share with GitHub Copilot. In VS Code, check your access to Copilot Chat; organizations can disable it. Choose a short file and its tests. Exclude secrets and personal data. Preserve a reference version so you can review changes, and do not authorize functional changes disguised as documentation work.

Step-by-step

  1. Open Copilot Chat and select Ask if offered. Request an explanation first, without file edits or commands.
  2. Add the file and its tests explicitly using the context picker or a # reference. Searching a project does not put every file into the conversation context.
  3. Ask for observed facts separately from assumptions: expected input types, returned value, errors, side effects and limits.
  4. Request a function comment and usage example. For a README, ask only for relevant sections and require “needs verification” for unconfirmed installation commands.
  5. Compare the text against the code, correct unsupported claims and apply only the documentation changes you retain.

Example to adapt

This deliberately simple function is a practice example:

def total_quantities(values):
    return sum(values)

Try: “Document this function for a beginner colleague. Explain the expected input, return value and empty-list case. Do not claim that it validates data or rejects negative values. Include two examples. Do not change the code.”

The expected result for [2, 3] is 5; for [], it is 0. A useful description says that this function adds the supplied values. It does not invent stock validation or monetary rounding. [-1, 3] produces 2: if negative quantities are forbidden in your business, implement that rule separately rather than claim it already exists in a comment.

Check your result

  • Every documented parameter exists, and every example matches the documented version.
  • Edge cases are explained without turning assumptions into guarantees.
  • The diff contains no unwanted functional change.
  • Project tests remain consistent; the practice exercise's expected values do not replace running those tests.

Common problems

Generic description: narrow the scope to one function and supply an anonymized real call. Invented API: ask which file supports the claim, then remove anything unsupported. Too many comments: keep explanations of decisions and constraints rather than paraphrases of each statement. Outdated README: check commands against the project before recommending them.

Next steps

Explore the GitHub Copilot overview and apply the same approach to a second module, asking someone unfamiliar with it to review the documentation.