Skip to content

refactor: split the five largest files into modules - #82

Merged
IAmJSD merged 1 commit into
mainfrom
refactor/split-godfiles
Aug 30, 2026
Merged

IAmJSD merged 1 commit into
mainfrom
refactor/split-godfiles

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Aug 30, 2026

Copy link
Copy Markdown
Member

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.

file was now
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

How the two god-impls were cut

Both 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 — layers, vector, text, raster, adjust, effects — with its free functions grouped by job into bitmap, resample, shapes, paint, dump.

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 things a line-for-line diff won't show

  • dialogs.rs had a module-scoped use 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.rs lost 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 warnings and cargo 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) and plugins/tools-paint/src/lib.rs (2094).

🤖 Generated with Claude Code

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]>
@IAmJSD
IAmJSD merged commit 9bf6b3a into main Aug 30, 2026
3 checks passed
@IAmJSD
IAmJSD deleted the refactor/split-godfiles branch August 30, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant