RedPRL / asai

🩺 A library for compiler diagnostics
https://ocaml.org/p/asai
Apache License 2.0
35 stars 2 forks source link

📐 More comprehensive support for computing with ranges #176

Closed kentookura closed 3 weeks ago

kentookura commented 4 weeks ago

I find myself doing a lot computations with positions and ranges, of both LSP and Asai type. I am creating this issue to discuss the design of a more comprehensive set of functions to deal with this.

One API mismatch is that an LSP position is just:

type t = {
    character : int;
    line : int;
}

but an Asai position carries more information:

type position = {
    source: source;
    offset: int;
    start_of_line: int;
    line_num: int;
}

so a prospective pos_of_lsp_pos would require another argument, probably of type TextDocumentItem.t

Ultimately, I would in particular like to have functions that allow me to compute if a position is inside of a range, both Asai and LSP positions/ranges.

favonia commented 4 weeks ago

@kentookura Thanks. Let me think about it. The LSP part is underdeveloped and I appreciate your efforts in trying it out.

May I confirm that your LSP server has insisted on using bytes in UTF-8? If so, it seems the easiest way is to convert all asai positions to LSP positions before comparison, not the other way around. Is there truly a need to convert LSP positions to asai positions?

kentookura commented 4 weeks ago

@favonia Regarding the encoding, I have not made any changes from the original Asai LSP.

Indeed, at the moment it does not seem to be necessary to convert in both directions...

favonia commented 3 weeks ago

@kentookura Should we close this issue for now, then?