Connecting to rust-analyzer’s running LSP server for “Go to Definition” from a VS Code extension #2482
Unanswered
splo
asked this question in
Extension Development QnA
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I’m the author of the Bevy Inspector VS Code extension, and after some interaction, I get a Rust struct string like
my::module::StructName
. What I want to do is programmatically direct the user to the file/line/column location of the definition—essentially, a “Go to Definition” command.I couldn’t find a command like “go to definition” or “find file/line/column of a type” in the rust-analyzer registered commands.
So far, my approach has been to create a virtual VS Code document with the input struct and maybe wrap it with some Rust code.
Then use the generic "Go to Definition" VS Code command, it doesn't work since it doesn't have the right context.
I tried to connect to the running rust-analyzer server via the Language Server Protocol (LSP) to make a
textDocument/definition
request, which should return the location of the type definition.The problem is that the VS Code rust-analyzer extension manages (starts and stops) the rust-analyzer server instance. I want to connect to the already running server, not start a new one nor ask the user to maintain an external one.
Is this possible? Which transport would the connection use (IPC, socket, etc.)?
Are there other approaches I should consider?
Beta Was this translation helpful? Give feedback.
All reactions