rust-lang / rust-lang/rust-analyzer
Show definition information when hovering variable
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Currently, when hovering (textDocument/hover) a variable, only the type is shown. I think it could be very useful if this would also show where the variable came from and if it is mut. For example:
fn foo(mut a: u32) {
let b = 2i32;
a;
b;
}
Hovering a currently shows:
`u32`
but could show
`mut u32`
-------------
function parameter: `fn foo(mut a: u32)`
and for b:
`i32`
--------------
variable: `let b = 2i32;`
This is inspired by clangd, which does this:
void foo(unsigned int a) {
int b = 2;
a;
b;
}
### param `a`
---
Type: `unsigned int`
---
// In foo
unsigned int a
### variable `b`
---
Type: `int`
Value = `2`
---
// In foo
int b = 2
<- it is even inferring the value, which is pretty cool
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the textDocument/hover entry point and compare the current variable hover output with the examples in the issue. Determine how declaration information and mutability are represented, then verify that hovering variables shows their type, mutability, and declaration context without losing the existing type display.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100