gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Use text edit API for more precise LSP autocompletions

Open VlkrS opened this issue 1 year ago • 5 comments

When testing autocomplete with helix (helix-editor.com), I get some odd behavior:

Entering

string.re doesn't give me an autocompletion but a live error message ``the module gleam/string does not have a re field.

When completing string.repeat, I get offered an autocompletion, which - when accepted, expands to string.string.repeat.

When not accepting, but deleting characters back to string.rep, I get an autocompletion offered for string.replace, string.repeat, ... (including string.is_empty, which doesn't look like a good match).

However the gist of it is that I need to first completely type a valid field in a module in order to make autocompletion yield anything on that line of code.

VlkrS avatar May 24 '23 09:05 VlkrS

This due to unfortunate ambiguity in the LSP specification. The manner in which autocompletions are inserted by the client is "open to interpretation". In future we will use the more complex autocompletion API in order to ensure no editors do this, but it has not yet been implemented.

lpil avatar May 24 '23 09:05 lpil

I understand that this explains why string.replace turns into string.string.replace when completed, correct? But that no autocompletion is found before a complete symbol is entered should not be affected by this, right?

VlkrS avatar May 24 '23 09:05 VlkrS

I think it's that this editor is using . as the input boundary. I was hoping they'd instead match the whole prefix, but alas it seems not to be the case.

lpil avatar May 24 '23 09:05 lpil

Still not sure if the missing completions are related to the input boundary. When I type

io.pri

in line 9, I see on the wire:

{"jsonrpc":"2.0","method":"textDocument/completion","params":{"position":{"character":8,"line":9},"textDocument":{"uri":"file:///<path_to_file>"}},"id":5}

and as a response I see: {"jsonrpc":"2.0","id":5,"result":null}

when I completely type

io.println

I see

{"jsonrpc":"2.0","method":"textDocument/completion","params":{"position":{"character":12,"line":9},"textDocument":{"uri":"file:///<path_to_file>"}},"id":2}

and as a response I see {"jsonrpc":"2.0","id":2,"result":[{"detail":"fn() -> fn(String) -> Nil","kind":3,"label":"main"},{"detail": ...

VlkrS avatar May 24 '23 18:05 VlkrS

Oh I see, I didn't realise you were reporting two problem. Could you open a second one with code examples for how the problem is triggered? Thank you.

lpil avatar May 24 '23 19:05 lpil