helix-editor/helix
helix-stdx
Extensions to the Rust standard library — the helpers shared across crates that don't fit neatly elsewhere. ~2,200 lines of Rust. The name and pattern are borrowed from rust-analyzer's stdx crate.
Purpose
helix-stdx is a kitchen sink, but a structured one. It collects:
- Path manipulation that goes beyond
std::path(tilde expansion, normalize without canonicalize, fuzzy file finding). - Environment-variable wrappers and
which-style executable lookup. - File-access predicates (readable/writable, atomic copy of metadata).
- Small range/interval helpers used by selection math.
RopeSliceExt— extension methods on ropey types (regex search, byte-range mapping).
Directory layout
helix-stdx/src
├── lib.rs # `pub use range::Range;` plus module re-exports
├── env.rs # current_working_dir, set_current_working_dir, executable lookup
├── faccess.rs # access checks, atomic file copy with metadata preservation
├── path.rs # canonicalize, normalize, expand_tilde, get_relative_path, find_paths
├── range.rs # Range, is_subset
└── rope.rs # RopeSliceExt: regex_iter_at, byte ranges, line indexing helpersKey abstractions
| Item | File | Purpose |
|---|---|---|
path::canonicalize, normalize, expand_tilde |
path.rs |
Path manipulation that produces predictable cross-platform results without resolving symlinks (unlike std::fs::canonicalize). |
path::get_relative_path |
path.rs |
Computes a path relative to the current working dir; used for prettier display. |
path::find_paths |
path.rs |
The gf (goto file) implementation; given a snippet, search candidate locations and return any that exist. |
env::current_working_dir, set_current_working_dir |
env.rs |
A process-global CWD that bypasses std::env::set_current_dir (which is racy on Windows). |
env::which, ExecutableNotFoundError |
env.rs |
Locate executables in $PATH. Used by LSP/DAP/formatter spawning to surface helpful errors when binaries are missing. |
faccess::readonly, copy_metadata |
faccess.rs |
Determine if a path is writable; copy metadata atomically when saving to avoid losing permissions. |
range::Range |
range.rs |
A simple (start, end) interval used by selection diff math. |
rope::RopeSliceExt |
rope.rs |
Methods on RopeSlice that ropey doesn't ship: regex iteration, byte-range conversion, fast char/byte index conversions. |
Highlights
Path normalization
path::normalize resolves .. and . components without touching the filesystem. This matters when a path contains a symlink — std::fs::canonicalize would resolve through the symlink, which is rarely what users mean when they reference a file relative to the workspace.
Process-global CWD
env::current_working_dir uses an internal RwLock<PathBuf> rather than std::env::set_current_dir. The std API is process-wide and not thread-safe on Windows. Helix overrides it because :cd should work even from inside async tasks.
Atomic save metadata
faccess::copy_metadata is invoked when Helix's atomic save renames a temp file over the original. Without this, the resulting file would inherit the temp file's permissions instead of the original's.
RopeSliceExt
ropey is intentionally minimal. RopeSliceExt adds:
regex_iter_at(start, regex)— runs a regex over a rope slice without allocating aString.byte_range_at_char(idx)— char-to-byte range conversion.- Fast skipping of contiguous matching/non-matching runs.
Integration points
Used by every other crate. Notable consumers:
helix-corefor path manipulation in language detection and workspace lookup.helix-viewfor clipboard providers, document save, and CWD-relative display paths.helix-lspandhelix-dapforwhichto surface "executable not found" errors instead of opaque IO failures.helix-termfor picker filtering and prompt path completion.
Entry points for modification
- Adding a new path utility: prefer
helix-stdx/src/path.rsto inlining in callers. - Adding a
RopeSliceExtmethod: extendrope.rs. - Cross-platform shenanigans (Windows long path, macOS case sensitivity): keep them inside this crate so the rest of the workspace stays portable.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.