Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Can VS Code support CLion-like type-hint? #374

Open
crlf0710 opened this issue Jul 18, 2018 · 12 comments
Open

Can VS Code support CLion-like type-hint? #374

crlf0710 opened this issue Jul 18, 2018 · 12 comments
Labels
enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension

Comments

@crlf0710
Copy link
Member

CLion can display a "span" prompting the auto deduced type/argument name/etc. I wonder if this is possible in VS Code too? (Doesn't have to be exactly the same.)

@phiresky
Copy link

Do you mean like this?
image

@nrc
Copy link
Member

nrc commented Jul 19, 2018

Woah, how did you do that?

@phiresky
Copy link

My actual goal was to do parameter hints like IntelliJ (which can be done heuristically e.g. only when there are >3 params or when multiple parameters have the same type). I could not find a way to get that information out of the compiler / from rls-analysis (would maybe need to walk the AST to find all function call tokens?).

The protocol does not support this by default, there is an open issue for VScode here: microsoft/vscode#16221, so I used a custom notification sent from DocumentSymbols which has the most relevant information and is called on every document change for me.

See these two patches: rls-vscode, rls.

@nrc
Copy link
Member

nrc commented Jul 22, 2018

@phiresky Nice!

TODO: how would you send a notification from a RequestAction asynchronously (without blocking?)

Why does it need to be a blocking request? We usually only use these for lifecycle requests.

I don't think the notifcation needs to be sent async - we're not waiting for a reply or anything, so sending a reply is fast.

@phiresky
Copy link

Why does it need to be a blocking request?

The only reason I changed it to a BlockingRequestAction is because I couldn't find a way to get a reference to the Output instance (to call output.notify) from the ActionContext given to the RequestAction.

I didn't really mean async.. just meant without making the Symbols RequestAction a BlockingRequestAction. I'm not a Rust expert as you might have noticed :)

I'm also not sure if this is even the right place to put that (and who actually calls DocumentSymbols and why)

@nrc
Copy link
Member

nrc commented Jul 24, 2018

I think the right approach is to include that data in the response rather than sending a separate notification. Not sure if there are fields you can use already to do that, but if not, you can always add custom fields to the protocol messages.

Xanewok pushed a commit to Xanewok/rls-vscode that referenced this issue Mar 27, 2019
@Xanewok Xanewok added enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension labels Apr 7, 2019
@Kreyren
Copy link

Kreyren commented Feb 7, 2020

What is the status on this?

@DCjanus
Copy link

DCjanus commented Feb 7, 2020

@Kreyren It seems done.

@Kreyren
Copy link

Kreyren commented Feb 7, 2020

@DCjanus can't confirm on my end, is there any specific configuration for this?

@DCjanus
Copy link

DCjanus commented Feb 7, 2020

oh, I just made a silly mistake, I'm using rust-analyzer and I thout we are talking about it.

(I subscribed this issue long time ago, when notification came, I thout it's from rust-analyzer)

@Kreyren
Copy link

Kreyren commented Feb 7, 2020

@DCjanus Can rust-analyzer do this?

@p-avital
Copy link

p-avital commented Feb 7, 2020

I wrote a PR (#587) for this a while ago. It's not perfect, so I understand why they wouldn't want to merge it, but you can always use my fork if you want. I don't really update it much though, so you may want to keep your own fork if you want.

But yes, rust-analyzer has implemented this feature since then. While bugs in chalk cause type inference to fail in some cases, it still works pretty well, feel free to try it out, although the install process is a bit more complicated (at least it was last I checked).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension
Projects
None yet
Development

No branches or pull requests

7 participants