gleam icon indicating copy to clipboard operation
gleam copied to clipboard

LSP: Support inlay hint feature

Open septemhill opened this issue 10 months ago • 13 comments

Hi gleam team,

I would like to suggest support inlay hint feature in vscode-gleam. This feature be supported in most of popular programming languages (e.g. Rust, Go, etc.) It would save us much time to hover over the variables/functions to check the types.

Looking forward to hearing from your reply !

septemhill avatar Sep 02 '23 00:09 septemhill

Hello! Where would we show these hints?

Moving this to the compiler repo as this is a language server feature rather than a vscode feature.

Edit: it won't let me move it from my phone, I'll have to do this later

lpil avatar Sep 02 '23 08:09 lpil

Hi @lpil, I'm not pretty sure which repo should I put this issue, thanks for ur help.

Currently, as I knew, there're two hints would be shown on VSCode

  1. Variable assignment
  2. Function call with argument
Screenshot 2023-09-02 at 5 23 06 PM

Here I used Go as example

The L154 and L155 are belong to first type (Variable assignment). We can see the variable user with type []*User and err with type error.

And L156, L157, L159 are belong to second type (Function call with argument). So we can also see parameters query and arg... with corresponding values "name = ? AND age < ?" and "Septem", 10 and so on.

septemhill avatar Sep 02 '23 09:09 septemhill

Are there any other places we might want them? The language server can put them anywhere.

Seeing as Gleam has labels does it still make sense to show the argument names in function calls?

We would also need to decide what hints we would have on by default. We don't want to introduce too much noise, and we want the code to be as readable even when not using the language server.

lpil avatar Sep 02 '23 10:09 lpil

I'd like this a lot IF it is something I can toggle globbally/per project via vscode settings.

inoas avatar Sep 02 '23 21:09 inoas

Are there any other places we might want them? The language server can put them anywhere.

This proposal is all I can think of now.

Seeing as Gleam has labels does it still make sense to show the argument names in function calls?

Agree. For this case, I think we could ignore. But another question is, if the function without named arguments how do we display, may be just show the type ?

I understand we don't want to make whole UI with too much noise. So here I provide Go inlay-hint features in LSP settings. There're many hints in Go and we could decide which hint would be enabled in a language rather than a project. But the config could be created under .vscode/setting in different projects.

Screenshot 2023-09-04 at 9 13 21 AM

Thanks.

septemhill avatar Sep 04 '23 01:09 septemhill

Fab! Ok so the next steps are to determine how to send these hints via the language server protocol, and to turn them on and off with the language server protocol, and to design some hints to support.

lpil avatar Sep 04 '23 09:09 lpil

Are there any other places we might want them? The language server can put them anywhere.

This proposal is all I can think of now.

Seeing as Gleam has labels does it still make sense to show the argument names in function calls?

Agree. For this case, I think we could ignore. But another question is, if the function without named arguments how do we display, may be just show the type ?

I understand we don't want to make whole UI with too much noise. So here I provide Go inlay-hint features in LSP settings. There're many hints in Go and we could decide which hint would be enabled in a language rather than a project. But the config could be created under .vscode/setting in different projects.

Screenshot 2023-09-04 at 9 13 21 AM

Thanks.

would we want the comments around it, i think the rust lsp skips those. just grey and some opacity, and maybe (not sure) you cannot select them ever with the cursor

inoas avatar Sep 04 '23 13:09 inoas

We don't have an inline comment syntax so we couldn't wrap them like Go does.

lpil avatar Sep 06 '23 09:09 lpil

I'm currently working on this https://github.com/jamesbirtles/gleam/tree/feat/inlay-hints along with some code actions to add in the types when clicked

CleanShot 2023-11-02 at 20 39 23@2x

https://github.com/gleam-lang/gleam/assets/3743418/e019bc91-2d5e-4db5-a8c9-d2a8fc467f3a

https://github.com/gleam-lang/gleam/assets/3743418/b8a83b38-18ab-449a-9f8b-969c5e2ebae7

Currently working for top level functions and constants, its a little trickier for things inside functions like calls and variable assignment as I don't think theres a generic visitor/walker(?) to get at all expressions without manually recursing through them

jamesbirtles avatar Nov 02 '23 21:11 jamesbirtles

Very exciting!

Let's start with the MVP feature-set and we can add more over time. That way it is easier to review and merge.

lpil avatar Nov 05 '23 12:11 lpil

Prior art https://github.com/gleam-lang/gleam/pull/2393

lpil avatar Apr 25 '24 10:04 lpil