Skip to content

Commit

Permalink
fix: line offset off by one when at the last line (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl committed Feb 11, 2023
1 parent 05f1dc4 commit 0db9a5f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ export class LspDocument implements TextDocument {
}

getLineEnd(line: number): lsp.Position {
const nextLineOffset = this.getLineOffset(line + 1);
return this.positionAt(nextLineOffset - 1);
const nextLine = line + 1;
const nextLineOffset = this.getLineOffset(nextLine);
// If next line doesn't exist then the offset is at the line end already.
return this.positionAt(nextLine < this.document.lineCount ? nextLineOffset - 1 : nextLineOffset);
}

getLineOffset(line: number): number {
Expand Down

0 comments on commit 0db9a5f

Please sign in to comment.