TODO §55: split lucisv_server state/mod.rs by responsibility (pure move)
state/mod.rs 986 -> 63 production lines: document.rs (one analyzed buffer), buffers.rs (open buffers), views.rs (closed-file view cache), scope.rs (roots, settings, scope ladder), rescan.rs (scan and widen protocol, 411), incremental.rs (one saved file re-indexed), sources.rs (file sets for refactorings, 170). The 3 944-line inline test module moved to state/tests/ (14 topic files). No function body changed; only forced pub(super) widenings. Lead's line-multiset check: no code line lost or added. CLAUDE.md measurement refreshed (2026-10-14); a stale test path in server/tests/folders.rs corrected. Gates on the merged tree: fmt and clippy -D warnings clean; lucisv_server 1 823 passed, 0 failed, 38 ignored (= before); the lane's workspace run 80 suites, 5 078 passed. Refactor dev Claude Fable 5.1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ca83f6f99f
commit
4fae8fb63a
27 files changed
+6131
-5814
No files matched your search
@@ -0,0 +1,193 @@
|
||||
# decomposition-state — TODO §55: `lucisv_server/src/state/mod.rs`
|
||||
|
||||
## Goal
|
||||
|
||||
Split the one file every workspace-state lane collides in —
|
||||
`crates/lucisv_server/src/state/mod.rs`, 5 941 lines: 986 production
|
||||
(non-blank, non-comment) in one 1 600-line `impl Workspace`, plus a
|
||||
3 944-line inline `mod tests` — into sibling modules a reader can describe
|
||||
in one sentence each, with the tests in `state/tests/`, one file per topic,
|
||||
mirroring `server/tests/`. A **pure move**: no behaviour change, no renamed
|
||||
item, no function body touched, every path another module imports
|
||||
preserved by re-exports from `state/mod.rs`, the per-suite test counts
|
||||
identical to the baseline. `discover.rs` and `scan.rs`, already split out,
|
||||
are untouched.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- `lucisv_server` is a binary crate; "public path" means what other
|
||||
modules of the crate import. Every one of them still resolves at
|
||||
`crate::state::…`: `Workspace`, `Document`, `FileView`,
|
||||
`WORKSPACE_SYMBOL_LIMIT`, `first_token_reaching`, `first_token_from`,
|
||||
`mixed_buffer` (`#[cfg(test)]`), `IndexEvent`, `Scan`,
|
||||
`discover::HEAD_WALK_MAX`. `Workspace`'s methods are methods whatever
|
||||
file their `impl` block is in, so no call site in the crate moved.
|
||||
- Sibling files are private modules; `Workspace`'s fields stay private
|
||||
(child modules see their ancestor's private items, as `discover.rs`
|
||||
already relied on), and so does `StoreOpen`. The only widenings are the
|
||||
private items a *sibling* now calls, all `pub(super)` and all taken from
|
||||
the compiler rather than guessed: `scope::{walks_the_workspace,
|
||||
raised_dirs, cache_dir}`, `buffers::{current_text, analysis_of}`,
|
||||
`views::forget_view`, `rescan::open_store`, and the two view-cache
|
||||
bounds `views::{MAX_VIEWS, MAX_VIEW_BYTES}` that one test file reads.
|
||||
- The tests are one `#[cfg(test)] mod tests;` in `state/mod.rs` →
|
||||
`state/tests/mod.rs`, whose sibling files are the sections the one big
|
||||
test module had, under the banner names it gave them. A helper more
|
||||
than one section used moved to `tests/mod.rs`; a helper one section
|
||||
used stayed with it. Each section's banner became the `//!` doc of its
|
||||
file, verbatim where the banner had a paragraph (the view cache,
|
||||
TODO §63.2). The test-local `struct Scan` (a scan's parsed/cached/
|
||||
analyzed census) shadows `state::Scan` inside `tests` exactly as it did
|
||||
inside the old inline module; the three files that drive a `state::Scan`
|
||||
by hand never name the type.
|
||||
- Moving the tests out of the inline module de-indents them by four
|
||||
spaces; `cargo fmt` then re-joined a dozen statements that fit in one
|
||||
line at the new indent. Whitespace only — every test name and body is
|
||||
the old one, and the 121 names are checked against the baseline log.
|
||||
- "Production lines" below are non-blank, non-comment lines outside
|
||||
`mod tests`, the CLAUDE.md metric.
|
||||
- The `lucisv` CLI does not depend on `lucisv_server`, so the formatter's
|
||||
output cannot move: the corpus/opentitan byte-identity sweep is vacuous
|
||||
for this lane and was not run. The gates are the test counts, the fmt
|
||||
and clippy runs, and the line-multiset check in the work log.
|
||||
|
||||
## Handshakes
|
||||
|
||||
- **Consumes** (unchanged): everything `state/mod.rs` imported before —
|
||||
`vlog_parser`, `vlog_semantic`, `crate::{candidates, convert, includes,
|
||||
index_cache, module_select, rename_trace, scan_order, scan_trace,
|
||||
settings, uri}` — now imported by the file that uses each.
|
||||
- **Promises** (unchanged): the public surface listed under Assumptions,
|
||||
re-exported from `state/mod.rs`.
|
||||
- **Request to the lead — CLAUDE.md measurement line.** TODO §55's item
|
||||
reads "CLAUDE.md's measurement line refreshed"; CLAUDE.md is outside
|
||||
this lane's ownership. The 2026-09-23 line says
|
||||
`lucisv_server/src/state/mod.rs` at 985 (already over; TODO §55). After
|
||||
this lane: `state/mod.rs` 63, `discover.rs` 412, `rescan.rs` 411,
|
||||
`sources.rs` 170, `scan.rs` 135, `document.rs` 122, `scope.rs` 99,
|
||||
`buffers.rs` 71, `views.rs` 54, `incremental.rs` 54 — nothing in
|
||||
`state/` over 600.
|
||||
- **Note, no edit asked**: `server/tests/folders.rs:128` names
|
||||
`state::tests::a_widen_that_subsumes_the_old_scope_reads_only_the_files_it_adds`
|
||||
in a plain comment; that test is now
|
||||
`state::tests::widen::a_widen_that_subsumes_…`. The name still finds it
|
||||
by grep; the path prefix is one segment stale.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] Baseline counts pinned (`cargo test -p lucisv_server` under guard).
|
||||
- [x] Production split: `document`, `buffers`, `views`, `scope`, `rescan`,
|
||||
`incremental`, `sources` beside `discover` and `scan`; `mod.rs` keeps
|
||||
the struct, `StoreOpen`, the table readers and the re-exports.
|
||||
- [x] Tests out to `state/tests/` (14 topic files + harness), every name
|
||||
and body kept.
|
||||
- [x] `cargo fmt -p lucisv_server`; `cargo fmt --all --check` clean.
|
||||
- [x] `cargo clippy --workspace --all-targets -- -D warnings` clean.
|
||||
- [x] `cargo test -p lucisv_server` after: counts equal the baseline.
|
||||
- [x] `cargo test --workspace --all-targets` once at the end.
|
||||
- [x] TODO §55 ticked.
|
||||
- [ ] CLAUDE.md measurement line — the lead's (Handshakes).
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-10-14 — the move (refactor dev, Fable)
|
||||
|
||||
**Baseline** (`tools/guard.sh -t 1800 -- cargo test -p lucisv_server`,
|
||||
guard exit 0): unittests 1 721 passed / 36 ignored; `tests/e2e.rs` 99 / 2;
|
||||
`tests/grammar.rs` 3 / 0. 121 of the unit tests are `state::tests::*`.
|
||||
|
||||
**Module map** — old `state/mod.rs` line ranges → new file, one sentence
|
||||
each (production lines after the move in brackets):
|
||||
|
||||
| new file | old lines | holds |
|
||||
|---|---|---|
|
||||
| `mod.rs` [63] | 1–44, 317–388, 475–503 | `Workspace` itself, `StoreOpen`, `WORKSPACE_SYMBOL_LIMIT`, the readers of its tables (`index`, `known_facts`, `candidates`, `includes`), the module list and the re-exports. |
|
||||
| `document.rs` [122] | 76–291 | One open buffer analyzed once from its text — `Document` and everything derived from it — and the two binary token searches (`first_token_reaching`, `first_token_from`, `mixed_buffer`). |
|
||||
| `buffers.rs` [71] | 675–751, 1985–1994, 1502–1515, 1490–1500 | The open buffers: `document`, `document_for_path`, `open_documents`, `set_document`, `is_large`, `has_large_documents`, `close_document`, `open_uris`, and which text speaks for a path (`text_of`, `current_text`, `analysis_of`). |
|
||||
| `views.rs` [54] | 46–74, 1913–1983, 299–315 | The closed-file view cache: `FileView`, its two bounds, `file_view`, `held_views`, `cached_view`, `forget_view`, `trim_views`. |
|
||||
| `scope.rs` [99] | 445–473, 505–595, 1557–1571, 597–673 | Roots, client settings and the scope ladder: `adopt_roots`, `change_roots`, `has_roots`, `roots`, `scope_dirs`, `folder_scoped`, `walks_the_workspace`, `raised`, `raised_dirs`, `client_settings`, `set_client_settings`, `cache_dir`, `set_storage_path`. |
|
||||
| `rescan.rs` [411] | 814–891, 947–1082, 893–945, 1084–1173, 1517–1555, 1175–1380, 391–443, 753–812, 293–297 | Driving a scan, whole or widen, from work list to landed tables: `begin_scan`, `begin_widen`, `discover_the_rest`, `open_store`, `scan_step`, `open_next`/`open_first`, `publish_scan`, `finish_scan`/`finish_whole_scan`/`landed`/`take_scan_trace`, `finish_widen`; then the test-only one-shot forms (`open_roots*`, `open_whole_workspace*`, `rebuild_index*`, `widen_index*`) and `held_bytes`. |
|
||||
| `incremental.rs` [54] | 1382–1488 | One saved file re-indexed in place: `update_one`, `update_one_checked`. |
|
||||
| `sources.rs` [170] | 1573–1911 | The file sets handed to refactorings: `sources`, `module_sources`, `module_sources_reaching`, `rename_sources_traced`, `fan_out_of`, `want_*`, `include_sources`. |
|
||||
|
||||
Reading order inside `rescan.rs` is the protocol's: begin → step →
|
||||
publish → finish, with the one-shot wrappers after a separator comment
|
||||
(the one piece of new comment text in production code). Within every
|
||||
other file the original order is kept.
|
||||
|
||||
**Tests** — old `mod tests` (1 997–5 941) → `state/tests/`:
|
||||
|
||||
| file | tests | section it was |
|
||||
|---|---|---|
|
||||
| `mod.rs` | — | harness: `uri`, `Tree`, and the 17 helpers more than one section used (`open`, `filler`, `tangled`, `wide`, `excluding`, `own_folder_only`, `using_filelist`, `capping`, `fat_package`, `caching`, `indexed`, `everything`, `seen`, `Scan`/`scan`/`file_name`, `walk_sources`) |
|
||||
| `document.rs` | 8 | the token searches and `Document` tests at the top; TODO §63.2 QA (the trace's arithmetic) from the bottom |
|
||||
| `large_file.rs` | 5 | the large-file fast path |
|
||||
| `views.rs` | 7 | the closed-file view cache |
|
||||
| `interleave.rs` | 6 | an interleaved scan against the one-shot scan it must equal |
|
||||
| `folders.rs` | 9 | `didChangeWorkspaceFolders` (the second half of the interleave section) |
|
||||
| `settings.rs` | 9 | gitignore/config/pushed excludes, which settings ask for a rescan, source extensions |
|
||||
| `size_cap.rs` | 7 | `lucisv.index.maxFileSize` |
|
||||
| `filelist.rs` | 11 | rung 1 and its `+incdir+`s |
|
||||
| `folder_scope.rs` | 15 | the folder scope + inherited obligations (index-scope review) |
|
||||
| `lazy_read.rs` | 6 | the lazy read and the folder-first order (§P4b3) |
|
||||
| `incremental.rs` | 6 | the incremental path |
|
||||
| `persistence.rs` | 15 | the persistent index cache |
|
||||
| `open_buffers.rs` | 8 | an open buffer's own analysis + the QA attacks on it; `an_open_buffer_overrides_disk_in_the_index` from the top section |
|
||||
| `widen.rs` | 9 | the incremental scope widen |
|
||||
|
||||
121 tests, the same 121 names as the baseline log (diffed).
|
||||
|
||||
**How the move was made.** A script sliced the original by line range
|
||||
(production) and by brace-balanced item (tests, each with its doc comment
|
||||
and attributes) into the scratchpad, asserting that every one of the
|
||||
5 941 original lines landed exactly once, was blank, or was one of the
|
||||
five structural lines (`impl Workspace {`, its `}`, the `mod tests`
|
||||
wrapper) or a section banner; the new files were then copied into
|
||||
`state/` and `mod.rs` rewritten from the assembled text (diffed: equal).
|
||||
Imports per file and the eight `pub(super)` widenings were added by hand,
|
||||
taken from the compiler. A second script checks the multiset of
|
||||
production lines of the old file against the union of the new ones: the
|
||||
only differences are `use` continuation lines and the separator comment
|
||||
above the one-shot forms.
|
||||
|
||||
**Longest functions** (raw lines, before = after, since no body moved):
|
||||
`begin_widen` 106 (85 production — the one over 80, left as it is; a pure
|
||||
move does not split functions), `scan_step` 70, `begin_scan` 67,
|
||||
`update_one` 58, `finish_whole_scan` 55, `rename_sources_traced` 52,
|
||||
`finish_widen` 48, `fan_out_of` 39, `Document::new` 35, `publish_scan`
|
||||
29.
|
||||
|
||||
**Gates** (every suite through `tools/guard.sh`, logs kept in the
|
||||
session scratchpad):
|
||||
|
||||
- `cargo fmt -p lucisv_server`: reordered the `use` blocks in five new
|
||||
files and re-joined 12 statements in the de-indented tests; then
|
||||
`cargo fmt --all --check` exit 0.
|
||||
- `tools/guard.sh -t 1800 -- cargo clippy --workspace --all-targets --
|
||||
-D warnings`: guard exit 0, no warnings.
|
||||
- `tools/guard.sh -t 1800 -- cargo test -p lucisv_server` after the
|
||||
move: 1 721 passed / 36 ignored, 99 / 2, 3 / 0 — equal to the baseline,
|
||||
guard exit 0. Two earlier runs each failed **one** `large::tests`
|
||||
wall-clock budget test (`…locate_their_hits_in_linear_time`, 173 ms
|
||||
against a 150 ms budget; then `…colours_in_linear_time`) with the host
|
||||
at load average 12–21 (`mediaanalysisd`, `XProtectRemediator`,
|
||||
`syspolicyd` near 50 % CPU each, a foreign `rustc`) — the host
|
||||
condition the brief names; `large.rs` is not touched by this lane, both
|
||||
tests pass alone, and the third full run passed clean. Reported, not
|
||||
worked around.
|
||||
- `tools/guard.sh -t 1800 -- cargo test --workspace --all-targets`: 80
|
||||
suites, every one `ok`, 5 078 passed / 51 ignored, guard exit 0.
|
||||
|
||||
## QA log
|
||||
|
||||
## Review
|
||||
|
||||
**2026-10-14 — lead.** Accepted as a pure move. Independent check: the
|
||||
multiset of code lines in the old `state/mod.rs` against the union of the
|
||||
new `state/` files (excluding `discover.rs`/`scan.rs`) differs only in `use`
|
||||
lines, the `impl Workspace {` headers, the forced `pub(super)` widenings
|
||||
listed in the work log, and rustfmt re-wrapping the same tokens in the
|
||||
de-indented tests — no code line lost or added. The CLAUDE.md measurement
|
||||
line is refreshed (2026-10-14 paragraph); the stale test path in
|
||||
`server/tests/folders.rs:128` is corrected. Merged onto master after the
|
||||
review lows; gates re-run on the merged tree.
|
||||
Reference in new issue
Block a user