haskell / lsp

Haskell library for the Microsoft Language Server Protocol
364 stars 90 forks source link

Migrate VFS to Data.Text.Utf16.Rope.Mixed #423

Closed Bodigrim closed 7 months ago

Bodigrim commented 2 years ago

I've added a new flavour of Rope, which offers simultaneous indexing by Unicode code points and by UTF-16 code units without conversions. @michaelpj could you please give it a try? If it works satisfactory, I'll release it as text-rope-0.2.

https://github.com/Bodigrim/text-rope/tree/1f721c1936cbfb1ea4a742f12754047afdcff3a8

michaelpj commented 2 years ago

I'll give it a go.

I haven't yet had the time to really start using this stuff in HLS, so I don't really have any idea whether the current implementation is a significant performance problem. My suspicion is that it will turn out to be fine, since we're only paying costs linear in line length, but really we would have to try it. So perhaps it's not worth expending too much effort on optimizing this for now? I won't say no to a better implementation, though :)

Bodigrim commented 2 years ago

It should simplify code a lot, e. g.,

codePointPositionToPosition :: VirtualFile -> CodePointPosition -> J.Position
codePointPositionToPosition vFile (CodePointPosition cpl cpc) =
  J.Position (fromIntegral cul) (fromIntegral cuc)
  where
    text = _file_text vFile
    (prefix, _) = Rope.charSplitAtPosition (Char.Position (fromIntegral cpl) (fromIntegral cpc)) text
    Utf16.Position cul cuc = Rope.utf16LengthAsPosition prefix
michaelpj commented 8 months ago

Done now, thanks @Bodigrim and @soulomoon !