zed-industries/zed
Editor
Active contributors: Veykril, SomeoneToIgnore, ConradIrwin, mikayla-maki
Purpose
crates/editor is the editor view. At ~147k LOC it is the largest crate in the workspace. It renders a MultiBuffer with cursors, selections, decorations, completions, hover popovers, signature help, code actions, inline diagnostics, and the rest of the surface a code editor exposes. Most editor-facing features live here or in adjacent UI crates.
Directory layout
crates/editor/ ~147k LOC
├── Cargo.toml
├── benches/ # Hot-path benchmarks
└── src/
├── editor.rs # Module root
├── element.rs # The GPUI Element implementation that draws editors
├── display_map/ # Buffer offsets ↔ display rows/columns
├── selection_history.rs # Undo/redo for selections
├── inlay_hint_cache.rs # LSP inlay hints
├── code_actions.rs # Quick-fixes, refactors
├── lsp/ # Editor-side LSP integration (completions, hover, …)
├── git/ # Inline blame, hunk gutter
└── ... # 100+ modules
crates/multi_buffer/ # The "logical" buffer
crates/text/ # CRDT text buffer (offsets, anchors, history)
crates/rope/ # Underlying rope data structure
crates/buffer_diff/ # Diff between two buffers (used for git, agent edits, …)Key abstractions
| Type | File | Description |
|---|---|---|
Editor |
crates/editor/src/editor.rs |
The view entity |
EditorElement |
crates/editor/src/element.rs |
The GPUI Element that paints an editor |
MultiBuffer |
crates/multi_buffer/src/multi_buffer.rs |
A logical buffer composed of excerpts from multiple Buffers |
Buffer |
crates/language/src/buffer.rs |
A single text file, with text + syntax + diagnostics |
DisplayMap |
crates/editor/src/display_map.rs |
Wrapping, folds, inlay hints, blocks |
Anchor |
crates/text/src/anchor.rs, crates/multi_buffer/src/anchor.rs |
Edit-resilient positions |
Selection |
crates/editor/src/editor.rs |
A (start, end, head) range |
Rope |
crates/rope/src/rope.rs |
Persistent rope of UTF-8 chunks |
BufferDiff |
crates/buffer_diff/src/buffer_diff.rs |
Per-line diff state |
How it works
graph TD
P[Project] -->|provides Buffer| MB[MultiBuffer]
MB -->|excerpts| E[Editor]
E -->|render| EE[EditorElement]
EE -->|paint| W[Window]
LSP[LSP] -->|completions, diagnostics| E
Tree[tree-sitter] -->|syntax highlighting| MB
Git[GitStore] -->|hunk diffs| E
Agent[Agent] -->|streamed edits| E
User[User input] -->|key events| EE
EE --> EDisplay map
DisplayMap is the layer that translates between buffer space (UTF-8 byte offsets in the underlying Buffer) and display space (rows/columns of what the user actually sees). It accounts for:
- Soft wrap.
- Folds (collapsed regions).
- Inlay hints (LSP-provided ghost text).
- Block decorations (e.g. expanded diagnostic, agent message).
- Replacement folds (e.g. summarised function bodies).
Most rendering code works in display space; most semantic code works in buffer space.
Selections and cursors
A single Editor can have arbitrarily many selections (multi-cursor). Each is a Selection with start, end, and head (the active end, where the cursor sits). Mutations preserve selection invariants by mapping anchors through edits.
MultiBuffer
A MultiBuffer is one logical document made of excerpts pulled from many Buffers. It powers:
- Search results across files.
- Diagnostic panels.
- Project-wide code-actions.
- Git diff views.
- The agent's "files I edited" view (
acp_thread::ThreadFileEdits).
Edits in a MultiBuffer route back into the underlying Buffers, so a save still writes to the original files.
Tree-sitter integration
Syntax trees live on the Buffer (in crates/language) and update incrementally as text changes. The editor reads the tree to drive highlighting, brackets, smart indent, and outline.
Integration points
- Below:
multi_buffer,text,rope,buffer_diff,language,tree-sitter. - Sibling:
crates/git_ui(for hunk gutter),crates/diagnostics(for inline diagnostics),crates/code_actions(where applicable). - Above:
crates/workspacefor tab/pane management.
Entry points for modification
- New decoration kind —
crates/editor/src/display_map/. - New cursor / selection action — extend the action set in
crates/editor/src/editor.rs. Wire up to keymaps inassets/keymaps/. - New LSP capability surfacing —
crates/editor/src/lsp/. - Tweak rendering hot paths —
crates/editor/src/element.rsplus the benches.
Related pages
- Project — supplies buffers
- Language services — supplies syntax + per-language behaviour
- LSP — supplies semantic features
- Vim mode — modal layer over
Editor
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.