gleam icon indicating copy to clipboard operation
gleam copied to clipboard

LSP: show labelled arguments

Open ameknite opened this issue 1 year ago • 4 comments

Instead of only showing the types Screenshot 2024-03-07 at 19 18 47

show also labelled arguments like in the docs Screenshot 2024-03-07 at 19 19 56

without that you don't know if a function can be used with labels or no, you will need to go to the docs to learn that.

ameknite avatar Mar 08 '24 01:03 ameknite

Great suggestion! Thank you

lpil avatar Mar 08 '24 10:03 lpil

Hello! I've been really interested in improving the language server for gleam. I was exploring the code in order to implement this, but I have a question that might be due to my lack of context.

As far as I have explored, the hover information for function declarations is done by collecting the type_ of the arguments, but the label information is contained within arg.names when the arg is a NamedLabelled.

After collected, they are formatted to be pretty-printed (see here), which takes a Type. in which the variants Var and Named have no field for a Optional label, at least this was the direction I was going. But by adding a new field to some Type variants, many places would require updates, and that didn't seem like a good solution to me.

So I wanted to ask which direction did you expect this to go, or if this is something that you personally haven't checked deeply, I'm open to discuss how this could be implemented.

I'll be looking into other areas of the LSP to improve in the meantime, thanks for your time

wllfaria avatar Mar 18 '24 14:03 wllfaria

Labels are not part of the type system, and to add them would be a major breaking change and make the language much more difficult to use, so that's not an option. The LSP needs to take this information from the typed AST itself.

lpil avatar Mar 18 '24 14:03 lpil

Folks, I did some work on the tagged PR. Pleaase feel free to make suggestions there.

manuraj17 avatar Mar 19 '24 21:03 manuraj17