Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't panic in leanPosToLspPos #3071

Merged
merged 5 commits into from
Dec 16, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
kim-em committed Dec 15, 2023
commit fe835ae9f9abbee66d4c28397deac8414d34cd28
15 changes: 7 additions & 8 deletions src/Lean/Data/Lsp/Utf16.lean
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ namespace Lean
namespace FileMap

private def colPos (text : FileMap) (line : Nat) : String.Pos :=
if h : line < text.positions.size then
text.positions.get ⟨line, h⟩
else if text.positions.isEmpty then
0
else
text.positions.back
if h : line < text.positions.size then
text.positions.get ⟨line, h⟩
else if text.positions.isEmpty then
0
else
text.positions.back

/-- Computes an UTF-8 offset into `text.source`
from an LSP-style 0-indexed (ln, col) position. -/
Expand All @@ -79,8 +79,7 @@ def lspPosToUtf8Pos (text : FileMap) (pos : Lsp.Position) : String.Pos :=

def leanPosToLspPos (text : FileMap) : Lean.Position → Lsp.Position
| ⟨line, col⟩ =>
let colPos := colPos text (line - 1)
⟨line - 1, text.source.codepointPosToUtf16PosFrom col colPos⟩
⟨line - 1, text.source.codepointPosToUtf16PosFrom col (colPos text (line - 1))⟩

def utf8PosToLspPos (text : FileMap) (pos : String.Pos) : Lsp.Position :=
text.leanPosToLspPos (text.toPosition pos)
Expand Down