Stream: t-compiler/rust-analyzer

Topic: LSP: Difference between Goto Definition and Goto Declaration


Viliam Vadocz (Apr 05 2021 at 16:59, on Zulip):

What is the difference between Goto Declaration and Goto Definition in the Language Server Protocol?
Goto Definition: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
Goto Declaration: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration

Should a language server implement both or only one?
(Sorry about cross-posting to #t-compiler/help, I didn't know where to ask.)

Viliam Vadocz (Apr 05 2021 at 17:01, on Zulip):

After looking at the rust-analyzer source, it seems only Goto definition is implemented. Is Goto Declaration an older name kept for backwards compatibility?

Jeremy Kolb (Apr 05 2021 at 17:01, on Zulip):

It's really used in languages that need the distinction between declaration and well... definition. For instance in C++ you can have a variable declared somewhere (ex a header) and defined somewhere else (cpp)

Viliam Vadocz (Apr 05 2021 at 17:02, on Zulip):

Ok, that makes sense. Thanks.

Jeremy Kolb (Apr 05 2021 at 17:02, on Zulip):

We don't use it in rust-analyzer: https://github.com/rust-analyzer/rust-analyzer/blob/1ae20d2b894171f0b8368309da727cd365b95fc1/crates/rust-analyzer/src/caps.rs#L46

Jeremy Kolb (Apr 05 2021 at 17:03, on Zulip):

If you have questions about the LSP protocol itself the best place is: https://github.com/microsoft/language-server-protocol

Viliam Vadocz (Apr 05 2021 at 17:05, on Zulip):

That's helpful.
If I have questions about language server implementation is it ok if I ask here? I am using Rust for mine (+ similar dependencies), but it's for a different target language.

Jeremy Kolb (Apr 05 2021 at 17:08, on Zulip):

I can answer some questions

Jeremy Kolb (Apr 05 2021 at 17:09, on Zulip):

We use https://crates.io/crates/lsp_server and https://crates.io/crates/lsp_types. https://crates.io/crates/tower-lsp is also an implementation but I haven't played with it.

Florian Diebold (Apr 05 2021 at 17:25, on Zulip):

see also https://github.com/rust-analyzer/rust-analyzer/issues/2541

Jeremy Kolb (Apr 05 2021 at 17:33, on Zulip):

Good point! I forgot about that issue.

Last update: Jul 28 2021 at 03:45UTC