Data Flow Architecture

Tracing a keystroke from OS event to GPU pixels

Commit 13e7c11768 · Tap any stage to expand

Seven stages, each a tap away. Links open the full component breakdown.

1
User Input
OS event arrives at the platform layer
gpui_macos gpui_linux gpui_windows

Platform-specific code (Cocoa/X11/Win32) intercepts OS events and converts them into GPUI's unified event types, then hands them off to the application event loop.

Key Types
KeyDownEventRaw keystroke with modifiers
MouseDownEventClick with position & button
InputEventIME composition text
GPUI detail →
2
GPUI Event Dispatch
Keystroke resolved to an Action via Keymap
gpui

App::dispatch_action() routes actions through the focused element tree in capture then bubble phases. The keymap translates keystroke sequences like ctrl-k into typed action structs like MoveToEndOfLine.

Key Types
ApplicationRoot GPUI reference (app.rs:140)
AppGlobal state: windows, entities (app.rs:596)
KeymapBindings: keystroke → Action
Entity<T>Handle to reactive state
GPUI detail →
3
Workspace & Pane Routing
Action forwarded to the active editor item
workspace project

Workspace orchestrates panes, docks, and the project. The active Pane holds a stack of items; the focused item (usually an Editor) receives the action. Project owns buffer and LSP lifetimes.

Key Types
WorkspacePanes, docks, active project (ws.rs:1353)
PaneTab container, routes to active item
ProjectBuffers, LSP servers, worktrees (proj.rs:213)
Workspace detail →
4
Editor & Action Handlers
Action mutates selections and buffer state
editor

Editor is the central editing component. handle_input processes typed text; action handlers update SelectionsCollection (cursors) and call MultiBuffer::edit() for text mutations. The DisplayMap tracks visual transforms.

Key Types
EditorBuffer, selections, scroll (editor.rs:883)
EditorElementRenders editor to scene (element.rs:198)
DisplayMapWraps, folds, inlays, git diffs
SelectionsCollectionAll cursor & selection ranges
Editor detail →
5
Buffer & Language
Text stored in CRDT; tree-sitter re-parses async
language multi_buffer text

Buffer wraps a CRDT TextBuffer and a tree-sitter SyntaxMap. Edits are applied transactionally; the syntax tree is invalidated and re-parsed on a background thread. MultiBuffer stitches multiple buffers into a single composite view with excerpt ranges and undo history.

Key Types
BufferText + syntax + diagnostics (buffer.rs:98)
MultiBufferComposite of excerpts (multi_buffer.rs:73)
LanguageGrammar + LSP config (language.rs:849)
BufferSnapshotImmutable snapshot for rendering (buffer.rs:186)
Buffer detail →
6
LSP Integration
Language server notified; diagnostics flow back
lsp project

After each buffer edit, LspStore sends a textDocument/didChange JSON-RPC notification to each registered LanguageServer process. The server replies asynchronously with diagnostics, which are stored back in the Buffer and trigger a re-render. Completions, hover, and go-to-definition follow the same request/response pattern.

Key Types
LanguageServerSpawned process + JSON-RPC (lsp.rs:99)
LspStoreManages server lifecycles
DiagnosticSetPer-server diagnostics on a buffer
LSP detail →
7
Display Map & GPU Rendering
Snapshot → elements → scene → WGPU → screen
editor gpui gpui_wgpu

cx.notify() schedules a redraw. GPUI calls each view's render(), building an element tree. EditorElement::paint() takes a DisplaySnapshot, converts lines to glyph positions, and emits quads/sprites into a Scene. The WGPU layer then batches these into draw calls submitted to Metal/Vulkan/DX12 and presents the framebuffer.

Key Types
DisplayMapApplies wraps, folds, inlays to buffer
EditorElementPaints lines, cursors, gutters (element.rs:9786)
SceneAccumulated GPU primitives (scene.rs:27)
Rendering detail →