Repository navigation
fix(lsp): start finding diagnostics on the saved expression, not column 0 - #4688
Conversation
…mn 0 Diff probes carry analyzer column 1, so LSP ranges underlined leading whitespace on indented lines and hover only matched on that indent. Locate the probe expression on the saved line, measure the prefix in the negotiated encoding, and keep the column fallback when the file cannot be read. Analyzer columns and SARIF are unchanged. Closes #4602 Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedNext included review available in 34 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (3)
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. Comment |
Route a missing saved line through expression_span_range so the lib build does not warn that the column-based constructor is dead. Co-authored-by: Steven Zimmerman, CPA <EffortlessSteven@users.noreply.github.com>
EffortlessSteven
left a comment
There was a problem hiding this comment.
review-pr (author self-review, COMMENT)
GitHub cannot request changes from the author; this is not approval.
reviewed_head_sha: a0118496dfa1289828300f13d736b897dccd7773
integration_basis: origin/main at branch time 3dd43c383; PR base object now eb3a2e9ce (behind-only; no content conflict inspected as requiring restack)
claim_boundary: LSP-local finding diagnostic Range start on the saved probe expression (#4602). Analyzer columns, SARIF, BOM/non-UTF-8 decode (#4597), and producer-owned start_byte origins (#4464) are out of scope.
changed_surfaces_and_semantic_owners_inspected:
- crates/ripr/src/lsp/position.rs (encoding width + saved-line start)
- crates/ripr/src/lsp/diagnostics.rs (saved-line IO, diagnostic_range_for_finding)
- crates/ripr/src/lsp/tests.rs (production-path diagnostic_for_finding + hover matcher)
- hover.rs diagnostic_covers_position / position_in_range (consumer, not rewritten)
- seam/gap line_span_range and SARIF (untouched)
blocking_findings: none from source/oracle inspection
non_blocking_suggestions:
- First substring match is the specified LSP-local heuristic; repeated identical expressions stay #4464.
- Per-finding read_to_string is fail-closed and simple; a file cache is not required for this claim.
refuted_or_stale_findings: none
proof_and_ci_observed:
- Red before repair: diagnostic tests expected 36..42 and got 0..6 on a0118496d's parent behavior.
- cargo test -p ripr --lib -- lsp::position lsp::tests::diagnostic_for_finding_ : 37 passed on a0118496d
- cargo check -p ripr: clean
- cargo xtask precommit: pass (target/ripr/reports/precommit.md)
- cargo xtask check-fast: pass; independently git diff --name-only origin/main...HEAD = 3 rust files; selector ran clippy, skipped fixture-contracts
- Hosted: pr-plan/cargo-deny/dependency-review/GitGuardian success; Rust Small / rust-feature / ub-review in progress; Gemini quota (missing provider review, not clean review); CodeRabbit skipped-by-policy
proof_or_review_missing: exact-head required rust gates not terminal; ub-review not terminal
affected_currentness_dimensions: production implementation, test stimulus, test oracle, public claim (PR body). Generated/conflict unchanged.
residual_assumptions_and_non_claims:
- Hover is correct because it matches diagnostic.range; not a separate hover renderer rewrite.
- Expressions that already include leading indent (Python/TS preview goldens) stay at character 0 by verbatim find.
- Non-UTF-8 saved files fall back to column-1; #4597 is not absorbed.
disposition: REVIEW_INCOMPLETE
No blocking source defect on this head. Merge convergence waits on terminal required checks for a0118496d.
EffortlessSteven
left a comment
There was a problem hiding this comment.
review-pr (author self-review, COMMENT)
GitHub cannot request changes from the author; this is not approval.
Published-head refresh of the 2026-09-29T02:49:05Z pass on the same SHA. Source/oracle inspection is unchanged; exact-head CI/receipts and integration-basis currentness are refreshed.
reviewed_head_sha: a0118496dfa1289828300f13d736b897dccd7773
integration_basis: origin/main c92f4c0c3 (PR base object eb3a2e9ce; behind-only +32, merge-tree clean, mergeStateStatus CLEAN; no restack)
claim_boundary: LSP-local finding diagnostic Range start on the saved probe expression (Closes #4602). Analyzer columns, SARIF, BOM/non-UTF-8 decode (#4597 / #4582–#4583), and producer-owned start_byte origins (#4464) remain out of scope.
changed_surfaces_and_semantic_owners_inspected:
- crates/ripr/src/lsp/position.rs (encoding_unit_offset, expression_span_range_on_saved_line, first-non-whitespace / unread fallbacks)
- crates/ripr/src/lsp/diagnostics.rs (saved_line_for_finding + diagnostic_range_for_finding)
- crates/ripr/src/lsp/tests.rs (production-path diagnostic_for_finding + hover matcher)
- crates/ripr/src/lsp/hover.rs diagnostic_covers_position / position_in_range (consumer, not rewritten)
- seam/gap line_span_range and SARIF (untouched; origin/main has no expression_span_range_on_saved_line)
blocking_findings: none
non_blocking_suggestions:
- First substring match is the specified LSP-local heuristic; repeated identical expressions stay #4464.
- Per-finding read_to_string is fail-closed; a file cache is not required for this claim.
refuted_or_stale_findings:
- Gemini quota comment is missing provider review, not a source finding.
- CodeRabbit skipped-by-policy (manual OSS trigger), not a clean review and not a required check.
proof_and_ci_observed:
- Local (prior pass, same SHA): cargo test lsp::position + diagnostic_for_finding_ 37 passed; cargo check -p ripr clean; cargo xtask precommit pass; cargo xtask check-fast pass on 3 rust files
- Hosted exact-head a0118496d: Ripr Rust Small Result success 03:10:15Z (required); Rust gates success 03:10:10Z; ub-review success 03:06:03Z; rust-feature / pr-plan / cargo-deny / dependency-review / GitGuardian success; no in-progress or failed checks
- Review threads: none unresolved
- Claim-identity: no equivalent on origin/main; open #4688 is the only #4602 closer; #4597 remains a separate BOM/non-UTF-8 claim
proof_or_review_missing: Gemini review quota (missing provider); CodeRabbit skipped-by-policy. Author COMMENT on this SHA is the permitted alternative.
affected_currentness_dimensions: exact-head CI/receipts and integration basis refreshed; production/test/oracle/public-claim unchanged since a0118496d.
residual_assumptions_and_non_claims:
- Hover is correct because it matches diagnostic.range; not a separate hover renderer rewrite.
- Expressions that already include leading indent stay at character 0 by verbatim find.
- Non-UTF-8 saved files fall back to column-1; #4597 is not absorbed.
- Analyzer column / SARIF / producer start_byte are unchanged.
disposition: REVIEW_READY
No blocking source, oracle, or required-CI defect on this published head. Merge convergence may proceed by ordinary protected squash.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a0118496df
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| fn saved_line_for_finding(root: &Path, finding: &Finding) -> Option<String> { | ||
| let path = absolute_finding_path(root, finding); | ||
| let contents = std::fs::read_to_string(path).ok()?; |
There was a problem hiding this comment.
Cache source text before constructing diagnostics
When one refresh emits many canonical findings from the same source file, finding_diagnostics_by_uri_with_profile calls this helper once per finding, so every diagnostic synchronously rereads and UTF-8-decodes the entire file and rescans from its beginning to the target line. Refresh cost therefore becomes findings × file size, which can noticeably delay the interactive did-save path for dense or large changed files. Cache the file contents or indexed lines once per path for the diagnostic batch, and add a read-count or dense-file regression test alongside the focused LSP tests.
AGENTS.md reference: AGENTS.md:L253-L255
Useful? React with 👍 / 👎.
| let contents = std::fs::read_to_string(path).ok()?; | ||
| let line_index = finding.probe.location.line.saturating_sub(1); | ||
| contents.lines().nth(line_index).map(str::to_owned) |
There was a problem hiding this comment.
🔴 Repeated source reads delay finding refreshes
For multiple findings in one file, saved_line_for_finding reads and decodes the entire file per diagnostic. The per-finding loop in finding_diagnostics_by_uri_with_profile multiplies refresh I/O by the finding count.
Learn more
A finding diagnostic is produced for each canonical finding in finding_diagnostics_by_uri_with_profile. Every call to saved_line_for_finding reads and decodes its full source file, then walks from the first line to the target line. Findings in the same file repeat the same I/O and scanning during each interactive refresh. The delivery budget runs after diagnostics are built, so it cannot prevent this work.
Example: A 2 MB source file with 300 distinct findings causes 300 full-file reads and decodes during one refresh instead of one.
Recommended fix: Cache source text or indexed lines by path for the duration of finding_diagnostics_by_uri_with_profile, pass that cache into range construction, and validate with a many-findings/single-file refresh test.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let prefix_bytes = match saved_line.find(expression) { | ||
| Some(offset) if !expression.is_empty() => offset, | ||
| _ => first_non_whitespace_byte(saved_line), | ||
| }; | ||
| encoding_unit_offset(&saved_line[..prefix_bytes], encoding) |
There was a problem hiding this comment.
🟡 Expression matches inside strings hide actual code
When a line contains expression inside a string before the changed code, start_character_on_saved_line selects the string. The diagnostic and hover then target unrelated text rather than the changed expression.
Learn more
The LSP diagnostic range chooses the first substring occurrence without knowing whether it is executable code. On a single source line, a string or comment can contain the same bytes as the actual changed expression. Since diagnostic_covers_position uses that diagnostic range, hovering the real expression then misses the finding.
Example: For saved line let label = "x >= 5"; return x >= 5; and probe expression x >= 5, the range starts inside label rather than on the return expression.
Recommended fix: Use the parser-produced start byte when available, or restrict matching to code regions and disambiguate repeated occurrences using a producer-owned source position. Add a diagnostic-plus-hover test with an earlier literal occurrence.
Was this helpful? React with 👍 or 👎 to provide feedback.
| fn first_non_whitespace_byte(line: &str) -> usize { | ||
| line.char_indices() | ||
| .find(|(_, ch)| !ch.is_whitespace()) | ||
| .map_or(line.len(), |(idx, _)| idx) | ||
| } |
There was a problem hiding this comment.
🟡 Whitespace-only deletion loses accessible hover
For a removed-only finding projected onto a whitespace-only saved line, first_non_whitespace_byte places its range after the line. Hover on the visible line cannot reach the finding.
Learn more
build_probe projects removed-only probes onto new-side lines. Their old expression is often absent from the saved file. A whitespace-only new-side line therefore reaches this fallback, whose offset is the line length. The range begins after the last visible character, so diagnostic_covers_position cannot match a cursor on the line.
Example: A removed-only probe with expression old_call(); projected onto line " " gets range 4..15. Hovering any of its four spaces returns no finding, whereas its previous range began at zero.
Recommended fix: For absent expressions on whitespace-only lines, retain the analyzer-column fallback or anchor at character zero. Test removed-only diagnostics and hover against whitespace-only projected lines.
Was this helpful? React with 👍 or 👎 to provide feedback.
| #[test] | ||
| fn diagnostic_for_finding_underlines_indented_expression_not_leading_whitespace() | ||
| -> Result<(), String> { | ||
| let root = unique_lsp_test_root("finding-range-verbatim")?; | ||
| let finding = | ||
| finding_on_saved_pricing_line(root.path(), INDENTED_UNICODE_PROBE_LINE, "x >= 5")?; | ||
| let diagnostic = diagnostic_for_finding(root.path(), &finding); | ||
| assert_finding_range(&diagnostic, 36, 42)?; |
Summary
Finding diagnostics on indented lines started at character 0 (
column - 1from analyzer column 1), so the squiggle covered leading whitespace and hover on the changed expression showed nothing. The LSP now reads the saved line, locates the probe expression, and measures that prefix in the negotiated encoding.Swarm / Source Boundary
This PR targets
EffortlessMetrics/ripr-swarm, the normal development trunk fortrusted same-repo
riprwork. Confirm the change belongs here:dependency, or repo-ops development for
ripr-swarmSource-of-truth Links
Proposal: n/a
Spec: n/a (LSP-local range conversion; module docs in
crates/ripr/src/lsp/position.rs)ADR: n/a
Plan item: n/a
Governing issue or accepted claim: Closes #4602
Acceptance delta (one sentence): On an indented saved line, the published finding diagnostic (and therefore hover) covers the probe expression, not the leading whitespace.
Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication):
cursor/lsp-diagnostic-range-indent-3cefStack parent or prerequisite PR (if any): none
Proposed replacement of PR (if any; not yet accepted): none
Open Claude PR #4597 owns BOM/non-UTF-8 source decode; this PR does not absorb that work. Open #4464 owns producer-owned parser
start_byteorigins; this PR is the LSP-local first-match heuristic only.Scope
LSP finding diagnostic
Rangeconstruction. Hover is not separately rewritten; it already matchesdiagnostic.range.Scope Classification
This PR is scoped by:
Production delta:
diagnostic_range_for_findingreads the saved line and callsexpression_span_range_on_saved_line.column - 1span.source_range.columnin diagnostic data stays the analyzer column.Evidence/support delta:
diagnostic_for_findingtests including the LSP finding diagnostics start at character 0, so the squiggle covers indentation and hover on the changed expression shows nothing #4602 Unicode/tab fixture, hover coverage, CRLF, and fail-closed unread/non-UTF-8/past-EOF cases.Single acceptance criterion:
\tlet s = "日本語🎉"; let _ = s; return x >= 5;with expressionx >= 5and analyzer column 1, UTF-16 range is 36..42 (not 0..6), and hover at character 36 matches while character 0 does not.Non-goals:
start_byte/ SARIF changes (fix(lsp): preserve producer-owned source origins for current Rust expression diagnostics #4464).ripr check(exit 2) #4582–--diff FILEand--diff -refuse a diff containing non-UTF-8 bytes that the git route accepts #4584).line_span_range(still 0..120).Support-tier Impact
Claim/proof notes:
Policy Impact
Proof
Result, failures, or skipped proof:
a0118496d.a0118496d: requiredRipr Rust Small Resultsuccess 03:10:15Z; Rust gates success 03:10:10Z; ub-review success 03:06:03Z; no failed or in-progress checks.Claim Boundary
May claim: LSP finding diagnostics (and hover that matches them) start on the saved probe expression when the saved line can be read.
Must not claim: analyzer columns are accurate; SARIF changed; producer-owned byte origins; runtime mutation results; that first-substring match is the parser node.
Rollback
Plain revert of this branch. No schema, cache, or golden generation bump.
Spec-Test-Code Traceability
crates/ripr/src/lsp/position.rsmodule docs (LSP finding diagnostics start at character 0, so the squiggle covers indentation and hover on the changed expression shows nothing #4602)lsp::position::tests::*saved_line*,lsp::tests::diagnostic_for_finding_underlines_indented_expression_not_leading_whitespace, hover/encoding/fallback siblingscrates/ripr/src/lsp/position.rs,crates/ripr/src/lsp/diagnostics.rsStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Gates
cargo fmt --check(via precommit / check-fast)cargo xtask precommitcargo xtask check-fast(clippy included)