Compare commits

...

5 Commits

Author SHA1 Message Date
Scott Morrison
35f183d56d better name 2023-12-16 12:34:01 +11:00
Scott Morrison
fe835ae9f9 cleanup 2023-12-15 15:05:36 +11:00
Scott Morrison
32463a3ea5 trigger toolchain 2023-12-15 10:58:01 +11:00
Scott Morrison
7c5108cf4b suggestion from review 2023-12-15 09:58:50 +11:00
Scott Morrison
8916b1cf5e don't panic 2023-12-14 13:54:05 +11:00

View File

@@ -62,21 +62,24 @@ end String
namespace Lean
namespace FileMap
private def lineStartPos (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
/-- Computes an UTF-8 offset into `text.source`
from an LSP-style 0-indexed (ln, col) position. -/
def lspPosToUtf8Pos (text : FileMap) (pos : Lsp.Position) : String.Pos :=
let colPos :=
if h : pos.line < text.positions.size then
text.positions.get pos.line, h
else if text.positions.isEmpty then
0
else
text.positions.back
let chr := text.source.utf16PosToCodepointPosFrom pos.character colPos
text.source.codepointPosToUtf8PosFrom colPos chr
let lineStartPos := lineStartPos text pos.line
let chr := text.source.utf16PosToCodepointPosFrom pos.character lineStartPos
text.source.codepointPosToUtf8PosFrom lineStartPos chr
def leanPosToLspPos (text : FileMap) : Lean.Position Lsp.Position
| ln, col => ln-1, text.source.codepointPosToUtf16PosFrom col (text.positions.get! $ ln - 1)
| line, col =>
line - 1, text.source.codepointPosToUtf16PosFrom col (lineStartPos text (line - 1))
def utf8PosToLspPos (text : FileMap) (pos : String.Pos) : Lsp.Position :=
text.leanPosToLspPos (text.toPosition pos)