Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Coding conventions

Patterns specific to this codebase. General Rust style (rustfmt defaults) applies on top.

Documentation

  • missing_docs = "deny" is set for every crate by [workspace.lints]. Document all public items with ///; module headers use //!.
  • Doc comments say what and why, briefly. Implementation details that would surprise a reader get an inline // comment explaining the why.
  • One CHANGELOG.md entry per user-visible change, added to ## [Unreleased] in the same change that makes it (T309, tasks.md) — not batched up for later. “User-visible” means anything a person running Vix could notice: a new feature, a changed default, a fixed bug, a removed capability. A change with no such effect — an internal refactor, a crate split, a test reorganization, a CI/tooling fix, a lint cleanup — does not get one; padding the changelog with those buries the entries that matter. When in doubt, ask whether a user reading the changelog would care; if the honest answer is no, leave it out.

Lints

  • unsafe_code = "forbid", missing_docs = "deny" and clippy::pedantic live once in the root [workspace.lints]; each crate has [lints] workspace = true (T599), so there are no per-file lint attributes to repeat. Every #[allow(..)] needs a reason = "..", and Arc::clone(&x) is used instead of x.clone() on reference-counted pointers. Keep cargo clippy --workspace --all-targets -- -D warnings clean.
  • No blanket allows. There is no #![allow(clippy::pedantic)] and no #![allow(missing_docs)]; fix findings in code (saturating try_from casts, extract helpers for too_many_lines, context structs for too_many_arguments, add # Errors/# Panics, etc.). editor_core’s modules are held to the same workspace clippy::pedantic as everywhere else — there is no blanket #[allow(clippy::all, clippy::pedantic)] anywhere in the crate.
  • Sanctioned exceptions are only a handful of targeted too_many_lines / too_many_arguments allows on specific functions that resist further extraction. There is no standing #[allow(clippy::struct_excessive_bools)] anywhere in the codebase: every bool-cluster struct (App, Settings, SearchBar, WorkspaceSearch, DblockParams, both editor_core::Editors) has been converted to a bitflags-based Flags field instead — prefer that over a new allow for a struct whose bools are independent, freely-combinable toggles.
  • Project lints (tui/tests/code_lints.rs, T833): no println!, eprintln!, print!, eprint! or dbg! in library code outside its allowlist (each entry with a count and a reason), and no untranslated literal handed to self.messages.* or self.status. See spec/test, “Project-specific lints”.

Internationalization

  • User-facing strings are i18n keys looked up with t!, never literals.
  • Keys are dotted and namespaced (menu.*, cmd.*, ui.*, status.*, msg.*, help.*, prompt.*, theme.*, palette.*).
  • Interpolation uses %{name} in YAML and t!("k", name = value) in code.
  • t! returns Cow<str>; call .to_string() when a String is required.
  • Data modules (menu/palette/theme/keyboard) hold keys; the host calls t!.

Actions

  • Commands are string ids dispatched by App::run_action (in the App shell, tui/src/app.rs). The menu (crates/vix-menu/) and palette (crates/vix-palette/, re-exported as crate::menu / crate::palette) reference the same ids.
  • To add a command: add the run_action arm, then reference it from a menu item and/or palette::COMMANDS, and add its i18n label key.

Pure-logic modules

  • Prefer a small pure module (text -> text or (text, cursor) -> …) with unit tests for any non-trivial transform, and keep the App method a thin wrapper that reads the buffer, calls the pure fn, and writes back. Examples: align, emmet, tags, http_client::parse_request, org_table, and textops (whole-text transforms plus the cursor-relative rewrites bump_number_at / smart_toggle_at / transpose_*_at / delete_*_at). A family of related transforms shares its unit builders rather than each re-deriving ranges — see textops’s word_units / sentence_units / paragraph_units / section_units, used by both transpose and delete.
  • Buffer-mutating actions funnel through App::transform_selection_or_buffer (selection-or-whole-buffer), App::rewrite_at_cursor (cursor-relative), or insert_str; all are read-only-aware.

