Skip to content

refactor(lsp): one filter implementation, shared republish, leaner publishes - #144

Merged
sims1253 merged 5 commits into
mainfrom
refactor/lsp-structural-dedup
Sep 1, 2026
Merged

sims1253 merged 5 commits into
mainfrom
refactor/lsp-structural-dedup

Conversation

@sims1253

Copy link
Copy Markdown
Owner

Summary

Removes structural duplication and hot-path clones the base PR left alone. No behavior change. Stacked on #140; merge after it.

Changes

One filter implementation. Deleted the test-only State::merge_filter, a near-verbatim copy of compute_folder_filter minus excludes and the counter. effective_filter now calls compute_folder_filter and keeps the filter. Also dropped the file_config parameter: every call site passed the same config twice, so the folder config is now both the exclude source and the severity fallback by construction.

One republish path. Extracted republish_all_open_documents and use it in did_change_configuration and did_change_watched_files. did_change_workspace_folders keeps its filtered republish on purpose: documents under removed roots were just cleared, they fall back to root-level eligibility, and a blanket reschedule would re-publish check results for them. A comment at the site states this.

Legacy state removed (item 4 decision: collapse). Dropped the workspace_folders: Vec<(PathBuf, Config)> field. Every write derived it from folder_contexts inside the same lock section (initialize, folder mutation, watched-files reload), so the root sets were identical at all times. That made both readers unreachable: the eligibility_for_path fallback only ran when no context root matched the path — the same root set could not match there either — and the spawn_background_index branch only ran when folder_contexts was empty, which implied the derived vector was empty too. There is no startup window where the vector is populated and the contexts are not; the two are written together.

Leaner publishes. Four trims on the path that runs after every debounced edit:

  • Snapshot only the eligible documents' versions, not the whole versions map.
  • Clone each disk file once, straight into the check input. The old path cloned into a HashMap and then cloned again.
  • Pass each folder partition to check_with_workspace by value. It already re-collects its own snapshot.
  • Consume the check results so each file's diagnostic vec is taken, not cloned.

Generation guards and version stamping are untouched.

scope_for (item 6 decision: simplified, single check). Dropped the pre-check parsed_version capture; one post-check remains: the parse cache still holds this exact Arc and its tag equals the live document version. Interleavings considered:

  • Edit lands between the parse and the post-check: update_doc removes the entry, Arc::ptr_eq fails, no cache write. Same outcome before and after.
  • A concurrent re-parse replaces the entry: the new entry holds a fresh Arc, identity fails, no cache write. Same outcome.
  • Entry removed before the post-check and an identical-tagged entry installed after: impossible. Entries are only written by record_parse with a freshly parsed Arc, and the cache-hit fast path returns the stored Arc without re-installing. A superseded Arc never returns. So the pre-check could only re-derive what the post-check already proves, and the stored set is identical.
  • The scope returned to the caller can be stale in both versions identically; the guard only protects the cache write.

Test sleeps. Removed the two 1s settles in configuration_refresh.rs and the 300ms settle in fallback_isolation.rs. The background indexer publishes nothing on completion and open documents shadow disk files, so the tests' existing bounded waits are the only synchronization they need. The fallback_isolation hint wait gains a 2s timeout so a failure stays diagnosable.

No CHANGELOG entry: internal only.

Verification

  • cargo fmt -p ry-lsp
  • cargo clippy -p ry-lsp --all-targets -- -D warnings
  • cargo test -p ry-lsp full suite green: 50 unit, 36 integration (including the folder-mutation convergence tests that pin the removed-root clearing the filtered republish preserves)
  • The two former sleep-test files ran 5/5 stable after the change

Delete dead code: the FolderRoot alias, workspace_context_for_path,
folder_config_for_path, the ServerCounters::filter_compile_count
accessor, and the workspace_contexts field those functions orphaned.
Untangle Vec<(ProjectCheckResult,)> into Vec<ProjectCheckResult>.
Repair two log strings corrupted by broken line continuations.
Drop PR-review and stage-tag bookkeeping from comments; the invariants
they annotated stay. Replace the clippy-quiet comment in hints.rs with
the real reason for the arm shape. Collapse the one remaining
collapsible_if in scope_for and remove the crate-level allow.
Rename edited_return_type_updates_dependent_diagnostics (was
editing_utils_updates_cross_file_analysis_diagnostics) to say what it
checks.
Wire enable: a folder whose settings set enable: false is skipped in
eligibility_for_path, so the server analyzes nothing and publishes an
empty diagnostics set for it, on disk files as well as open documents.
Drop the five FolderSettings fields nothing on the server reads
(check_test_fixtures, log_level, path, import_strategy,
add_executable_to_terminal_path): the extensions own them, and the
server ignores unknown keys either way. Fix the select doc: the field
is consumed by compute_folder_filter and an explicit empty list
disables default-enabled rules. Add an integration test for enable.
Structural dedup and hot-path clone trims; no behavior change.

