rust-lang / rls

Repository for the Rust Language Server (aka RLS)
Other
3.51k stars 257 forks source link

Go to type definition on `self` #1381

Open vorner opened 5 years ago

vorner commented 5 years ago

Hello

Let's say I have a code like this:

struct X {
  some_stuff: usize,
}

// Bunch of other code in here

impl X {
  fn whatever(&self) {
    // ...
  }
}

I'd expect that when I go to the self parameter and do a go to definition, it would jump at the struct X at the top (this is what happens if I go to a parameter type).

Does it make sense, or is it just me expecting such behaviour?

For the record, I'm using rls from a recent nightly.

Thank you

jeffvandyke commented 5 years ago

Just spitballing ideas here: This would make sense inside impl X blocks, and perhaps impl OtherTrait for X, but not other areas where self would be valid, say when implementing functions for certain kinds of generic traits. That might be ok.

Another possible behavior would be to jump to the top of the impl block, but that would require another jump to a type.

Maybe where it jumps could depend on if self has a single unambiguous location, which would work for impl X { ... }, impl OtherTrait for X { ... } or even for impl OtherTrait for MyTrait { ... }, where MyTrait has an definite location. It seems like it could improve the editor experience, as long as there aren't other use-cases for having different behavior.

vorner commented 5 years ago

Another possible behavior would be to jump to the top of the impl block, but that would require another jump to a type.

That would probably also be fine, two jumps are OK. I just want a fast way to get to the definition and scrolling is not that great 😇

Xanewok commented 5 years ago

This should be fixed with Go to Type Definition request (we have the type info already and we can goto-def on them so it's a matter of implementation work)