Crate layering

  • A new dependency keeps the five layering rules in docs/architecture: nothing depends on vix-tui; only vix-input and vix-tui use crossterm; a *-core/*-model crate reaches no *-panel/*-picker/*-preview/*-view crate; no GUI depends on another; vix-mcp-server reaches no such UI-surface crate either. tui/tests/crate_layering.rs fails on the offending edge. After changing a crate’s dependencies, regenerate docs/reference/crate-layers.md with cargo run --example list_commands -- --write.
  • The same run rewrites docs/reference/quality-metrics.md (lines, test, property-test and ignore counts, translation completeness, allowlist sizes), so adding tests, keys or allowlist entries changes it too; commit the regenerated page with the change.

Rendering

  • All of the app’s drawing is in tui/src/ui.rs; no editing/state logic there. The editor widget renders itself (in editor_core); the app just hands it a Rect.
  • Paint the whole frame in the theme background first, then panes, then overlays.
  • Overlays Clear their rect and set the block .style(theme::base()) so they read correctly in light mode.
  • Use the region-aware styles (theme::region_base(Region::…)) for the menu bar, status bar, docks, and editor so custom themes can color them.

Terminal input

  • The terminal is owned by tui/src/main.rs alone: raw mode, mouse capture, bracketed paste, and (on macOS) the kitty keyboard flags that make the Command modifier reportable. Every mode it turns on it turns off again, on exit and around suspend.
  • Events reach exactly three entry points — App::on_key, App::on_mouse, App::on_paste. Anything that needs a fourth is a bug in the routing, not a new entry point.
  • Normalize at the entry point, not per binding: the macOS Command → Control fold happens once at the top of on_key, so every keymap sees a chord it already knows.
  • A pasted chunk is one edit, not a replay of keystrokes: replaying re-triggers auto-indent and auto-pairing and leaves one undo entry per character.

Theme

  • Built-ins are monochrome; get colors from theme::fg/bg/base/title/dim/selected (mode-aware) or theme::region_* (custom-theme-aware).
  • Reversed video is reserved for selections and the block cursor.

State and modals

  • App holds all state. Overlays are Option<…> fields; every modal layer has one row in the OVERLAYS table in tui/src/app/overlays.rs, ordered bottom to top (see spec/overlay-priority). The frame draws the open rows in table order (ui::draw_overlays); keys are offered to them in reverse order (App::route_overlay_key), so the layer drawn on top gets the keys. App::overlay_capturing_keys is derived from the same table (the paste router and ghost text ask it whether a keypress would reach the editor). To add an overlay: add its row, its OverlayId variant (enum order is table order) and its arm in ui::draw_overlay; a layer with no key policy does not compile.
  • The chooser/model modules expose open()/up()/down()/selected_*(); the app wires keys and applies the result.

Errors and panics

  • No unsafe. Avoid unwrap/expect on fallible runtime paths; prefer reporting to the message drawer (self.messages.error(…)) or status line.
  • expect is acceptable for genuinely-infallible invariants, with a message.
  • Library crates return typed errors, not Result<_, String> (T610; no public function in crates/, gui/ or tui/src does any more). Define a small #[non_exhaustive] enum per fallible operation (BaseError, ConvertError, SessionError, …), implement Display and std::error::Error by hand (the tree does not use thiserror), keep Display text equal to the message a caller already showed, and wrap the cause (io::Error, ParseIntError) in a variant so callers can match on it. Private helpers may keep String.

Security

  • A change that runs a program, reads project configuration, talks to the network, holds a secret, takes a path from outside or parses input Vix did not write answers the “Checklist for a new feature” in docs/threat-model.md. A change that adds or moves a trust boundary updates that page and SECURITY.md with it.
  • Never commit a credential. tui/tests/secret_scan.rs fails on a real-shaped one; a test fixture that needs a full-length fake goes in its ALLOWED list with a reason (build fakes at run time where you can, as its own tests do).

Tests

  • Prefer terminal-independent tests: build an App, feed KeyEvents, assert on state. Render checks use a sized TestBackend.
  • Avoid asserting on translated text where a process-global locale could race; assert on state or i18n keys instead.
  • Tests must not touch the machine. The platform clipboard is opt-in (vix_clipboard::use_system, called only by main), so a test run cannot overwrite what the developer copied; hold anything else that reaches outside the process to the same standard, and write to a temp directory keyed by std::process::id().
  • A platform-specific behavior gets a test that asserts the platform-appropriate outcome (if cfg!(target_os = "macos") { … } else { … }), so it still runs — and still means something — on the CI that is not that platform.
  • Pure parsers and text transforms get a fuzz target under fuzz/fuzz_targets/; anything on the per-keystroke or per-frame path gets a Criterion benchmark under tui/benches/. Run one with cargo +nightly fuzz run <target> (needs cargo install cargo-fuzz; add -- -max_total_time=600 for a fixed-length run rather than fuzzing until Ctrl+C) — it’s a separate workspace (fuzz/Cargo.toml) so cargo build/cargo check --workspace at the repo root never touch it. See fuzz/README.md (target list, reproducing/minimizing a crash) and spec/test/index.md.
  • When the layout itself is what’s under test (a dialog’s framing, a dock’s column widths, a long line truncating), add a golden-screen test to tui/tests/snapshots.rs instead of a state assertion — pin the locale to en first, since rust_i18n::locale() is process-global. Reviewing a changed snapshot: INSTA_UPDATE=always cargo test --test main snapshots::, then read every line of git diff tui/tests/snapshots/ (or cargo insta review with cargo-insta installed) before committing — a snapshot diff is a signal to explain, not a formality to wave through. See spec/test/index.md’s “Snapshot testing” section.