Skip to content

refactor(lsp): drop test-only counter threading, fold folder_projects into contexts - #158

Merged
sims1253 merged 1 commit into
mainfrom
cleanup/02b-lsp-structural
Sep 2, 2026
Merged

refactor(lsp): drop test-only counter threading, fold folder_projects into contexts#158
sims1253 merged 1 commit into
mainfrom
cleanup/02b-lsp-structural

Conversation

@sims1253

@sims1253 sims1253 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Cleanup sprint, PR 2b (stacks on #156). Net −139 lines. These are the two "judgment call" cleanups split out from the backend.rs diet so they can be accepted or rejected independently — they are the only changes in this sprint that remove instrumentation and a defensive structure rather than pure duplication.

1. Test-only filter-compile counter threading (−~80)

filter_compile_count / compile_during_last_publish / ServerCounters / run_with_counters existed solely so one integration test could assert "zero filter compiles during a publish cycle" — production signatures (compute_folder_filter, build_folder_contexts, rebuild_folder_context(s), refresh_cached_folder_filters) carried a counter parameter purely for it. Deleted the threading; the test keeps all its real assertions (RY090 sentinels, field-by-field equality, paths) and loses only the counter assertion.

Coverage lost by design: the "zero compiles during publish" property. It is structural — filters are precomputed when folder contexts are built (build_folder_contexts / refresh_cached_folder_filters), never inside the publish loop — but the counter was a tripwire against future regressions of that structure. If you want the tripwire back, the honest place is a debug log or a debug_assert!, not six threaded parameters.

Kept: BASELINE_DISK_READS and its three no-I/O-during-publish tests — that counter guards actual disk behavior and stays.

2. folder_projects mirror folded into FolderAnalysisContext (−~59)

State kept two parallel maps keyed by folder URI (folder_contexts, folder_projects) that were built together, synchronized at four sites, and looked up together — a desync bug class for no benefit. The project cache now lives inside FolderAnalysisContext (Arc<Mutex<ProjectCache>>), and the parallel map plus its sync code is gone.

Details verified by independent review: the removed unwrap_or_else(root_project) fallback was unreachable on base (no divergence window between the maps — every mutation was atomic under one lock); rebuild_folder_context carries the old cache Arc so incremental check state survives config reloads (a fresh cache there would have forced full re-installs — same diagnostics, wasted work); lock ordering (state lock released before any project-cache lock) is unchanged at all three sites.

Gates

cargo test --workspace (all LSP integration suites green: protocol_contract, session_state_machine, session, protocol, fallback_isolation, configuration_refresh), clippy -D warnings, fmt.

Summary by CodeRabbit

  • Improvements

    • Improved diagnostic handling across workspace folders, with folder-specific analysis information retained more consistently during updates and background processing.
    • Diagnostic results for indexed files continue to be validated across projects with different filtering configurations.
  • Testing

    • Updated protocol coverage to verify diagnostic correctness across many files and workspace folders.
    • Streamlined server lifecycle testing while preserving standard shutdown behavior.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 27bf9061-5c95-493c-96c8-4c7bdd8c40f6

📥 Commits

Reviewing files that changed from the base of the PR and between 62b9290 and a36d033.

📒 Files selected for processing (3)
  • crates/ry-lsp/src/backend.rs
  • crates/ry-lsp/src/lib.rs
  • crates/ry-lsp/tests/protocol_contract.rs

📝 Walkthrough

Walkthrough

Changes

The LSP backend now stores one ProjectCache in each FolderAnalysisContext. Context rebuilds preserve existing caches. Diagnostics and cleanup use the owning context directly. Filter compilation counters and the counter-based test server API were removed.

Folder cache ownership

Layer / File(s) Summary
Context cache construction
crates/ry-lsp/src/backend.rs
FolderAnalysisContext owns a ProjectCache. Folder context construction and root filter computation no longer use compilation counters.
Cache lifecycle and diagnostics
crates/ry-lsp/src/backend.rs
Workspace updates create caches for new contexts and retain caches for surviving contexts. Rebuilds preserve existing caches. Cleanup and diagnostics access caches through folder contexts.
Server counter seam removal
crates/ry-lsp/src/lib.rs, crates/ry-lsp/tests/protocol_contract.rs
run_with_counters and ServerCounters were removed. The protocol test uses run_with and validates diagnostic correctness without construction counters.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit checks each folder’s store
Caches stay when contexts restore
Counters hop away
Diagnostics find their way
Clean paths bloom across the door

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cleanup/02b-lsp-structural

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — this PR's full diff (3 files, 1 commit): the two judgment-call cleanups split out from the backend.rs diet.

  • Test-only counter threading removed: filter_compile_count / compile_during_last_publish / ServerCounters / run_with_counters are gone and run_with is now the single server-construction path for production and tests; a repo-wide grep finds no stale references to any removed symbol. The lost "zero filter compiles during publish" tripwire is a documented, by-design trade — and the disk-behavior counters (BASELINE_DISK_READS, parse_count) stay.
  • folder_projects folded into FolderAnalysisContext: the per-folder ProjectCache now lives at backend.rs:163, and the parallel map plus its sync sites are gone. I independently confirmed the three claims in the description: the removed unwrap_or_else(root_project) fallback was unreachable on base (per_folder keys derive from folder_contexts itself at backend.rs:1325, and every base mutation of the two maps was atomic under one state lock — the config-reload path preserves roots, so keys stayed stable); rebuild_folder_context clones the old cache Arc (backend.rs:1863) so incremental check state survives config reloads exactly as before; and lock ordering (state lock released before any project-cache lock) is unchanged at did_close (backend.rs:899) and the publish loop (backend.rs:1307). The new comment at backend.rs:775 accurately describes the workspace-folder mutation semantics.
  • Test updated honestly: many_files_flat_filter_construction keeps the RY090 sentinel, field-by-field equality, and first/last path assertions, and the triple-unwrap chain matches the new JoinHandle<LspResult<()>> shape.

Gates verified locally: cargo build -p ry-cli, cargo test -p ry-lsp (all targets — all suites green including the modified test), cargo clippy -p ry-lsp --all-targets -- -D warnings, and cargo fmt --check.

Pullfrog  | View workflow run | Using openai-compatible/glm-5.3𝕏

@sims1253
sims1253 changed the base branch from cleanup/02-lsp-diet to main September 2, 2026 10:08
@sims1253
sims1253 force-pushed the cleanup/02b-lsp-structural branch from 7ea3b47 to a36d033 Compare September 2, 2026 10:15
@sims1253
sims1253 merged commit a988a03 into main Sep 2, 2026
14 of 15 checks passed
@sims1253
sims1253 deleted the cleanup/02b-lsp-structural branch September 2, 2026 10:19
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