Skip to main content

Coding standards

Formatting and lints are enforced by CI; this page covers what tools cannot check.

Rust​

  • Safe Rust only. unsafe_code is forbidden in the workspace; a change that needs it requires an ADR, isolation in one module, documented invariants and tests.
  • Library code returns Result with a thiserror error type that says what failed and where ({path}: permission denied). The session turns errors into user-visible notices. No unwrap on input from files, servers, users or extensions; expect only for invariants the code itself guarantees, with a message saying which.
  • No todo!(), unimplemented!() or placeholder panics on reachable paths (clippy warns).
  • Name the unit of every offset: char_*, byte_*, utf16_*. Never mix coordinate systems without a conversion function from ide-text.
  • Keep work off the UI thread when it can block: process IO, network, anything unbounded. Use the existing pattern: a background thread, a channel, and a waker that requests a repaint.
  • Every cache and queue has a bound and a documented reason. Prefer computing for the visible range only.
  • Prefer concrete types and functions to traits. Add a trait when there are two real implementations (as with DecorationProvider and AiProvider).
  • Public items get a doc comment explaining why and any non-obvious contract. Comments that restate code are noise.

Dependencies​

Add a crate only when it clearly beats writing the code: check licence (see dependencies), maintenance, transitive weight and unsafe surface. Put the version in the root Cargo.toml [workspace.dependencies].

UI code​

The desktop app translates input into core calls and paints. If a behaviour could matter to a second front end or a test, it belongs in ide-core instead.