Thicket thicket
cambridge
REPOS 4

Projects covers Forester, Merry, xdge and ocaml-crockford.

W37.2026 · 7–13 Sep / Issue

Semantic token ranges appear offset in editor

tangled · jonmsterling.com/ocaml-forester · did:plc:jjiv56ot7d6sgethto3jr3r5

This is a screenshot of Neovim. Look in the title line of the first subtree.

Image

Comments

did:plc:jjiv56ot7d6sgethto3jr3r5

If I replace the curly apostrophe with a straight one, the problem disappears. This is perhaps related to the difference between UTF-8 and UTF-16, but I'm not certain.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Biting the bullet on this, I confirmed it to have to do with UTF-16. I hope whatever solution I find can be used to also fix position encodings.


did:plc:jjiv56ot7d6sgethto3jr3r5

OK :) This is painful work, but it's going to have a huge impact for us. Godspeed!!!


did:plc:jjiv56ot7d6sgethto3jr3r5

P.S. I wonder if this issue may also be related to the on-again-off-again issues with completions.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Image

The completions don't care at all about character encodings as they work directly with the lexical token stream, so I doubt this has anything to do with it.

However, it seems that we are now compliant with UTF16-encoded positions!


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

https://tangled.org/jonmsterling.com/ocaml-forester/commit/50d8d9cf251eb8b7d2fb4cfa479b0e300d563267


did:plc:jjiv56ot7d6sgethto3jr3r5

Wow, that was so quick! Thank you so much for doing this.


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Turned out waaay simpler than I thought, since with the way Grace handles everything, we can just decode the length on a per-line basis


did:plc:jjiv56ot7d6sgethto3jr3r5

Re: completions, maybe I'm misremembering how this works, but surely the client is sending us some kind of offset that we use to figure out where in the token stream the cursor is?


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

You may be right, let me have a think


did:plc:4gj3ihsdh6fn3aqq5bdnw5w3

Yes, the commit should have had an effect on the completion behavior. It also makes sense that you said that the error resolved itself: the offsets would only have been wrong if there was a problematic character before the cursor on the same line.


did:plc:jjiv56ot7d6sgethto3jr3r5

OK, great! I'll keep an eye on that issue then, and close it if I can no longer reproduce it.