Skip to content
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

Feature: show values of constants #8497

Closed
lf- opened this issue Apr 13, 2021 · 5 comments · Fixed by #10933
Closed

Feature: show values of constants #8497

lf- opened this issue Apr 13, 2021 · 5 comments · Fixed by #10933
Labels
A-ty type system / type inference / traits / method resolution E-medium fun A technically challenging issue with high impact S-actionable Someone could pick this issue up and work on it right now

Comments

@lf-
Copy link
Contributor

lf- commented Apr 13, 2021

I would find it really cool and useful if RA could tell me the values of numeric constants. I don't need a super fancy evaluation, even just an MVP that handles math operators would be absolutely rad.

The thing I would love to use this for is for double checking the hex value of bit hacks I've done to generate the right value, e.g. const TOP: usize = !0 & !(!0 >> 1);. Currently I either have to tab out of my editor to stuff it into another rust project or the playground, or just hope I got it right.

@flodiebold
Copy link
Member

We also kind of need this to handle at least array sizes, if not full const generics.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution E-medium fun A technically challenging issue with high impact S-actionable Someone could pick this issue up and work on it right now labels Apr 13, 2021
@lf-
Copy link
Contributor Author

lf- commented May 11, 2021

We also kind of need this to handle at least array sizes, if not full const generics.

array sizes: #8799, in a limited way ;)

@firasuke
Copy link

firasuke commented Jun 5, 2021

We also kind of need this to handle at least array sizes, if not full const generics.

array sizes: #8799, in a limited way ;)

How close is rust-analyzer to showing values of constants (similar to what Idea does)?

Thanks in advance!

@lf-
Copy link
Contributor Author

lf- commented Jun 5, 2021

We also kind of need this to handle at least array sizes, if not full const generics.

array sizes: #8799, in a limited way ;)

How close is rust-analyzer to showing values of constants (similar to what Idea does)?

Thanks in advance!

We currently parse numeric literals for the purposes of array sizes. Adding a basic expression evaluator is probably not very hard with the infrastructure we have now. I'm not sure the exact code paths to hook it up to display in the IDE but I doubt it would be super hard either. My guess is that implementing some form of constant value evaluation is O(1 day) of work.

@firasuke
Copy link

firasuke commented Jun 5, 2021

We also kind of need this to handle at least array sizes, if not full const generics.

array sizes: #8799, in a limited way ;)

How close is rust-analyzer to showing values of constants (similar to what Idea does)?
Thanks in advance!

We currently parse numeric literals for the purposes of array sizes. Adding a basic expression evaluator is probably not very hard with the infrastructure we have now. I'm not sure the exact code paths to hook it up to display in the IDE but I doubt it would be super hard either. My guess is that implementing some form of constant value evaluation is O(1 day) of work.

Nice! Thanks for your time and effort!

bors bot added a commit that referenced this issue Dec 23, 2021
10933: show values of constants in hover r=flodiebold a=HKalbasi

Fix #8497
cc #8655


Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
@bors bors bot closed this as completed in 7b7a1ed Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution E-medium fun A technically challenging issue with high impact S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants