Expand description
The editor’s text model: rope-backed buffers, documents with undo and dirty tracking, regex search, and the small renderer-neutral vocabularies (buffer ids and kinds, pane geometry, folds, indent units, project roots) that every other lattice crate shares.
This crate owns the actor-protected document model. It is content-type
agnostic; tree-sitter, LSP, plugin, and rendering concerns live elsewhere.
The dispatcher that serialises edits is not here either — it lives in
lattice-host; this crate only guarantees each operation is consistent.
§What it owns
- Text and editing.
Bufferwraps aropey::Ropeand applies [protocol::Edit]s, returning anbuffer::AppliedEdit(inverse + tree-sitter delta).Documentadds identity, path, versions, selections, theUndoStack(with insert-session coalescing viaDocument::begin_undo_group) and dirty tracking. Errors areCoreError. - Search.
search::find/search::find_allstream a compiledfancy_regex::Regexover the rope without materialising it. - Shared vocabularies.
BufferId/BufferKind/BufferFlags; the pane tree and its geometry (ui::pane::PaneTree);Fold/FoldMethod;IndentUnit/IndentMethod;ProviderChainfor formatting;AutoWrap; thelabeled_enum!macro every enum-typed option is declared with. - Service seams for crates that sit below the host:
Clipboard,ProjectResolver,FoldOverlayService,ExcerptSourceResolver,ViewArgsResolver— traits here, implementations wired in at boot.
§Coordinates
Every position is a [protocol::Position]: a 0-based line and a
0-based UTF-8 byte offset within that line — not a char index and
not a display column. Ranges are half-open [start, end).
§What it must not depend on
Nothing above [lattice_protocol]: no syntax, grammar, config, mode,
LSP, plugin or renderer crate, and no async runtime. Roughly thirty
crates depend on this one, so any dependency added here is a dependency
of the whole workspace — and one that reaches upward is a cycle. That
is the structural reason it is its own crate: it is the floor. Types
that several upper crates must share without depending on each other
(fold sources, pane-group row mappers, project resolution) are hoisted
down to here as data or traits, and implemented above.
§Example
use lattice_core::Document;
use lattice_core::protocol::edit::Edit;
use lattice_core::protocol::position::{Position, Range};
let mut doc = Document::from_text("fn main() {}\n");
// Rename `main` (line 0, bytes 3..7).
let range = Range::new(Position::new(0, 3), Position::new(0, 7));
let applied = doc.apply_edit(Edit::replace(range, "start"))?;
assert_eq!(doc.text(), "fn start() {}\n");
assert_eq!(applied.replaced_text, "main");
assert_eq!(doc.text_version(), 1);
doc.undo()?;
assert_eq!(doc.text(), "fn main() {}\n");
assert!(!doc.dirty());§Design documents
docs/dev/architecture/design.md§5.1 (buffer / document model) and §5.9 (everything is a buffer; panes)docs/dev/architecture/owner-write-caret.md(selection transform across edits)docs/dev/architecture/project-resolution.md,docs/dev/architecture/fold-architecture.md,docs/dev/architecture/clipboard.md,docs/dev/architecture/text-reflow.md,docs/dev/architecture/pane-zoom.md,docs/dev/architecture/pane-groups.md
Re-exports§
pub use crate::buffer::Buffer;pub use crate::buffers::BufferFlags;pub use crate::buffers::BufferId;pub use crate::buffers::BufferKind;pub use crate::clipboard::Clipboard;pub use crate::clipboard::ClipboardHandle;pub use crate::clipboard::FakeClipboard;pub use crate::document::Document;pub use crate::document::DocumentBuilder;pub use crate::error::CoreError;pub use crate::error::CoreResult;pub use crate::folding::Fold;pub use crate::folding::FoldMethod;pub use crate::folding::FoldOverlayService;pub use crate::folding::FoldOverlayServiceHandle;pub use crate::folding::FoldSource;pub use crate::folding::ProviderId;pub use crate::folding::ProviderKind;pub use crate::format_chain::FormatIntent;pub use crate::format_chain::FormatProvider;pub use crate::format_chain::ProviderChain;pub use crate::indent::IndentMethod;pub use crate::indent::IndentUnit;pub use crate::indent_blocks::LineShape;pub use crate::project::DEFAULT_ROOT_MARKERS;pub use crate::project::ExcerptSource;pub use crate::project::ExcerptSourceResolver;pub use crate::project::ExcerptSourceResolverHandle;pub use crate::project::MarkerResolver;pub use crate::project::Project;pub use crate::project::ProjectKind;pub use crate::project::ProjectResolver;pub use crate::project::ProjectResolverHandle;pub use crate::project::ViewArgsResolver;pub use crate::project::ViewArgsResolverHandle;pub use crate::search::Direction as SearchDir;pub use crate::search::SearchHit;pub use crate::search::find as search_find;pub use crate::undo::UndoEntry;pub use crate::undo::UndoStack;pub use crate::wrap::AutoWrap;pub use crate::wrap::DEFAULT_TEXTWIDTH;pub use crate::wrap::WrapWidth;pub use lattice_protocol as protocol;
Modules§
- buffer
- Buffer: a thin, edit-aware wrapper around
ropey::Rope. - buffers
- Buffer-kind discriminator for the multi-buffer foundation (DESIGN.md §5.9).
- clipboard
- System-clipboard abstraction (CB.0).
- document
- Document: a buffer plus the metadata needed for the rest of the editor.
- error
- The crate’s error type,
CoreError, and itsCoreResultalias. - folding
- Buffer-level folding semantics.
- format_
chain - Who formats a range — an ordered chain of typed providers.
- home
~expansion, shared so every consumer resolves a home the same way.~expansion, in one place.- indent
- Indentation units and methods.
- indent_
blocks - Indent blocks — the shared answer to “what block is this line in”.
- labeled_
enum labeled_enum!— declarative macro for enum-typed options that participate in:set foo=<Tab>cmdline completion.- on_disk
- On-disk identity of a file-backed buffer — the shared “did this file change underneath us” primitive.
- project
- Which project a path belongs to (slice PR.1).
- search
- Buffer-level regex search.
- ui
- UI primitives shared across renderers.
- undo
- Undo stack.
- wrap
autowrap— whether typing pasttextwidthbreaks the line.
Macros§
- labeled_
enum - Declare an option enum whose variants carry a canonical label, optional parse aliases and a one-line completion doc.