Open-Source Wikis

/

Zed

/

Reference

/

Data models

zed-industries/zed

Data models

A quick reference for the core types you will keep running into.

Buffer (crates/language/src/buffer.rs)

pub struct Buffer {
    text: text::Buffer,                    // CRDT-flavored rope
    file: Option<Arc<dyn File>>,           // backing file (or None for scratch)
    language: Option<Arc<Language>>,
    syntax_map: SyntaxMap,                 // tree-sitter trees
    diagnostics: DiagnosticsBackend,
    edits_since_save: ...,
    /* … */
}

A Buffer is the in-memory representation of a single text file. Edits are CRDT operations that survive concurrent mutation. Multiple Editors and MultiBuffers can share a single Buffer.

MultiBuffer (crates/multi_buffer/src/multi_buffer.rs)

pub struct MultiBuffer {
    excerpts: SumTree<Excerpt>,
    buffers: HashMap<BufferId, Entity<Buffer>>,
    /* … */
}

A virtual buffer that displays excerpts from many Buffers as one logical document. Search results, diagnostics, agent edits, and similar surfaces all use it.

Project (crates/project/src/project.rs)

pub struct Project {
    worktrees: Vec<Entity<Worktree>>,
    fs: Arc<dyn Fs>,
    lsp_store: Entity<LspStore>,
    debugger_store: Entity<DebuggerStore>,
    task_store: Entity<TaskStore>,
    git_store: Entity<GitStore>,
    terminals: Entity<TerminalStore>,
    collaborators: ...,
    /* … */
}

The model of an open project. Every editor view roots back to one of these.

Worktree (crates/worktree/src/worktree.rs)

A single root folder with a watched entry tree. Worktree::Local runs file-system watches; Worktree::Remote exists when collaborating or remote-developing.

Editor (crates/editor/src/editor.rs)

pub struct Editor {
    buffer: Entity<MultiBuffer>,
    display_map: Entity<DisplayMap>,
    selections: ...,
    /* hundreds of fields */
}

The view. Rendered by EditorElement (crates/editor/src/element.rs).

Workspace (crates/workspace/src/workspace.rs)

pub struct Workspace {
    project: Entity<Project>,
    panes: Entity<Pane>,
    docks: ...,
    panels: ...,
}

The window-level container around panes, docks (panels at the edges), and tabs.

Anchor (crates/text/src/anchor.rs)

A buffer position that survives concurrent edits. The MultiBuffer has its own Anchor type that wraps these and adds an excerpt ID.

Selection

A (start: Anchor, end: Anchor, head: SelectionHead). An editor can have many. Multi-cursor is a vector of selections.

Action

A typed message dispatched via keymap or code. Defined with actions!(namespace, [Foo, Bar]) for no-data actions, or #[derive(Action)] for data-bearing ones.

Task (gpui)

A future returned by cx.spawn / cx.background_spawn. Cancelled on drop. See GPUI.

Entity

Reference-counted handle to state. Most things in Zed are Entity<X>s held via cx. WeakEntity<T> is a non-owning equivalent.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Data models – Zed wiki | Factory