Skip to content

Commit 6fbf012

Browse files
Jesper Schulz-WeddeCopilot
andcommitted
Widen single-line re-anchor window to recover larger mis-anchors
The model-reported anchor for a single-line suggestion can be off by more than 8 lines (e.g. PR #8933 VendorNL Confirm() was off by 10, label rename off by 9). Widen the search window to 40 lines either side so the correct target within the same procedure is considered, while the 0.5 similarity floor and 0.1 ambiguity margin keep an unrelated look-alike from winning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 521c866 commit 6fbf012

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

tools/Code Review/scripts/Invoke-CopilotPRReview.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,17 +556,20 @@ function Resolve-SuggestionPlacement {
556556
# A one-line suggestion almost always *edits* a line, so it is NOT equal to
557557
# the line it replaces (e.g. inserting 'this.' for CodeCop AA0248). Exact
558558
# equality therefore fails for the common case and the model's reported
559-
# anchor is unreliable (it frequently points at a neighbouring comment or
560-
# blank line). We instead score every file line in a window around the
561-
# anchor by similarity to the suggested line and take the clear winner.
562-
# When no candidate is similar enough, or the best is ambiguous against the
563-
# runner-up, we return $null so the caller suppresses the ```suggestion```
564-
# block (posting a manual snippet) rather than corrupting the file by
565-
# trusting the wrong anchor.
559+
# anchor is unreliable: it frequently points at a neighbouring statement
560+
# inside the same procedure (observed off by 10+ lines), a comment, or a
561+
# blank line. We score the file lines in a window around the anchor by
562+
# similarity to the suggested line and take the clear winner. The window is
563+
# wide enough to recover a target elsewhere in the same procedure, while the
564+
# similarity floor, ambiguity margin, and proximity tie-break keep an
565+
# unrelated look-alike from being chosen. When no candidate is similar
566+
# enough, or the best is ambiguous against the runner-up, we return $null so
567+
# the caller suppresses the ```suggestion``` block (posting a manual
568+
# snippet) rather than corrupting the file by trusting the wrong anchor.
566569
if ($sCount -eq 1) {
567570
$minSimilarity = 0.5 # absolute confidence floor for a re-anchor
568571
$ambiguityMargin = 0.1 # winner must beat the runner-up by this much
569-
$window = 8
572+
$window = 40 # lines either side of the anchor to consider
570573

571574
$lo = [math]::Max(1, $AnchorLine - $window)
572575
$hi = [math]::Min($fileCount, $AnchorLine + $window)

0 commit comments

Comments
 (0)