rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Type hint via codelens for pipeline operator

Open amiralies opened this issue 3 years ago • 14 comments

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)

amiralies avatar May 24 '21 22:05 amiralies

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

cristianoc avatar May 25 '21 00:05 cristianoc

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

amiralies avatar May 25 '21 09:05 amiralies

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 avatar May 25 '21 10:05 cristianoc

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.

cristianoc avatar May 25 '21 10:05 cristianoc

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.

amiralies avatar May 25 '21 12:05 amiralies

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?

alarbada avatar Sep 06 '21 11:09 alarbada

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.

amiralies avatar Sep 06 '21 13:09 amiralies

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.

Mng12345 avatar Dec 15 '21 01:12 Mng12345

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

rust_analyzer and tsserver already implemented type hint.

aspeddro avatar May 23 '22 12:05 aspeddro

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.

zth avatar Jun 02 '22 16:06 zth

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.

  • Only let bindings has type hint.

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

aspeddro avatar Jun 10 '22 05:06 aspeddro

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 avatar Jun 10 '22 06:06 zth

@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.

zth avatar Jun 10 '22 08:06 zth

@zth ok.

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

moving forward.

image

aspeddro avatar Jun 10 '22 09:06 aspeddro