rescript-lang / rescript-vscode

Official VSCode plugin for ReScript
MIT License
327 stars 55 forks source link

Type hint via codelens for pipeline operator #251

Open amiralies opened 3 years ago

amiralies commented 3 years ago

fsharp / ionide has this feature image

maybe we can have similar feature (note that // at end of line are not comments they are virtual texts)

cristianoc commented 3 years ago

Is that while you type? Or just like code lenses it stays there?

amiralies commented 3 years ago

It stays, You can give it a try on gitpod with https://github.com/ionide/playground

cristianoc commented 3 years ago

Thanks. Looking at it, at least for me, it raises more questions than anything else. Do you really need those long pipes, to justify showing types on every step.

cristianoc commented 3 years ago

And if you do, how much added value do you get, in particular in terms of removing resources for building some other features and prioritise this one instead.

amiralies commented 3 years ago

It's quite useful imo. i find myself adding intermediate variables in pipelines when reading code to actually see what is happening.

About priority, I think it's not a high priority feature. I'm exploring features from other extensions/language-server to see how can we improve experience of rescript extension i'm adding my ideas here to achieve this in long term. For now I think stablizing current features is more important.

alarbada commented 3 years ago

Unfortunately with the current rescript pipe formatting this enhancement is impossible:

let add = (x, y) => x + y
3
->add(3)
->add(2)
->add(4)
->Js.log

Gets formatted into:

let add = (x, y) => x + y
3->add(3)->add(2)->add(4)->Js.log

However, maybe codelens could be implemented for let declarations, like the vscode-ocaml-platform plugin does: image

(Sorry for the bad quality, image gotten from here)

I don't know how difficult is this to implement, it looks easier to me than @amiralies suggestion, and it is quite helpful aswell.

What do you guys think?

amiralies commented 3 years ago

There's an issue on syntax repo about smart printing pipelines.

speaking of lens fot let bindings , I also think that's an improvement we can work on but for me hover is enough for let bindings but hovering on pipelines do not give enough information.

Mng12345 commented 2 years ago

The pipe operator should get tips from ide, but only the first pipe get tips, the second and others get nothing. this make us very tired when coding with some complex library for finding the function of type.

aspeddro commented 2 years ago

This feature is specified in LSP version 3.17. See textDocument/inlayHint Request.

rust_analyzer and tsserver already implemented type hint.

zth commented 2 years ago

This might be a good issue for a new contributor to experiment with. We have all we need in the analysis bin I think, just need to put the pieces together.

However, we need to think about whether we can provide a good enough experience given that we don't have continuous type information without saving (and successfully compiling). No way around experimenting with it and seeing how it works in practice, imo.

Please ping me if you'd be interested in taking a stab at this, and we can discuss the details. This work would mainly be in OCaml.

aspeddro commented 2 years ago

Hey @zth, I'm playing with ocaml and I did some tests.

The behavior is not responsive on save. I need to save twice. I don't know why this happens. When I save once and run it through the CLI the type returned is correct.

dune exec rescript-editor-analysis inlayHint ~/Desktop/learning-rescript/src/Demo.res 0 0

0 and 0 is a range for full lines.

https://user-images.githubusercontent.com/16160544/172999324-7f1a007c-e1af-475e-8db2-a7573ef6468a.mp4

zth commented 2 years ago

Very cool!! Great work! 😄

I think we can leverage the "inlay hint refresh" LSP request here: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_inlayHint_refresh

We already have a mechanism in the server listening to when compilation finishes. Maybe you could try hooking into that, and dispatch an inlay hint refresh request there as compilation is done?

zth commented 2 years ago

@aspeddro let me know if you need help with that btw, I'd be happy to fix that. If so, open a PR with your changes and I can edit it there.

aspeddro commented 2 years ago

@zth ok.

I'm fixing vscode, I had to update dependencies so everything was breaking.

moving forward.

image