Roadmap Phase 3-8: unify config resolution and cache per-call waste - #121
Merged
Conversation
- cache explicit --config loads by canonical path + mtime - rfmt config prints the effective Rust-resolved configuration - fail fast once on a broken --config instead of per-file errors - align Rfmt::Config.find search order with the Rust side - ConfigError follows the message-only Display convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 8 of the ruby-prism migration plan (#110 Phase 3): one config system, and the per-call waste that the fork model used to hide is gone.
What changes for users
--config PATHactually works now. It was silently ignored by the formatter: the Ruby side only used it for file selection while Rust independently re-discovered config on every call. Now:rfmt --config custom.yml --write file.rbapplies the file's formatting settings (verified end-to-end with a distinctiveindent_width)exit_on_failure?undefined) meant even error paths exited 0rfmt confignow prints the effective settings the Rust formatter actually resolved (via a newresolved_config_yamlFFI), instead of a Ruby-side approximation.rfmt.ymletc.) is unchanged for well-formed files; a broken discovered file now warns and falls back to defaults instead of failing every format (deliberate: an LSP mid-edit of.rfmt.ymlshould not make formatting impossible). Explicit-path errors stay loud — the asymmetry is documented and testedLong-lived processes pick up config edits: discovery results are cached keyed by cwd + found-file mtime; editing
.rfmt.ymlbetween two in-process formats changes the output (tested). Known limit (in code): a config newly created in a parent directory is picked up on the next cache invalidation, not instantly.Performance
Config::discover()was a cwd→root→home filesystem walk on everyRfmt.formatcall, andFormatter::newrebuilt the 23-rule registry each time. With the discovery cache (walk → one stat batch), an explicit-path cache, and aOnceLockregistry:Cumulative since the migration started: 4.28 → 0.19 ms/file (~22x).
Design notes
format_code/1,format_code_with_config/2) instead of magnus variadic parsing; config crosses the boundary as a PATH so YAML parsing stays in one placeRfmt.format(source, config_path: nil)keeps the positional call compatibleConfiguration(Ruby) shrinks to file-selection/cache concerns; the three discovery implementations now share one search order (full dedup left out of scope, noted in the plan)Verification