Beginner

Code Completions

Code completions are the original GitHub Copilot feature β€” as you type, Copilot suggests the next line or block of code as faded β€œghost text.” Press Tab to accept, Escape to dismiss, or keep typing to get a revised suggestion. This happens inline in your editor without switching context to a chat panel.

How It Works

Copilot uses a technique called Fill-in-the-Middle (FIM) to generate completions. Rather than only looking at what's before your cursor, it considers both the code before and after β€” giving it context about what the completed code needs to fit into. The model receives:

  • Prefix β€” code before the cursor (current file, from top)
  • Suffix β€” code after the cursor (rest of the current file)
  • Related files β€” other open tabs and recently edited files in your workspace
  • Comments β€” your inline comments describing intent are strong signals

What It Can Suggest

Single line

Complete the current line β€” variable assignments, function calls, conditions.

Multi-line block

Entire function bodies, class methods, loop bodies based on a function signature or comment.

Tests

Start typing a test function β€” Copilot infers what to test from the function name and generates assertions.

Boilerplate

Config files, import blocks, error handlers, schema definitions β€” pattern-heavy code it can reproduce accurately.

Repetitive patterns

After seeing 2-3 items in a list or switch statement, it can continue the pattern for remaining items.

Documentation strings

Type /** or triple-quote above a function and Copilot drafts the docstring from the function signature and body.

Context Window & Relevance

Copilot doesn't send your entire codebase with every keystroke β€” that would be too slow and too expensive. Instead it uses a relevance-ranked context window:

  • Current file content (highest priority) β€” prefix and suffix around cursor
  • Open editor tabs β€” files you have open contribute to the snippet pool
  • Recently edited files β€” files you've touched recently in the same session
  • Workspace imports β€” files that are imported by the current file

The context window is typically around 8,000–16,000 tokens for completions. Copilot selects the most relevant snippets from open files to fill the window rather than arbitrarily including everything.

Getting Better Completions

Write descriptive comments before code

A comment like `// parse ISO 8601 date, return null if invalid` gives Copilot a strong signal about intent.

Use clear function names

`calculateMonthlyInterestRate()` produces better completions than `calc()`. Names are strong signals.

Open relevant files in tabs

If your function needs to match an interface defined in another file, open that file so it enters the context window.

Provide one example first

For lists or mappings, write the first item manually β€” Copilot picks up the pattern and completes the rest.

Accept partial suggestions

Press Ctrl+β†’ (or Cmd+β†’ on Mac) to accept one word at a time rather than the whole suggestion β€” useful when the suggestion is mostly right.

What to Watch For

  • Hallucinated APIs β€” Copilot may suggest function calls with incorrect parameter names or non-existent methods. Always verify suggested API calls.
  • Security issues β€” suggested code may not follow security best practices (hardcoded values, weak patterns). Review security-sensitive completions carefully.
  • Stale patterns β€” the model's training data has a cutoff. It may suggest deprecated APIs for frameworks that have changed since training.
  • Confidently wrong logic β€” especially in complex algorithms or edge cases, completions can look correct but produce subtle bugs. Test all Copilot-generated logic.

Checklist: Do You Understand This?

  • Ghost text completions are inline β€” Tab accepts, Escape dismisses, Ctrl+β†’ accepts word-by-word
  • Fill-in-the-Middle (FIM): Copilot sees both prefix (before cursor) and suffix (after cursor)
  • Context includes: current file + open tabs + recently edited files + imported files
  • Better completions: descriptive names + inline comments + open relevant files in tabs
  • Always review: API correctness, security implications, edge case handling

Page built: 01 Jun 2026