1# Zed Development: Glossary
  2
  3These are some terms and structures frequently used throughout the zed codebase.
  4
  5This is a best effort list and a work in progress.
  6
  7<!--
  8TBD: Glossary Improvement
  9
 10Questions:
 11
 12- Can we generate this list from doc comments throughout zed?
 13- We should have a section that shows the various UI parts and their names. (Can't do that in the channel.)
 14-->
 15
 16## Naming conventions
 17
 18These are generally true for the whole codebase. Note that Name can be anything
 19here. An example would be `AnyElement` and `LspStore`.
 20
 21- `AnyName`: A type erased version of _name_. Think `Box<dyn NameTrait>`.
 22- `NameStore`: A wrapper type which abstracts over whether operations are running locally or on a remote.
 23
 24## GPUI
 25
 26### State management
 27
 28- `App`: A singleton which holds the full application state including all the entities. Crucially: `App` is not `Send`, which means that `App` only exists on the thread that created it (which is the main/UI thread, usually). Thus, if you see a `&mut App`, know that you're on UI thread.
 29- `Context`: A wrapper around the `App` struct with specialized behavior for a specific `Entity`. Think of it as `(&mut App, Entity<V>)`. The specialized behavior is surfaced in the API surface of `Context`. E.g., `App::spawn` takes an `AsyncFnOnce(AsyncApp) -> Ret`, whereas `Context::spawn` takes an `AsyncFnOnce(WeakEntity<V>, AsyncApp) -> Ret`.
 30- `AsyncApp`: An owned version of `App` for use in async contexts. This type is _still_ not `Send` (so `AsyncApp` = you're on the main thread) and any use of it may be fallible (to account for the fact that the `App` might've been terminated by the time this closure runs).
 31  The convenience of `AsyncApp` lies in the fact that you usually interface with `App` via `&mut App`, which would be inconvenient to use with async closures; `AsyncApp` is owned, so you can use it in async closures with no sweat.
 32- `AppContext` A trait which abstracts over `App`, `AsyncApp` & `Context` and their Test versions.
 33- `Task`: A future running or scheduled to run on the background or foreground
 34  executor. In contradiction to regular Futures Tasks do not need `.await` to start running. You do need to await them to get the result of the task.
 35- `Executor`: Used to spawn tasks that run either on the foreground or background thread. Try to run the tasks on the background thread.
 36  - `BackgroundExecutor`: A threadpool running `Task`s.
 37  - `ForegroundExecutor`: The main thread running `Task`s.
 38- `Entity`: A strong, well-typed reference to a struct which is managed by gpui. Effectively a pointer/map key into the `App::EntityMap`.
 39- `WeakEntity`: A runtime checked reference to an `Entity` which may no longer exist. Similar to [`std::rc::Weak`](https://doc.rust-lang.org/std/rc/struct.Weak.html).
 40- `Global`: A singleton type which has only one value, that is stored in the `App`.
 41- `Event`: A datatype which can be send by an `Entity` to subscribers
 42- `Action`: An event that represents a user's keyboard input that can be handled by listeners
 43  Example: `file finder: toggle`
 44- `Observing`: reacting entities notifying they've changed
 45- `Subscription`: An event handler that is used to react to the changes of state in the application.
 46  1. Emitted event handling
 47  2. Observing `{new,release,on notify}` of an entity
 48
 49### UI
 50
 51- `View`: An `Entity` which can produce an `Element` through its implementation of `Render`.
 52- `Element`: A type that can be laid out and painted to the screen.
 53- `element expression`: An expression that builds an element tree, example:
 54
 55```rust
 56h_flex()
 57    .id(text[i])
 58    .relative()
 59    .when(selected, |this| {
 60        this.child(
 61            div()
 62                .h_4()
 63                .absolute()
 64                etc etc
 65```
 66
 67- `Component`: A builder which can be rendered turning it into an `Element`.
 68- `Dispatch tree`: TODO
 69- `Focus`: The place where keystrokes are handled first
 70- `Focus tree`: Path from the place that has the current focus to the UI Root. Example <img> TODO
 71
 72## Zed UI
 73
 74- `Window`: A struct in zed representing a zed window in your desktop environment (see image below). There can be multiple if you have multiple zed instances open. Mostly passed around for rendering.
 75- `Modal`: A UI element that floats on top of the rest of the UI
 76- `Picker`: A struct representing a list of items in floating on top of the UI (Modal). You can select an item and confirm. What happens on select or confirm is determined by the picker's delegate. (The 'Model' in the image below is a picker.)
 77- `PickerDelegate`: A trait used to specialize behavior for a `Picker`. The `Picker` stores the `PickerDelegate` in the field delegate.
 78- `Center`: The middle of the zed window, the center is split into multiple `Pane`s. In the codebase this is a field on the `Workspace` struct. (see image below).
 79- `Pane`: An area in the `Center` where we can place items, such as an editor, multi-buffer or terminal (see image below).
 80- `Panel`: An `Entity` implementing the `Panel` trait. These can be placed in a `Dock`. In the image below we see the: `ProjectPanel` in the left dock, the `DebugPanel` in the bottom dock, and `AgentPanel` in the right dock. Note `Editor` does not implement `Panel` and hence is not a `Panel`.
 81- `Dock`: A UI element similar to a `Pane` which can be opened and hidden. There can be up to 3 docks open at a time, left right and below the center. A dock contains one or more `Panel`s not `Pane`s. (see image).
 82
 83<img width="1921" height="1080" alt="Screenshot for the Pane and Dock features" src="https://github.com/user-attachments/assets/2cb1170e-2850-450d-89bb-73622b5d07b2" />
 84
 85- `Project`: One or more `Worktree`s
 86- `Worktree`: Represents either local or remote files.
 87
 88<img width="552" height="1118" alt="Screenshot for the Worktree feature" src="https://github.com/user-attachments/assets/da5c58e4-b02e-4038-9736-27e3509fdbfa" />
 89
 90- [Multibuffer](https://zed.dev/docs/multibuffers): A list of Editors, a multi-buffer allows editing multiple files simultaneously. A multi-buffer opens when an operation in Zed returns multiple locations, examples: _search_ or _go to definition_. See project search in the image below.
 91
 92<img width="800" height="886" alt="Screenshot for the MultiBuffer feature" src="https://github.com/user-attachments/assets/d59dcecd-8ab6-4172-8fb6-b1fc3c3eaf9d" />
 93
 94## Editor
 95
 96- `Editor`: _The_ text editor, nearly everything in zed is an `Editor`, even single line inputs. Each pane in the image above contains one or more `Editor` instances.
 97- `Workspace`: The root of the window
 98- `Entry`: A file, dir, pending dir or unloaded dir.
 99- `Buffer`: The in-memory representation of a 'file' together with relevant data such as syntax trees, git status and diagnostics.
100- `pending selection`: You have mouse down and you're dragging but you have not yet released.
101
102## Collab
103
104- `Collab session`: Multiple users working in a shared `Project`
105- `Upstream client`: The zed client which has shared their workspace
106- `Downstream client`: The zed client joining a shared workspace
107
108## Debugger
109
110- `DapStore`: Is an entity that manages debugger sessions
111- `debugger::Session`: Is an entity that manages the lifecycle of a debug session and communication with DAPS
112- `BreakpointStore`: Is an entity that manages breakpoints states in local and remote instances of Zed
113- `DebugSession`: Manages a debug session's UI and running state
114- `RunningState`: Directly manages all the views of a debug session
115- `VariableList`: The variable and watch list view of a debug session
116- `Console`: TODO
117- `Terminal`: TODO
118- `BreakpointList`: TODO