Art produced by Saki
Rust Automod is a Visual Studio Code extension that keeps Rust module files in sync for you. It creates and updates mod.rs, lib.rs, and main.rs module declarations automatically, supports both the classic folder/mod.rs layout and the modern folder.rs + folder/ layout, supports richer .rautomod project rules, adds syntax highlighting and formatting for .rautomod, and now includes smart mod.rs visibility controls plus preview, undo, regenerate, explain, module-tree, and Studio-style config workflows inside VS Code.
This repository now also includes a Zed adaptation under zed/README.md, focused on .rautomod workflows that fit Zed's current extension surface. The current Zed package gives .rautomod files real editor support in Zed with diagnostics, formatting, hover help, and completions, adds Rust code actions for module registration and sync, includes Assistant slash commands for scaffold, audit, explain, and module-pair creation, and now ships a Rust daemon watcher that can automatically update closed Rust module targets after file create, delete, and rename events. When a target is open in the editor, the daemon intentionally defers the write and leaves the fix available as a code action instead of risking buffer/undo conflicts. The sync path now also preserves existing declaration style in targets that are already private/public instead of promoting everything to pub mod, no longer creates broad missing mod.rs targets during generic rescans or startup noise, only manages files that are actually covered by a real .rautomod in the current subtree, trims trailing whitespace plus collapses stale blank-line runs when it rewrites a managed target, now mirrors the VS Code extension more closely when deciding whether declarations should land before or after use blocks, now discovers missing direct and parent targets during watcher/manual sync flows so nested modules without pre-existing mod.rs get picked up more reliably, keeps Rust build outputs under zed/ out of Git through a local .gitignore, and avoids re-rendering the Studio editor while you are actively typing in many form inputs.
- For practical scenarios and copy-paste examples, see docs/USE_CASES.md.
- For a more detailed
.rautomodreference, see docs/RAUTOMOD_REFERENCE.md. - For the visual editor and manager UI flows, see docs/RAUTOMOD_STUDIO.md.
- For the Zed adaptation and its current feature matrix, see zed/README.md.
- For the Zed code-action and watcher setup on Rust files, see the install and settings section in zed/README.md.
- Creates
mod.rswhen a new Rust file appears in a module folder. - Updates
mod.rs,lib.rs, ormain.rswhen modules are added or removed. - Detects whether a folder follows the classic
mod.rsstyle or the modernfolder.rs + folder/style. - Can create a modern or classic module pair automatically, including the sibling file/folder structure.
- Supports nested folders and parent module registration.
- Supports
.rautomodrules for visibility, sorting, target selection, excludes, inheritance, generated comments, strict validation, and more. - Can run
cargo fmtafter updates. - Adds a dedicated file icon, syntax highlighting, linting, completions, and formatting for
.rautomod. - Opens
.rautomodin a custom visual editor withVisual,Split, andRawmodes. - Includes a workspace-wide Rust AutoMod manager UI for browsing configs, filtering audits, scaffolding new ones, and visualizing the module tree.
- Supports preview/dry run, undo of the last automod action, workspace or folder regeneration, and structured logging.
- Can explain why a file was registered a certain way and show the effective config that won for a Rust file.
- Can scaffold a
.rautomodfile, ignore files or folders from the Explorer, and change module visibility from quick actions. - Hides
mod.rsmore intelligently in the Explorer.
When Rust AutoMod reacts to a file or folder, it follows this general order:
- It finds the effective
.rautomodrule for the file, including inherited rules fromextends=.... - It checks whether the file is ignored by
exclude=or by a negativepattern=!something. - It resolves the target file:
target=auto: tries the crate root target when appropriate, otherwise detects classicmod.rsvs modern siblingfolder.rstarget=mod.rs: always writes to the local foldermod.rstarget=lib.rs: writes to the nearestlib.rstarget=main.rs: writes to the nearestmain.rs
- It generates the declaration block according to
visibility,cfg,reexport,group_order, andblank_lines. - It sorts or reorders the managed block according to
sort.
If strict=error and the .rautomod file has blocking diagnostics, Rust AutoMod stops before applying those changes.
Preview AutoMod Changes: opens a dry-run summary and diff before writing.Undo Last AutoMod Action: restores the previous automod batch without relying on editor undo history.Regenerate Rust Modules: rebuilds missing registrations and removes stale ones for a folder or workspace.Create Rust Module Pair: scaffoldsname/mod.rsorname.rs + name/based on the detected project style.Set Module Visibility: updates the parent declaration topub,pub(crate), or private without manually editing the parent file.Move Module to Crate Root: helps relocate a leaf module and rebuild declarations afterward.Explain AutoMod Decision: shows target file, winning rule, ordering, and generated snippet preview for a Rust file.Show Effective AutoMod Config: opens the resolved config, matched patterns, diagnostics, and source.rautomod.Open Rust AutoMod Log: opens the structured output channel with automod activity.Ignore in .rautomod: prepends anexclude=rule for a file or folder from the Explorer.Scaffold .rautomod: creates a starter config with the new keys and examples.- Conflict detection warns when Rust AutoMod notices manual edits in the managed declaration area before writing again.
Rust AutoMod now works with both major Rust module styles:
- Classic:
feature/mod.rs - Modern:
feature.rsplusfeature/
In rustautomod.moduleLayout, you can choose:
auto: detect the style from the surrounding project structureclassic: forcefolder/mod.rsmodern: forcefolder.rs + folder/
This affects:
- where
target=autowrites declarations - what
Create Rust Module Pairscaffolds - how folder modules appear in the manager module tree
- how regeneration detects stale declarations
Example modern layout:
src/
lib.rs
application.rs
application/
queries.rs
services.rs
With this structure, Rust AutoMod can keep src/lib.rs and src/application.rs synchronized without depending on mod.rs.
Rust AutoMod now treats .rautomod as a first-class editing surface instead of only a plain text file.
There are two UI entry points:
- A per-file visual editor for each
.rautomod - A manager surface for browsing configs across the workspace
Each .rautomod file can open in a custom editor with three modes:
Visual: form-based editing for rule blocks and global configSplit: visual cards side-by-side with the raw textRaw: a focused text area for manual edits
The visual editor exposes:
schema_version,strict, andextends- rule cards for
visibility,sort,fmt,target,pattern,exclude,cfg,group_order,blank_lines,reexport,header, andgenerated_comment - live audit and diagnostics feedback from the extension parser
- inline quick fixes for document and rule fields
- chip-based editors for
pattern,exclude,cfg, andextends - drag-and-drop rule ordering, plus duplicate, remove, and move actions
- impact preview showing matched, ignored, shadowed, and uncovered files
- a matching playground that explains why a path is matched, ignored, or uncovered
- local snapshot history for the current
.rautomod - real draft-state badges so you can see when Visual and Raw diverge
Format Raw,Apply Raw Changes, andOpen Raw Externally
Use Open Rust AutoMod Manager to open a central panel, or open the Rust AutoMod activity bar container to access the manager view.
The manager UI gives you:
- a workspace-wide list of
.rautomodfiles - quick search by path, workspace, strict mode, or target mode
- summary cards for configs, rules, diagnostics, uncovered files, and overlaps
- direct actions to open a config visually or in raw mode
- scaffold actions for workspace roots
- bulk actions to scaffold all roots, format all
.rautomodfiles, regenerate the workspace, and open configs with diagnostics - per-config audit cards with duplicate-rule, overlap, ignored, shadowed, and uncovered signals
- per-config impact samples with open-file and reveal-folder actions
- a manager-side why/why-not playground for testing individual paths
- a visual module tree built from crate roots and actual
moddeclarations - quick actions on module-tree nodes to create child modules, switch visibility, open files, or move a leaf module to the crate root
- lazy-rendered tree expansion so large module hierarchies stay more responsive as you open and close branches
- stable manager expansion state with in-place tree updates, so opening and collapsing branches keeps the viewport anchored instead of jumping
- quick access to the Rust AutoMod log
This manager is meant to feel closer to a product control surface, similar in spirit to a settings UI, while still keeping the actual .rautomod file as the source of truth.
The screenshots below use the pdv-server example workspace.
Manager view:
Visual editor for src/application/queries/.rautomod:
Split mode for the same config:
Rust Automod now supports three Explorer workflows for mod.rs:
- Smart hide for all index-like
mod.rs - Manual hide for one specific
mod.rs - Restore for both flows
Use the command Toggle Smart mod.rs Hiding.
When it is enabled, the extension hides only mod.rs files that behave like lightweight indexes, such as files containing only:
mod foo;pub mod foo;#[cfg(...)]attributes attached to those declarationspub use ...;re-exports
If a mod.rs contains real code, like functions, structs, impls, constants, inline modules with bodies, or any other implementation content, it stays visible.
Right-click a mod.rs file in the Explorer and run:
Hide This mod.rs
This hides only that file.
To restore hidden files, use:
Restore Hidden mod.rs
If you run it from the Explorer on a specific mod.rs, it restores that file directly.
If you run it from the Command Palette, the extension shows a picker with the manually hidden mod.rs files.
Toggle Smart mod.rs HidingHide This mod.rsRestore Hidden mod.rsPreview AutoMod ChangesRegenerate Rust ModulesUndo Last AutoMod ActionExplain AutoMod DecisionShow Effective AutoMod ConfigIgnore in .rautomodScaffold .rautomodCreate Rust Module PairSet Module VisibilityMove Module to Crate RootOpen Rust AutoMod LogOpen .rautomod VisualOpen .rautomod RawOpen Rust AutoMod Manager
Use Preview AutoMod Changes on a Rust file or folder when you want to inspect what would change first. Rust AutoMod opens a summary plus a diff of the first affected file without writing to the workspace.
If you want this behavior automatically before every write, enable the setting:
{
"rustautomod.previewBeforeApply": true
}Use Regenerate Rust Modules when:
- you moved many files outside VS Code
- a branch switch left stale declarations behind
- you want to rebuild a whole folder after changing
.rautomod
This command scans the selected folder or workspace, re-adds missing declarations, and removes stale ones.
Use Create Rust Module Pair on a folder when you want Rust AutoMod to scaffold the next module correctly for the surrounding project style.
Depending on detection or your rustautomod.moduleLayout setting, it creates either:
orders/mod.rsorders.rsplusorders/
It also registers the new module in the correct parent target and asks for the visibility up front.
Use:
Set Module Visibilityto switch an existing module declaration betweenpub,pub(crate), and privateMove Module to Crate Rootwhen you want to pull a leaf module upward and then let Rust AutoMod rebuild declarations
These flows are also exposed from the Studio manager module tree when applicable.
Use these two commands together when a result looks surprising:
Explain AutoMod Decision: shows why Rust AutoMod chose a target and what lines it wants to generateShow Effective AutoMod Config: shows the winning rule, matched patterns, diagnostics, and config source
Right-click a file or folder and use Ignore in .rautomod to prepend an exclude= rule to the workspace .rautomod. This is especially useful for:
- generated code
- fixtures
- snapshots
- migration folders
- vendored examples
Open any .rautomod file to work in the visual editor. Use Split when you want to see both the rule cards and the raw text at the same time.
The visual editor is especially useful when:
- you are creating a config for the first time
- you want to compare multiple rule blocks quickly
- you want guardrails around valid values such as
visibility,sort, ortarget - you want diagnostics visible while editing
- you want impact preview and rule-playground feedback without leaving the file
- you want to preserve unmanaged comments while still editing visually
If you want a broader workspace view, run Open Rust AutoMod Manager to open the central panel and jump into a config from there.
Place a .rautomod file at the root of your Rust project, or inside a subfolder, to customize behavior.
The file is now recognized as its own VS Code language, with a dedicated Explorer icon, colors for comments, keys, operators, known values, cfg(...) expressions, and list entries. You can run Format Document on .rautomod files to normalize spacing, assignment style, blank lines, and comma-separated lists, and the extension now provides quick fixes for invalid keys and common missing entries.
If you prefer a GUI instead of editing raw text, open the file in the built-in visual editor. The visual editor still writes back to the same .rautomod text file, so Git history, diffs, merges, and manual editing continue to work normally.
Visual saves now try to preserve:
- leading comment blocks
- unmanaged blocks that are not recognized as Rust AutoMod keys
- comments attached to managed document/rule blocks
For a line-by-line explanation of every key, precedence rule, and matching behavior, see docs/RAUTOMOD_REFERENCE.md.
Example:
visibility=pub
sort=alpha
fmt=enabled
target=auto
Available keys:
visibility=pub|private|pub(crate)|pub(super)sort=alpha|alpha_case_insensitive|none|pub_first|cfg_firstfmt=enabled|disabledtarget=auto|mod.rs|lib.rs|main.rsexclude=generated/**,tests/**cfg=feature="serde",all(unix, target_pointer_width = "64")pattern=utils,helpers,!testsgroup_order=use,cfg,pub_mod,mod,pub_useblank_lines=0|1|2reexport=enabled|disabledheader=generated by rustautomodgenerated_comment=managed by rustautomodstrict=off|warn|errorschema_version=1extends=./shared.rautomod
Example with inheritance, excludes, and generated comments:
schema_version=1
strict=warn
extends=./shared.rautomod
visibility=pub
sort=alpha
fmt=enabled
target=auto
group_order=use,cfg,pub_mod,mod,pub_use
blank_lines=1
reexport=disabled
generated_comment=managed by rustautomod
pattern=internal,!tests
visibility=private
sort=alpha_case_insensitive
exclude=generated/**
reexport=enabled
patternsupports negative entries with!.excludemarks matching files or folders as ignored by Rust AutoMod.extendsresolves relative to the current.rautomod.targetlets a rule choosemod.rs,lib.rs,main.rs, or automatic resolution.group_ordercontrols how managed declarations are grouped relative touse,cfg, public/private modules, and generatedpub use.blank_linescontrols spacing between managed groups.strict=errormakes validation strict enough for diagnostics to block automod actions that rely on the config file.
Here are a few common shapes that Rust AutoMod handles well:
src/
lib.rs
api.rs
config.rs
With target=auto, Rust AutoMod can keep src/lib.rs updated with:
pub mod api;
pub mod config;pattern=internal,!tests
visibility=private
sort=alpha_case_insensitive
This is useful when you want helper folders to stay internal even if the rest of the crate is public.
pattern=platform
cfg=unix,windows
visibility=pub
This generates #[cfg(...)] attributes before the managed declarations for matching modules.
exclude=generated/**,fixtures/**
Rust AutoMod resolves the config but skips writes for matching files and folders.
pattern=prelude
reexport=enabled
generated_comment=managed by rustautomod
This is handy for folders where the module file should both declare and re-export submodules.
For more complete, real-world examples, see docs/USE_CASES.md.
- Open VS Code.
- Open Extensions.
- Search for
Rust AutoMod. - Install and reload the editor.
- Open a Rust project with a
Cargo.toml. - Optionally add a
.rautomodfile. - Create or delete
.rsfiles inside your module folders. - Use
Preview AutoMod Changeswhen you want a dry run and diff. - Use
Regenerate Rust Modulesto rebuild a folder or workspace. - Use the Explorer commands when you want to hide or restore
mod.rs, ignore paths, or scaffold.rautomod. - Use
Explain AutoMod DecisionandShow Effective AutoMod Configwhen you want to understand why a file was handled a certain way.
The extension was refactored so each responsibility lives in a smaller module.
src/automod/automodModFile.ts: orchestration for create, delete, rename, regenerate, preview, explain, ignore, and scaffold flowssrc/automod/automodRuntime.ts: shared runtime for preview, diff, undo history, conflict detection, and batch applicationsrc/automod/modDeclarations.ts: parsing and generation of module declaration blockssrc/automod/modContentEditor.ts: insertion, removal, and sorting of declaration contentsrc/automod/modFileSystem.ts: async file-system helpers and target-file resolutionsrc/automod/cargoFmt.ts: isolatedcargo fmtintegrationsrc/automod/automodConfigFile.ts:.rautomodparsing, inheritance, pattern matching, and effective-config resolution
src/workbench/control.ts: Explorer command/controller flowsrc/workbench/modVisibility.ts: index-likemod.rsdetection and exclude reconciliationsrc/workbench/modVisibilityWorkspaceService.ts: per-workspace visibility persistence andfiles.excludesyncsrc/workspace/workspaceStateService.ts: generic workspace-scoped state storagesrc/workspace/automodLogger.ts: structured output channel loggingsrc/workspace/automodHistoryService.ts: undo stack for automod batches
src/linting/linting.automod.ts:.rautomoddiagnostics and strict-mode severity handlingsrc/linting/linting.codeActions.ts: quick fixes for invalid keys and common missing entriessrc/linting/linting.completion.ts: completions for the expanded.rautomodkey setsrc/linting/linting.formatting.ts: document formatting provider for.rautomodsrc/ui/rautomodCustomEditor.ts: per-file custom editor with visual, split, and raw workflowssrc/ui/rautomodManagerView.ts: workspace manager sidebar and full manager panelsrc/ui/rautomodState.ts: view-model shaping for the UI layersrc/ui/rautomodWebviewTemplates.ts: shared HTML shell for the Rust AutoMod Studio webviewsmedia/rautomodWebview.css: shared product-style UI styling for the manager and editormedia/rautomodEditorWebview.js: front-end logic for the per-file visual editormedia/rautomodManagerWebview.js: front-end logic for the manager UI
yarn compileyarn lintyarn test:unityarn testyarn screenshots:studio
The project now includes:
- unit tests for visibility heuristics
- unit tests for
mod.rscontent editing - unit tests for
.rautomodformatting - config-resolution tests for
.rautomodinheritance, negation, and excludes - config-serialization tests for comment and unmanaged-block preservation
- extension integration tests for Explorer commands and
files.exclude - extension integration tests for
.rautomodlanguage detection and formatting - extension integration tests for scaffold, ignore, preview, regenerate, undo, and effective config inspection
- extension integration tests for modern module layout detection, module-pair creation, and manager module-tree rendering
- the existing debounce and rename-detection suites
fmt=enabledrequirescargoandrustfmtto be available in your environment.- If no
.rautomodfile is found, Rust Automod falls back to VS Code settings underrustautomod.*. target=lib.rsandtarget=main.rsare most useful for crate-root style rules.- The extension ignores invalid or unsafe paths such as
.git,target,node_modules, and similar folders. - Some icon themes may override the default
.rautomodicon contributed by the extension. - Visual saves still normalize managed
.rautomodstructure, but now try to preserve leading comments, unmanaged blocks, and comments attached to managed sections.RawandSplitare still the safest modes when exact hand-tuned formatting matters.
Contributions, issues, and feature requests are welcome.



