Skip to main content

Module resolver

Module resolver 

Source
Expand description

Re-anchoring resolver for durable review threads.

A persisted ReviewAnchor stores a drift-robust location (path + side + line + content hash + a few context lines). The diff is re-scanned on every overlay open, so the anchor must be re-resolved to a fresh positional index into the new FileHunks. resolve_anchor reports whether the line is still in place, moved, or could not be placed at all.

Relocation requires one unambiguous match: the line, plus at least one recorded neighbour agreeing within CONTEXT_RADIUS on each side the candidate has neighbours. Anything less is left where it was and marked outdated, because a comment silently attached to the wrong code costs far more than one the reviewer has to go looking for.

A distance bound does not make that safer. Bounding how far a match may be found still leaves several candidates inside the bound, and choosing among them by proximity is exactly the guess uniqueness refuses to make.

Re-exports§

use std::collections::HashSet; 🔒
use forge_primitives::review::ReviewAnchor; 🔒
use forge_primitives::review::ReviewSide; 🔒
use forge_primitives::review::is_doc_scope; 🔒
use super::content::FileContent; 🔒
use super::hunks::DiffLine; 🔒
use super::hunks::FileHunks; 🔒
use super::hunks::Hunk; 🔒

Enums§

AnchorPlacement
One anchor’s landing in the terms a view draws it: no positional indices into one scan’s arrays, just the line the anchor sits on now and, when it could not be placed, the resolver’s own reason.
AnchorResolution
Where a re-resolved anchor landed against a fresh diff scan. Indices address files[file_idx].hunks[hunk_idx].lines[line_idx].
OutdatedReason
Why an anchor did not relocate. Attaching a comment to the wrong code costs more than leaving it behind, so anything short of one certain match lands here rather than being guessed at.

Constants§

CONTEXT_RADIUS
Lines captured on each side of an anchored line for fuzzy re-anchor disambiguation.

Functions§

anchor_hash
The hash to persist for a newly captured anchor. Whitespace-normalised so a cargo fmt reflow reads as the same line.
capture_context
Capture up to radius lines on each side of line_idx within hunk (excluding the line itself) as fuzzy-match context.
content_hash
content_hash_bytes over a diff line’s text.
content_hash_bytes
FNV-1a hash of raw bytes: what both a line’s text and a whole document go through, so one implementation pins both.
neighbourhood_agrees 🔒
Whether the code around line_idx still looks like where the comment was left. Each side the candidate has neighbours on must carry one of the anchor’s recorded lines within CONTEXT_RADIUS, in any order. A line on its own matches far too easily - a closing brace, a short call - so a neighbour has to agree. One implementation over any line-addressable slice, so the hunk resolver and the seat-tree one cannot drift.
neighbourhood_matches 🔒
normalise_ws 🔒
Collapse every run of whitespace to one space and trim the ends.
place_anchor_in_content
resolve_anchor_in_content, narrowed to what a view draws.
place_anchor_in_lines
One seat-tree anchor placed against a file’s whole current lines - the files page’s resolution. The scope’s numbering IS the file’s own (the seat’s tree is where the comment was written), so unlike a diff scope whose numbering may belong to another base, the recorded line is trusted: in place when it still carries the anchor’s text, otherwise re-found by content plus neighbours, and Gone / Ambiguous as the diff resolver reports them.
place_anchor_in_lines_with
The whole-file placement with the diff resolver’s trust rule: with trust_line_number the recorded line is evidence too, because the file handed in is numbered the way the anchor was written; otherwise the match is earned by content and neighbours alone.
place_document_anchor
A document anchor placed against the document’s whole current lines: the thread’s FIRST captured line is the key, looked for by content.
resolve_anchor
Re-resolve anchor against a fresh files scan. trust_line_number says whether files is numbered the same way the anchor was recorded in. Only then does the recorded line carry information; from another scope’s diff that number addresses whatever happens to sit there, so the match has to be earned by content and neighbours like any other.
resolve_anchor_in_content
Re-resolve anchor against the socket’s bounded content read, whose files carry hunks but not the overlay scan’s own shape. Same resolution as resolve_anchor, one implementation.
resolve_in 🔒
side_line 🔒
text_matches 🔒
Whether text is the line anchor was placed on. Anchors captured before normalisation hold the raw hash, so both forms are accepted; such an anchor keeps its old exact-match behaviour until it is rewritten.