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.mdentry 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"andclippy::pedanticlive 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 areason = "..", andArc::clone(&x)is used instead ofx.clone()on reference-counted pointers. Keepcargo clippy --workspace --all-targets -- -D warningsclean.- No blanket allows. There is no
#![allow(clippy::pedantic)]and no#![allow(missing_docs)]; fix findings in code (saturatingtry_fromcasts, extract helpers fortoo_many_lines, context structs fortoo_many_arguments, add# Errors/# Panics, etc.).editor_core’s modules are held to the same workspaceclippy::pedanticas 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_argumentsallows 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, botheditor_core::Editors) has been converted to abitflags-basedFlagsfield 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): noprintln!,eprintln!,print!,eprint!ordbg!in library code outside its allowlist (each entry with a count and a reason), and no untranslated literal handed toself.messages.*orself.status. Seespec/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 andt!("k", name = value)in code. t!returnsCow<str>; call.to_string()when aStringis 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 ascrate::menu/crate::palette) reference the same ids. - To add a command: add the
run_actionarm, then reference it from a menu item and/orpalette::COMMANDS, and add its i18n label key.
Pure-logic modules
- Prefer a small pure module (
text -> textor(text, cursor) -> …) with unit tests for any non-trivial transform, and keep theAppmethod a thin wrapper that reads the buffer, calls the pure fn, and writes back. Examples:align,emmet,tags,http_client::parse_request,org_table, andtextops(whole-text transforms plus the cursor-relative rewritesbump_number_at/smart_toggle_at/transpose_*_at/delete_*_at). A family of related transforms shares its unit builders rather than each re-deriving ranges — seetextops’sword_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), orinsert_str; all are read-only-aware.
Crate layering
- A new dependency keeps the five layering rules in
docs/architecture: nothing depends onvix-tui; onlyvix-inputandvix-tuiusecrossterm; a*-core/*-modelcrate reaches no*-panel/*-picker/*-preview/*-viewcrate; no GUI depends on another;vix-mcp-serverreaches no such UI-surface crate either.tui/tests/crate_layering.rsfails on the offending edge. After changing a crate’s dependencies, regeneratedocs/reference/crate-layers.mdwithcargo 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 (ineditor_core); the app just hands it aRect. - Paint the whole frame in the theme background first, then panes, then overlays.
- Overlays
Cleartheir 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.rsalone: raw mode, mouse capture, bracketed paste, and (on macOS) the kitty keyboard flags that make theCommandmodifier 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→Controlfold happens once at the top ofon_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) ortheme::region_*(custom-theme-aware). - Reversed video is reserved for selections and the block cursor.
State and modals
Appholds all state. Overlays areOption<…>fields; every modal layer has one row in theOVERLAYStable intui/src/app/overlays.rs, ordered bottom to top (seespec/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_keysis 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, itsOverlayIdvariant (enum order is table order) and its arm inui::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. Avoidunwrap/expecton fallible runtime paths; prefer reporting to the message drawer (self.messages.error(…)) or status line. expectis acceptable for genuinely-infallible invariants, with a message.- Library crates return typed errors, not
Result<_, String>(T610; no public function incrates/,gui/ortui/srcdoes any more). Define a small#[non_exhaustive]enum per fallible operation (BaseError,ConvertError,SessionError, …), implementDisplayandstd::error::Errorby hand (the tree does not usethiserror), keepDisplaytext 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 keepString.
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 andSECURITY.mdwith it. - Never commit a credential.
tui/tests/secret_scan.rsfails on a real-shaped one; a test fixture that needs a full-length fake goes in itsALLOWEDlist with a reason (build fakes at run time where you can, as its own tests do).
Tests
- Prefer terminal-independent tests: build an
App, feedKeyEvents, assert on state. Render checks use a sizedTestBackend. - 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 bymain), 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 bystd::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 undertui/benches/. Run one withcargo +nightly fuzz run <target>(needscargo install cargo-fuzz; add-- -max_total_time=600for a fixed-length run rather than fuzzing until Ctrl+C) — it’s a separate workspace (fuzz/Cargo.toml) socargo build/cargo check --workspaceat the repo root never touch it. Seefuzz/README.md(target list, reproducing/minimizing a crash) andspec/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.rsinstead of a state assertion — pin the locale toenfirst, sincerust_i18n::locale()is process-global. Reviewing a changed snapshot:INSTA_UPDATE=always cargo test --test main snapshots::, then read every line ofgit diff tui/tests/snapshots/(orcargo insta reviewwithcargo-instainstalled) before committing — a snapshot diff is a signal to explain, not a formality to wave through. Seespec/test/index.md’s “Snapshot testing” section.