X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,37 @@ function Get-ConciseViewPositionMessage {
$highlightLine = ''
if ($useTargetObject) {
$line = $_.TargetObject.LineText.Trim()

$offsetLength = 0
$offsetInLine = 0
$startColumn = 0
if (
([System.Collections.IDictionary]$_.TargetObject).Contains('StartColumn') -and
[System.Management.Automation.LanguagePrimitives]::TryConvertTo[int]($_.TargetObject.StartColumn, [ref]$startColumn) -and
$null -ne $startColumn -and
$startColumn -gt 0 -and
$startColumn -le $line.Length
) {
$endColumn = 0
if (-not (
([System.Collections.IDictionary]$_.TargetObject).Contains('EndColumn') -and
[System.Management.Automation.LanguagePrimitives]::TryConvertTo[int]($_.TargetObject.EndColumn, [ref]$endColumn) -and
$null -ne $endColumn -and
$endColumn -gt $startColumn -and
$endColumn -le ($line.Length + 1)
)) {
$endColumn = $line.Length + 1
}

# Input is expected to be 1-based index to match the extent positioning
# but we use 0-based indexing below.
$startColumn -= 1
$endColumn -= 1

$highlightLine = "$(" " * $startColumn)$("~" * ($endColumn - $startColumn))"
$offsetLength = $endColumn - $startColumn
$offsetInLine = $startColumn
}
Comment on lines 1192 to +1223
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The LineText is trimmed before validating and using StartColumn/EndColumn positions. If a caller provides LineText with leading or trailing whitespace and specifies column positions based on the original untrimmed text, the positions will be misaligned after trimming.

For example, if LineText is " abc def" (with 2 leading spaces) and StartColumn is 3 (pointing to 'a' in the original text), after trimming the line becomes "abc def" and position 3 would point to 'c' instead.

This should either be documented that LineText should not have leading/trailing whitespace when using StartColumn/EndColumn, or the code should skip trimming when column information is provided.

Copilot uses AI. Check for mistakes.
}
else {
$positionMessage = $myinv.PositionMessage.Split($newline)
Expand Down
Loading
Loading
X Tutup