Concretely, how does GitHub Copilot work to generate its code suggestions ?
Answer
Copilot analyzes the local context of the file being edited, often supplemented by other open or related files in the editor, and sends that context to a language model trained on large amounts of source code. The model predicts the most likely continuation of the code given that context, somewhat like a keyboard's predictive completion but applied to code, and proposes one or more suggestions the developer can accept, edit or ignore. It's not a search engine retrieving existing code: each suggestion is generated, not copied verbatim from a specific source.
Common trap
The trap is believing Copilot understands the project's business intent the way a developer would: it predicts a plausible continuation of code based on statistical patterns, not on real understanding of business rules, which is why suggestions always need a critical read against the actual context.