Skip to content

docs: document the code completion pipeline#867

Closed
chronicgiardia wants to merge 1 commit into
github:mainfrom
chronicgiardia:docs/completion-pipeline
Closed

docs: document the code completion pipeline#867
chronicgiardia wants to merge 1 commit into
github:mainfrom
chronicgiardia:docs/completion-pipeline

Conversation

@chronicgiardia

Copy link
Copy Markdown

Summary

Adds Docs/CompletionPipeline.md — a developer reference document covering the full end-to-end flow for GitHub Copilot inline code completions.

What's documented

Pipeline overview — ASCII diagram of all five layers:
EditorExtension → CommunicationBridge → ExtensionService → SuggestionService → LSP client → copilot-language-server → GitHub API

Trigger modes

  • On-demand (GetSuggestionsCommand) — why completionHandler(nil) must fire before the async work
  • Realtime prefetch (RealtimeSuggestionController) — keystroke-driven caching

Layer-by-layer breakdown

  1. EditorExtension — sandboxing constraints, EditorContent packaging
  2. XPC transport — XPCServiceProtocol method table (9 completion methods), CommunicationBridge relay rationale
  3. ExtensionService / XPCService — workspace location via AX API, filespace state management
  4. Suggestion middleware chain — PostProcessingSuggestionServiceMiddleware filter rules
  5. LSP client — GitHubCopilotService, JSON-RPC request types, server notification table, document sync callbacks and the -32602 reopen workaround

Suggestion injection — multi-byte/emoji handling, [Modification] semantics

Accept/reject cycle — full flow including telemetry back to the LSP server

Key source file index — 13 files mapped to layer and role

Motivation

The completion pipeline spans five processes, two XPC hops, and a stdio LSP subprocess. Understanding how a keypress becomes a displayed suggestion (and why certain architectural choices exist, like the early completionHandler(nil)) currently requires reading across a dozen files. This document consolidates that knowledge in one place.

Adds Docs/CompletionPipeline.md covering the full end-to-end flow:
- Trigger modes (on-demand vs realtime/prefetch)
- All five layers: EditorExtension → XPC → ExtensionService →
  SuggestionService middleware chain → LSP client (GitHubCopilotService)
- XPC protocol methods table
- LSP JSON-RPC request types and server notifications
- SuggestionInjector buffer modification semantics
- Accept/reject cycle with telemetry
- Key source file index

Co-Authored-By: Oz <oz-agent@warp.dev>
Copilot AI review requested due to automatic review settings June 23, 2026 08:16
@github-actions

Copy link
Copy Markdown
Contributor

At the moment we are not accepting contributions to the repository.

Feedback for GitHub Copilot for Xcode can be given in the Copilot community discussions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new developer reference document (Docs/CompletionPipeline.md) describing how inline code completions flow through the Copilot for Xcode architecture (editor extension → XPC relay → service app → LSP client → language server → cloud), including trigger modes, per-layer responsibilities, and key source file pointers.

Changes:

  • Introduces a comprehensive completion pipeline overview with an end-to-end diagram and trigger mode descriptions.
  • Documents XPC and LSP boundaries, including the protocol surface area and notification/request types.
  • Adds a “key source files” index mapping major components to their role in the pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


### Realtime (prefetch)

`RealtimeSuggestionController` (in `Core/Sources/Service/`) watches for editor changes via the AX API (`XcodeInspector`) and calls `prefetchRealtimeSuggestions` on every keystroke after a debounce delay. The prefetched suggestion is cached in the filespace so it can be displayed immediately when the user pauses.

### Protocol

`XPCServiceProtocol` is the `@objc` protocol that defines the raw XPC interface. All parameters are `Data` (JSON-encoded payloads) to satisfy the XPC serialisation requirement.
Comment on lines +125 to +129
1. **Decode** `Data` → `EditorContent`.
2. **Locate workspace** — uses `XcodeInspector` (AX API) to find the open workspace and the active file URL.
3. **Delegate to `WorkspaceSuggestionService`** — which manages per-filespace suggestion state (current index, suggestion list, snapshot for invalidation checks).
4. **Inject into filespace** — `SuggestionInjector` computes the line modifications.
5. **Encode** `UpdatedContent` → `Data` and reply.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants