Closed Bodigrim closed 7 months 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 :)
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
Done now, thanks @Bodigrim and @soulomoon !
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 astext-rope-0.2
.https://github.com/Bodigrim/text-rope/tree/1f721c1936cbfb1ea4a742f12754047afdcff3a8