Skip to content

refactor(chart): split the screener market scan into its steps - #1484

Merged
kirillDevPro merged 1 commit into
mainfrom
lane/refactor-2026-11-26
Nov 26, 2026
Merged

kirillDevPro merged 1 commit into
mainfrom
lane/refactor-2026-11-26

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

Refactor lane.

Signal: an oversized function. scan_market
(crates/moon-chart/src/auto_figures/scan.rs:402) was 171 lines from
signature to closing brace, over the 120-line limit (CONTRIBUTING.md sets
none). It now reads as its steps and is 44 lines; the parts moved into
private helpers in the same file:

  • run_rows (scan.rs:461): per-row closed bars, history check and
    detector run, returning the scanned/short counts.
  • pick_rows (scan.rs:516): each row's take plus the cross-row twin
    pass.
  • keep_lines (scan.rs:551): placing the picked lines against the last
    price and marking their events.
  • mark_confluence (scan.rs:604): the confluence pass over kept lines.
  • best_and_nearest (scan.rs:625): the best event and the nearest line.

Lines: one 171-line function -> 44 + 5 helpers (one file, about 100
insertions, 20 deletions). Signature, visibility, iteration order and
arithmetic are unchanged; the scratch buffers runs and kept are still
cleared in scan_market at the same point as before; no test file
changed.

Tests that cover it: cargo test -p moon-chart auto_figures::scan
(scan/tests.rs, 22 tests, every one calls scan_market; green before and
after the edit), the whole cargo test -p moon-chart (453 passed), and the
dependent's screener tests cargo test -p moon-ui-gpui --bin moonterminal screener:: (62 passed). cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --all are clean.

Reviewer: Codex. Its one finding: the first draft moved kept.clear()
past the detector loop, so after a panic caught by unwinding, the
result's derived Debug could show the previous market's kept lines.
The clear was moved back to its original position before the commit.

Refactor lane.

Signal: an oversized function. `scan_market`
(crates/moon-chart/src/auto_figures/scan.rs:402) was 171 lines from
signature to closing brace, over the 120-line limit (CONTRIBUTING.md sets
none). It now reads as its steps and is 44 lines; the parts moved into
private helpers in the same file:

- `run_rows` (scan.rs:461): per-row closed bars, history check and
  detector run, returning the scanned/short counts.
- `pick_rows` (scan.rs:516): each row's `take` plus the cross-row twin
  pass.
- `keep_lines` (scan.rs:551): placing the picked lines against the last
  price and marking their events.
- `mark_confluence` (scan.rs:604): the confluence pass over kept lines.
- `best_and_nearest` (scan.rs:625): the best event and the nearest line.

Lines: one 171-line function -> 44 + 5 helpers (one file, about 100
insertions, 20 deletions). Signature, visibility, iteration order and
arithmetic are unchanged; the scratch buffers `runs` and `kept` are still
cleared in `scan_market` at the same point as before; no test file
changed.

Tests that cover it: `cargo test -p moon-chart auto_figures::scan`
(scan/tests.rs, 22 tests, every one calls `scan_market`; green before and
after the edit), the whole `cargo test -p moon-chart` (453 passed), and the
dependent's screener tests `cargo test -p moon-ui-gpui --bin moonterminal
screener::` (62 passed). `cargo clippy --workspace --all-targets -- -D
warnings` and `cargo fmt --all` are clean.

Reviewer: Codex. Its one finding: the first draft moved `kept.clear()`
past the detector loop, so after a panic caught by unwinding, the
result's derived `Debug` could show the previous market's kept lines.
The clear was moved back to its original position before the commit.
@kirillDevPro
kirillDevPro merged commit 183a39f into main Nov 26, 2026
16 checks passed
@kirillDevPro
kirillDevPro deleted the lane/refactor-2026-11-26 branch November 26, 2026 08:14
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