Skip to content

Commit 85bee7d

Browse files
authored
Fix LSP line/pos at start of a line (#866)
1 parent 9c70e77 commit 85bee7d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/ls/converters.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,11 @@ func (c *Converters) PositionToLineAndCharacter(scriptInfo ScriptInfo, position
239239

240240
lineMap := scriptInfo.LineMap()
241241

242-
line, _ := slices.BinarySearch(lineMap.LineStarts, position)
243-
line = max(0, line-1)
242+
line, isLineStart := slices.BinarySearch(lineMap.LineStarts, position)
243+
if !isLineStart {
244+
line--
245+
}
246+
line = max(0, line)
244247

245248
// The current line ranges from lineMap.LineStarts[line] (or 0) to lineMap.LineStarts[line+1] (or len(text)).
246249

0 commit comments

Comments
 (0)