zed-industries/zed
Edit prediction
Active contributors: rtfeldman, benbrandt
Purpose
Edit prediction is Zed's inline AI completion. As you edit, a model proposes a multi-line change; you accept (Tab) or reject (Esc). It is distinct from LSP completions — it can rewrite code in arbitrary ways, not just append at the cursor.
Crates
| Crate | Role |
|---|---|
crates/edit_prediction |
Core: provider trait, request lifecycle |
crates/edit_prediction_context |
Builds the context window sent to the model |
crates/edit_prediction_types |
Shared types between provider implementations |
crates/edit_prediction_ui |
Inline ghost-text and accept-toolbar |
crates/edit_prediction_metrics |
Quality + latency metrics |
crates/edit_prediction_cli |
CLI for testing edit-prediction outside the editor |
crates/zeta_prompt |
First-party Zeta model prompt |
crates/copilot |
Copilot adapter (legacy completions) |
Key abstractions
| Type | File | Description |
|---|---|---|
EditPredictionProvider |
crates/edit_prediction/src/... |
Trait every backend implements |
Suggestion |
crates/edit_prediction_types/src/... |
One proposed edit |
Context |
crates/edit_prediction_context/src/... |
Surrounding buffer + cursor + recent edits |
| Inline view | crates/edit_prediction_ui/src/... |
The ghost-text element rendered in the editor |
How it works
sequenceDiagram
participant E as Editor
participant CTX as edit_prediction_context
participant P as EditPredictionProvider
participant UI as edit_prediction_ui
E->>CTX: cursor moved / text changed
CTX->>CTX: build context (buffer slice, recent edits, language, …)
CTX->>P: request_suggestion(context)
P-->>CTX: stream tokens
CTX->>UI: render ghost text
E->>UI: Tab pressed
UI-->>E: apply suggestionProviders
The default provider is Zeta, Zed's first-party model, with prompts in crates/zeta_prompt. Other providers wired through:
crates/copilot— Microsoft Copilot completions.- (Other adapters can be added by implementing
EditPredictionProvider.)
The choice is a setting; the registry is wired in crates/zed/src/zed/edit_prediction_registry.rs.
Context construction
crates/edit_prediction_context decides what to feed the model:
- The current buffer slice around the cursor.
- Recent edits (so the model sees the trajectory).
- Language and file path.
- Surrounding open files (configurable).
- Project-level
.rulescontent.
UI
When a suggestion arrives, crates/edit_prediction_ui renders it as ghost text inline in the editor with a small toolbar (Accept / Reject / Next / Previous). It composes with the editor's DisplayMap so wrap, fold, and scroll states stay correct.
Metrics
crates/edit_prediction_metrics records acceptance rate, latency, and per-language stats. These flow through telemetry only when the user opts in.
Integration points
- Reads: open buffers, recent edit history, project
.rules. - Writes: ghost text in the editor; on accept, applies a regular edit.
- Connects to: language-model providers (Zeta runs through the cloud gateway; Copilot uses the GitHub auth flow).
Entry points for modification
- New provider — implement
EditPredictionProvider, register incrates/zed/src/zed/edit_prediction_registry.rs. - Tweak context —
crates/edit_prediction_context. - Tweak prompt —
crates/zeta_prompt. - Inline UI changes —
crates/edit_prediction_ui. - CLI evaluation —
crates/edit_prediction_cli.
Related pages
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.