Skip to content

fix(lsp): start finding diagnostics on the saved expression, not column 0 - #4688

Merged
EffortlessSteven merged 2 commits into
mainfrom
cursor/lsp-diagnostic-range-indent-3cef
Sep 29, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
cursor/lsp-diagnostic-range-indent-3cef

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Finding diagnostics on indented lines started at character 0 (column - 1 from 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 for
trusted same-repo ripr work. Confirm the change belongs here:

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge,
    dependency, or repo-ops development for ripr-swarm

Source-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-3cef
Stack 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_byte origins; this PR is the LSP-local first-match heuristic only.

Scope

LSP finding diagnostic Range construction. Hover is not separately rewritten; it already matches diagnostic.range.

Scope Classification

This PR is scoped by:

  • One production behavior

Production delta:

  • diagnostic_range_for_finding reads the saved line and calls expression_span_range_on_saved_line.
  • Verbatim expression → start is negotiated-encoding width of the prefix.
  • Expression empty or not on the line → first non-whitespace character.
  • Unreadable file, non-UTF-8 file, or line past EOF → old column - 1 span.
  • source_range.column in diagnostic data stays the analyzer column.

Evidence/support delta:

Single acceptance criterion:

  • For saved line \tlet s = "日本語🎉"; let _ = s; return x >= 5; with expression x >= 5 and 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:

Support-tier Impact

  • none

Claim/proof notes:

  • Editor finding underlines/hover get a more useful range. No support-tier promotion.

Policy Impact

  • none

Proof

cargo test -p ripr --lib -- lsp::position lsp::tests::diagnostic_for_finding_ -- --test-threads=1
# 37 passed on a0118496d
cargo check -p ripr
# clean
cargo xtask precommit
# pass (target/ripr/reports/precommit.md)
cargo xtask check-fast
# pass; 3 files vs origin/main; clippy ran; fixture-contracts skipped

Result, failures, or skipped proof:

  • Local shift-left passed on a0118496d.
  • Hosted exact-head a0118496d: required Ripr Rust Small Result success 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

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • New non-Rust programming files are allowlisted with owner, surface, and reason.
  • New generated, dependency, process-spawn, or network surfaces are allowlisted with owner and reason.
  • Errors are reported with actionable context.
  • Public JSON/schema changes are documented.

Gates

  • cargo fmt --check (via precommit / check-fast)
  • cargo xtask precommit
  • cargo xtask check-fast (clippy included)
Open in Web Open in Cursor 

…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>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 34 minutes.

Check out review usage here.

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: Advanced

Run ID: 8fc23eea-07d2-4b16-8bdd-9cd2f9f22323

📥 Commits

Reviewing files that changed from the base of the PR and between c92f4c0 and a011849.

📒 Files selected for processing (3)
  • crates/ripr/src/lsp/diagnostics.rs
  • crates/ripr/src/lsp/position.rs
  • crates/ripr/src/lsp/tests.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.

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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review September 29, 2026 05:01
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T05:04:17.905762Z a011849 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@EffortlessSteven
EffortlessSteven merged commit 006eaf8 into main Sep 29, 2026
28 of 29 checks passed
@EffortlessSteven
EffortlessSteven deleted the cursor/lsp-diagnostic-range-indent-3cef branch September 29, 2026 05:02

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 4 potential issues.

Devin Review

Comment on lines +2302 to +2304
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)

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.

🔴 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +134 to +138
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)

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.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +141 to +145
fn first_non_whitespace_byte(line: &str) -> usize {
line.char_indices()
.find(|(_, ch)| !ch.is_whitespace())
.map_or(line.len(), |(idx, _)| idx)
}

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.

🟡 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.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +7008 to +7015
#[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)?;

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.

🔍 New range behavior lacks spec mapping

The new range tests have no accompanying spec entry or spec-test-code mapping. The repository review checklist requests both for behavior changes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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.

LSP finding diagnostics start at character 0, so the squiggle covers indentation and hover on the changed expression shows nothing

2 participants