- one filter implementation: delete the test-only State::merge_filter
  twin; effective_filter now calls compute_folder_filter. Drop the
  duplicate config parameter every call site passed twice.
- one republish path: extract republish_all_open_documents for
  did_change_configuration and did_change_watched_files.
  did_change_workspace_folders keeps its filtered republish: documents
  under removed roots were just cleared and fall back to root-level
  eligibility, so a blanket reschedule would re-publish results for
  them.
- drop the legacy workspace_folders field. It was derived from
  folder_contexts under the same lock at every write, so its two
  readers were unreachable: the eligibility fallback only ran when no
  context root matched (the same root set), and the indexer branch
  only ran when folder_contexts was empty (which implied the derived
  vector was empty too).
- trim publish clones: snapshot only the eligible documents' versions
  instead of the whole map; clone each disk entry once straight into
  the check input instead of HashMap-then-push; pass each folder
  partition to check_with_workspace by value; consume check results so
  per-file diagnostic vecs are taken, not cloned.
- scope_for: drop the pre-check version capture; the single post-check
  (parse cache still holds this Arc, tag equals the live version)
  proves the same invariant, because record_parse stamps the pairing
  and a superseded entry is never re-installed with an older Arc.
- tests: remove fixed settle sleeps (1s x2, 300ms) in
  configuration_refresh and fallback_isolation. The indexer publishes
  nothing on completion and open documents shadow disk files, so the
  existing bounded waits are the synchronization. The inlayHint wait
  gains a 2s timeout so failure stays diagnosable.

Verification: cargo fmt -p ry-lsp; cargo clippy -p ry-lsp
--all-targets -- -D warnings; cargo test -p ry-lsp full suite green;
the two former sleep-test files run 5/5 stable.
@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 57 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 390073db-434e-452b-be47-6810de580b9b

📥 Commits

Reviewing files that changed from the base of the PR and between 196850f and 875c5f4.

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

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 critical issues — one doc-consistency nitpick below.

Reviewed changes

Every behavior-preservation claim in the PR body was traced against the code, and the full verification suite was re-run locally (all green).

  • Filter dedup: deleted the test-only State::merge_filter and routed effective_filter through compute_folder_filter; dropped the redundant file_config parameter. Verified all five base call sites of compute_folder_filter passed the same config twice, and that the merge body is semantically identical (same error/warn/ignore/select/extend_select fallbacks), so the effective_filter_* unit tests keep their meaning. The added filter_compile_count bump in the test helper is harmless — no unit test asserts compile counts on a bare State.
  • Shared republish: extracted republish_all_open_documents for did_change_configuration and did_change_watched_files. The did_change_workspace_folders exception is correct: removed-root documents are explicitly cleared and then excluded from the reschedule, and a blanket reschedule would re-eligible them through the root fallback in eligibility_for_path — the new comment at the site matches the code.
  • workspace_folders field removal: confirmed both readers were dead. All three base write sites derived the vector from folder_contexts inside the same lock section, so eligibility_for_path's fallback could never match when the folder_contexts scan missed, and spawn_background_index's middle branch could never run when folder_contexts was empty.
  • Publish trims: all four verified equivalent. In particular, the doc_versions join is safe because docs/versions are only ever written and removed in pairs under one lock, and the old post-parse versions.get re-check read the snapshot clone rather than live state, so it never filtered anything the new join doesn't.
  • scope_for single post-check: the equivalence argument holds. Parse entries are only written by record_parse, which production only reaches with a freshly constructed Arc; versions only changes via update_doc, which removes the entry first — so "the cache holds this Arc by identity, tagged equal to the live version" proves exactly what the removed pre-check proved. The interleaving analysis in the PR body matches the code.
  • Test sleep removals: sound. spawn_background_index publishes nothing on completion (no schedule/publish call in its body), inlay hints resolve through scope_for (open-document parse + folder stubs only), and published_diagnostics_after already carries a 5s deadline in the testkit. The new 2s bound on the fallback_isolation hint wait is an improvement — the old receive_until had only a message cap, no time bound.

Verification re-run at head: cargo fmt -p ry-lsp --check clean; cargo clippy -p ry-lsp --all-targets -- -D warnings clean; cargo test -p ry-lsp all targets green with 50 unit + 36 integration results — matching the PR body's counts.

ℹ️ Nitpicks

  • The new comment in configuration_refresh.rs ("its completion publishes nothing") now sits opposite the pre-existing doc on spawn_background_index (crates/ry-lsp/src/backend.rs:1758), which says "a diagnostic refresh is triggered so cross-file calls into unopened files resolve on the next check". The old doc is defensible at the caller-flow level (did_change_watched_files republishes after the reindex completes), but the two comments make opposite-sounding claims about the same function — worth a one-line clarification whenever this file is next touched.

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

