lsp icon indicating copy to clipboard operation
lsp copied to clipboard

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

Open Bodigrim opened this issue 3 years ago • 2 comments

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

Bodigrim avatar Apr 25 '22 19:04 Bodigrim

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 :)

michaelpj avatar Apr 26 '22 08:04 michaelpj

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

Bodigrim avatar Apr 26 '22 20:04 Bodigrim

Done now, thanks @Bodigrim and @soulomoon !

michaelpj avatar Jan 03 '24 17:01 michaelpj