Repository navigation
refactor: split the five largest files into modules - #82
Merged
Merged
Conversation
workspace.rs had grown to 8205 lines, almost all of it a single 6600-line `impl Workspace`. import.rs, panels.rs, dialogs.rs and the adjustments crate root were on the same trajectory. Nothing here changes behaviour: every item keeps its name, signature and body, and lands in a module named for what it does. crates/app/src/workspace.rs 8205 -> 26 files, largest 1510 crates/codec-affinity/src/import.rs 4839 -> 14 files, largest 1021 crates/adjustments/src/lib.rs 3192 -> 10 files, largest 606 crates/app/src/panels.rs 3184 -> 14 files, largest 534 crates/app/src/dialogs.rs 2919 -> 16 files, largest 457 The two god-impls split along boundaries the files already had. Rust allows inherent impl blocks across modules of a crate, so `impl Workspace` follows its own `// ----- section -----` markers into docs, recovery, viewport, edit_ops, layers_panel, modals, filters, render and the rest; `impl Walker` splits by the node kind each method interprets. A child module can see its parent's private items, so `Workspace`'s fields stay private in workspace/mod.rs and the only edit to a moved method is `fn` -> `pub(super) fn` where a sibling calls it. Types whose private fields are touched from more than one module -- RgbaImage, GradientFill, Homography -- stay in their parent module for the same reason. In the affinity importer the submodules reach each other through glob imports named once in import/mod.rs rather than sibling-by-sibling. Two details worth naming, because a line-for-line diff will not show them. dialogs.rs had a module-scoped `use gpui::prelude::FluentBuilder as _;` sitting two thirds of the way down the file; anonymous imports do not travel through a glob, so it stays beside its users. And panels.rs lost a `// ===== layers panel =====` marker that no longer marked anything. Verified by comparing the multiset of source lines before and after for each file: identical apart from the module scaffolding, the visibility prefixes above, and rustfmt rewrapping signatures those prefixes pushed past the line limit. fmt, clippy -D warnings and the 848 workspace tests all pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
workspace.rshad grown to 8205 lines, almost all of it a single 6600-lineimpl Workspace.import.rs,panels.rs,dialogs.rsand the adjustments crate root were on the same trajectory.Nothing here changes behaviour. Every item keeps its name, signature and body, and lands in a module named for what it does.
crates/app/src/workspace.rscrates/codec-affinity/src/import.rscrates/adjustments/src/lib.rscrates/app/src/panels.rscrates/app/src/dialogs.rsHow the two god-impls were cut
Both split along boundaries the files already had. Rust allows inherent
implblocks across modules of a crate, soimpl Workspacefollows its own// ----- section -----markers intodocs,recovery,viewport,edit_ops,layers_panel,modals,filters,renderand the rest.impl Walkersplits by the node kind each method interprets —layers,vector,text,raster,adjust,effects— with its free functions grouped by job intobitmap,resample,shapes,paint,dump.A child module can see its parent's private items, so
Workspace's fields stay private inworkspace/mod.rsand the only edit to a moved method isfn→pub(super) fnwhere a sibling calls it. Types whose private fields are touched from more than one module —RgbaImage,GradientFill,Homography— stay in their parent module for the same reason. In the affinity importer the submodules reach each other through glob imports named once inimport/mod.rsrather than sibling-by-sibling.Two things a line-for-line diff won't show
dialogs.rshad a module-scopeduse gpui::prelude::FluentBuilder as _;sitting two thirds of the way down the file. Anonymous imports don't travel through a glob, so it stays beside its users.panels.rslost a// ===== layers panel =====marker that no longer marked anything.Verification
I compared the multiset of source lines before and after for each of the five files. They are identical apart from the module scaffolding, the visibility prefixes above, and rustfmt rewrapping the signatures those prefixes pushed past the line limit.
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspace(848 passed, 0 failed) are all clean — the three commands CI runs.Next candidates, left alone here:
plugins/filters-core/src/neural.rs(2182) andplugins/tools-paint/src/lib.rs(2094).🤖 Generated with Claude Code