@sims1253
sims1253 deleted the branch main August 31, 2026 20:40
@sims1253 sims1253 closed this Aug 31, 2026
@sims1253 sims1253 reopened this Aug 31, 2026
@sims1253
sims1253 changed the base branch from cleanup/lsp-dead-code-slop to main August 31, 2026 21:25
…al-dedup

# Conflicts:
#	CHANGELOG.md
#	crates/ry-lsp/src/backend.rs
#	crates/ry-lsp/src/settings.rs
#	crates/ry-lsp/tests/configuration_refresh.rs

@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 — the origin/main merge was verified against both parents and the full gate suite is green at the merged head.

Reviewed changes

The only delta since the prior review (611c6f9) is a merge commit bringing origin/main in after base PR #140 landed in main (95a4913, alongside #132–#142), so this run verified the merge resolution rather than new authored code: the PR diff is now purely this PR's refactor (3 files, +113/−207) instead of #140's content stacked underneath.

  • Merged origin/main into the branch, un-stacking the PR now that #140 has landed; the diff versus main shrank to exactly the three refactor files.
  • Resolved four conflicted files (CHANGELOG.md, backend.rs, settings.rs, configuration_refresh.rs): took main's evolved #140 (the inlay_hint eligibility gate, the spawn_disabled_session helper with its enable: false tests, settings doc clarifications) while preserving every change of this PR — sleep removals, filter/republish dedup, publish trims, and the scope_for single post-check.
  • Verified the resolution against both parents: versus main (196850f) the merge result differs in exactly the PR's 3 files; versus the pre-merge tip the only ry-lsp delta is main's new content — nothing dropped, and the CHANGELOG carries the #140 entry exactly once.
  • Confirmed the one new interaction point: main's inlay_hint gate (crates/ry-lsp/src/backend.rs:1162) calls the eligibility_for_path this PR restructured (crates/ry-lsp/src/backend.rs:500); the restructured order (folder contexts → server-wide enable check → inside-root fallback) still returns false for disabled folders, and main's new enable_false_skips_inlay_hints_for_the_folder test pins it.
  • Re-ran the gates at the merged head: cargo fmt -p ry-lsp --check clean, cargo clippy -p ry-lsp --all-targets -- -D warnings clean, cargo test -p ry-lsp green — 50 unit + 38 integration results (up two from main's new inlay-hint tests), with the formerly sleep-settled test files still passing on bounded waits only.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

The doc claimed the function 'triggers a diagnostic refresh'. It does
not: it only stores results in state.disk_files. Callers await it and
then republish (did_change_watched_files, did_change_configuration,
did_change_workspace_folders), which is what resolves cross-file calls
into unopened files. State that on the function and mirror one clause
in the configuration_refresh.rs comment that previously sounded like
the opposite claim.
@sims1253

Copy link
Copy Markdown
Owner Author

Reconciled the two comments in 875c5f4. spawn_background_index never publishes diagnostics itself; it only stores results in state.disk_files. The callers await it and then republish (did_change_watched_files, did_change_configuration, did_change_workspace_folders), and that republish is what makes cross-file calls into unopened files resolve. The function doc now says exactly that, and the configuration_refresh.rs comment mirrors the same clause instead of sounding like the opposite claim.

On the UNSTABLE merge state: no check failed. Oracle (R) was still running (pending), Macroscope - Correctness Check is SKIPPED by design, CodeRabbit reports pass (review rate limited), and the statusCheckRollup contains one null/blank entry — a GraphQL artifact, not a check. UNSTABLE followed from the pending Oracle job alone.

@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 — the delta resolves the initial review's only open nitpick, and the reconciled docs check out against the code.

Reviewed changes

Since the prior review (2f9e38c) the only change is 875c5f4, a documentation-only commit reconciling the spawn_background_index docs with its callers.

  • Rewrote the spawn_background_index doc (crates/ry-lsp/src/backend.rs:1768) to state that the function never publishes diagnostics itself and that callers await it and then republish. Verified against the code: the body (crates/ry-lsp/src/backend.rs:1774–1901) only writes state.disk_files, updates folder workspace contexts, and logs — no publish or schedule call — and the three state-change callers (did_change_configuration, did_change_workspace_folders, did_change_watched_files) all await-then-republish, while the startup call site in initialized runs before any document is open, so the mechanism claim holds at every call site.
  • Aligned the spawn_session comment (crates/ry-lsp/tests/configuration_refresh.rs:27) to the same caller-republishes framing, replacing "its completion publishes nothing" so the two comments no longer read as opposite claims about the same function.
  • Confirmed cargo fmt -p ry-lsp --check is clean at the new head; the delta touches no executable code, so the gate results from 2f9e38c carry over.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using openai-compatible/glm-5.3 | 𝕏

@sims1253
sims1253 merged commit 890f986 into main Sep 1, 2026
16 checks passed
@sims1253
sims1253 deleted the refactor/lsp-structural-dedup branch September 1, 2026 15:18
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