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

Define: Go to definition, declaration, implementation, type definition #2541

Closed
kjeremy opened this issue Dec 12, 2019 · 4 comments · Fixed by #12402
Closed

Define: Go to definition, declaration, implementation, type definition #2541

kjeremy opened this issue Dec 12, 2019 · 4 comments · Fixed by #12402
Labels
S-actionable Someone could pick this issue up and work on it right now

Comments

@kjeremy
Copy link
Contributor

kjeremy commented Dec 12, 2019

The LSP (as of 3.15) supports go to definition, declaration, implementation and type definition.

What do these mean in a rust world? Does supporting all of the above features make sense? We should define what each of the above operations mean and figure out what makes sense for rust.

Context: #2538 (comment)

@flodiebold
Copy link
Member

Thinking out loud...

For a file module:

  • definition goes to the file
  • declaration goes to the mod foo;
  • implementation N/A or same as definition?
  • type definition N/A

For a variable, const or static:

  • definition goes to the let/const/static foo
  • declaration same
  • implementation N/A
  • type definition goes to the ... definition of the type

For a trait method (call or implementation):

  • declaration goes to the fn foo in the trait
  • definition same? or same as implementation?
  • implementation goes to the fn foo in the impl if we know it
  • type definition N/A

For an inherent method (call):

  • definition/declaration/implementation go to the fn foo in the impl
  • type definition N/A

@matklad
Copy link
Member

matklad commented Dec 12, 2019

definition same? or same as implementation?

Same as implementation. You can unambigiously go from that to declaration, but not in the opposite direction.

IntelliJ Rust recently implemented a crazily neat feature where, when to you go to def for a method, it remembers the substitution, and subsequent goto defs take these substitutions into account.

Ie, goto def 92.to_string() brings you to blanket impl of ToString for display, and second goto there brings you to imp Display for i32 ⚡ ⚡ ⚡

@tigregalis
Copy link

I'm using VS Code. I'm not sure if this is the right issue to ask. I expected go to definition (F12) to go to the fn foo in the impl, but it goes to the fn foo in the trait. And go to implementation (Ctrl+F12) goes nowhere. I don't see go to declaration.

For a trait method (call or implementation):

  • declaration goes to the fn foo in the trait

  • definition same? or same as implementation?

  • implementation goes to the fn foo in the impl if we know it

  • type definition N/A

@flodiebold
Copy link
Member

We don't have a way to find the trait implementation yet. There's e.g. #4558 for this, and it's mostly why this issue is still open as well.

@lnicola lnicola added the S-actionable Someone could pick this issue up and work on it right now label Jan 27, 2021
@bors bors closed this as completed in 6c9fc4f May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants