Skip to content

Show actual type parameters of generic functions and methods #3588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Veetaha opened this issue Mar 13, 2020 · 2 comments
Open

Show actual type parameters of generic functions and methods #3588

Veetaha opened this issue Mar 13, 2020 · 2 comments
Labels
A-hover hover feature C-enhancement Category: enhancement E-hard E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Mar 13, 2020

The feature is to put actual type parameters (i.e. resolved, inferred ones) in onHover function signature hint. This lets you visually debug the type inference and find out what the formal parameters ended up to be for the specific function call expression.

I really miss the feature of inspecting the resolved types of a generic function from TypeScript where it looks the following way:
image

I'd like to bother implementing this if you don't mind.
@flodiebold @matklad I'd be grateful if you give any pointers to the code!

@flodiebold
Copy link
Member

flodiebold commented Mar 14, 2020

For simple function calls, you can already get these from the inference result; the callee itself will have a type like Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(.. the fn id..), parameters: .. the type parameters .. }). You can see this in the tests as well:
https://github.com/rust-analyzer/rust-analyzer/blob/bf0c3ec67e0f2bc232924923ef3bd55aa3bd0cbd/crates/ra_hir_ty/src/tests/simple.rs#L1553

For method calls, we don't record the parameters yet. Here's the point where we've got the method type, so we should record it in the InferenceResult. The parameters will often contain variables, which will need to be resolved after inference (before you do this, you'll probably see lots of _ in the substs). This happens here for other types recorded during inference.

As for actually printing the function definition with parameters, there's two approaches: Trying to print the whole definition from HIR, or adapting the current way and trying to substitute type parameters in it syntactically. Both have their complications. Printing full definitions from HIR will require a bunch of code we don't have yet (basically we only have printing of types). For substituting parameters syntactically, we have some code, but it's not general enough yet.

@Veetaha
Copy link
Contributor Author

Veetaha commented Mar 15, 2020

Thanks for the pointers! I'll look into this, but it may take some time!

@lnicola lnicola added S-actionable Someone could pick this issue up and work on it right now E-hard E-has-instructions Issue has some instructions and pointers to code to get started labels Jan 22, 2021
@Veykril Veykril added the A-hover hover feature label Jan 25, 2023
@Veykril Veykril added the C-enhancement Category: enhancement label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-hover hover feature C-enhancement Category: enhancement E-hard E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants