nomad / crop

🌾 A pretty fast text rope
https://crates.io/crates/crop
MIT License
264 stars 13 forks source link

UTF-16 and UTF-32 offsets #7

Closed alicelogos closed 1 year ago

alicelogos commented 1 year ago

Thanks for your work!

I like crop's API and consider using crop in a LSP server, however in LSP offsets can be UTF-8, UTF-16 or UTF-32, and LSP servers must support UTF-16 offsets.

According to crop's README:

crop doesn't currently implement those APIs but adding them would be extremely easy. If you need those features in your application please open an issue describing your use case.

So I open this issue. Hoping you could add UTF-16 and UTF-32 offsets support.

noib3 commented 1 year ago

Thanks and sorry for the late response!

I'm open to adding some methods on Rope and RopeSlice that allow converting byte offsets to and from UTF-16 code unit offsets. UTF-32 is rarely used and not mandatory according to the LSP spec so I don't think I'll add that.

I've started working on this in https://github.com/noib3/crop/pull/8, I'll ping you when it'll be ready to be merged.

noib3 commented 1 year ago

8 has just been merged to main, adding support for converting between UTF-16 and byte offsets by enabling the utf16-metric feature flag.

I consider this completed but feel free to re-open if you think there's something missing.