Completions defined in `editor.autocomplete` don't work on type aliases
I have a module BeltMapX with utility functions for working with Belt.Map.t.
I tried to set up autocomplete for pipe completion in rescript.json like so:
"editor": {
"autocomplete": {
"Belt.Map.t": ["BeltMapX"],
}
}
This didn't work so I did some debugging in analysis/src/CompletionBackEnd.ml, and it turned out that mainTypeId is actually Belt_Map.t.
https://github.com/rescript-lang/rescript/blob/7b4bc420cd052e492aea6b607df8f7513210b422/analysis/src/CompletionBackEnd.ml#L1068-L1077
Updating my rescript.json config to use the unaliased type, as below, worked.
"editor": {
"autocomplete": {
"Belt_Map.t": ["BeltMapX"],
}
}
Would it be possible to make the completions backend handle type aliases so that "Belt.Map.t": ["BeltMapX"] works?
Hmm, it's certainly possible, but I wonder if it's clear enough. How would you like it to work for it to be clear/usable enough?
Preferably, the type alias would be transparently converted to the type it points to. But I would also be fine with the compiler emitting a warning like Invalid editor.autocomplete value: Belt.Map.t is an alias for type Belt_Map.t and then having to manually update rescript.json with the correct value.
Maybe an alternative way of fixing this could be having the LSP provide type alias information. It would be nice if when I hover over e.g. a Belt.Map.t value in VS Code, in addition to seeing type Belt.Map.t<'key, 'value, 'identity>, I would see something like Alias for type Belt_Map.t and therefore know to use that instead.
This would be particularly helpful for something like Dom.element, where I had to follow the chain of type element = element_like = node_like = eventTarget_like to figure out the correct editor.autocomplete value.