gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.26k stars 715 forks source link

LSP: Support inlay hint feature #2319

Open septemhill opened 12 months ago

septemhill commented 12 months ago

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 !

lpil commented 12 months ago

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

septemhill commented 12 months ago

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.

lpil commented 12 months ago

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.

inoas commented 12 months ago

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

septemhill commented 12 months ago

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.

lpil commented 12 months ago

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.

inoas commented 12 months ago

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

lpil commented 11 months ago

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

jamesbirtles commented 10 months ago

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

lpil commented 9 months ago

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 commented 4 months ago

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

GearsDatapacks commented 2 months ago

Also another thing inlay hints could be used for is inferred types for arguments and return-types, since those might not be obvious in certain cases

lpil commented 2 months ago

For sure!!

codemonkey76 commented 1 month ago

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

CleanShot.2023-11-02.at.20.59.20.mp4 CleanShot.2023-11-02.at.21.44.31.mp4 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

I get a panic when using your feat/inlay-hints: /home/shane/dev/rust/gleam/compiler-core/src/language_server/server.rs:565 Unable to parse configuration: invalid type: null, expected struct Configuration