Co-Authored-By: Laurențiu Nicola <lnicola@users.noreply.github.com>
3.1 KiB
Debugging vs Code plugin and the Language Server
Prerequsities
-
Install LLDB and the LLDB Extension VSCode extensions.
-
Open the root folder in VSCode. Here you can access the preconfigured debug setups.
-
Install all TypeScript dependencies
cd editors/code npm install
Common knowledge
- All debug configurations open new
[Extension Development Host]
VSCode instance where only yourrust-analyzer
extension is enabled. - To activate the extension you need to open any Rust project folder in
[Extension Development Host]
.
Debug TypeScript VSCode extension
Run Extension
- runs the extension with the globally installedra_lsp_server
binary.Run Extension (Dev Server)
- runs extension with the locally built LSP server (target/debug/ra_lsp_server
).
TypeScript debugging is configured to watch your source edits and recompile.
To apply changes to an already running debug process press Ctrl+Shift+P and run the following command in your [Extension Development Host]
> Developer: Reload Window
Debug Rust LSP server
-
When attaching a debugger to an already running
rust-analyzer
server on Linux you might need to enableptrace
for unrelated processes by running:echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
-
By default, the LSP server is built without debug information. To enable it, you'll need to change
Cargo.toml
:[profile.dev] debug = 2
-
Select
Run Extension (Dev Server)
to run your locally builttarget/debug/ra_lsp_server
. -
In the original VSCode window once again select the
Attach To Server
debug configuration. -
A list of running processes should appear. Select the
ra_lsp_server
from this repo. -
Navigate to
crates/ra_lsp_server/src/main_loop.rs
and add a breakpoint to theon_task
function. -
Go back to the
[Extension Development Host]
instance and hover over a Rust variable and your breakpoint should hit.
Demo
Troubleshooting
Can't find the ra_lsp_server
process
It could be a case of just jumping the gun.
The ra_lsp_server
is only started once the onLanguage:rust
activation.
Make sure you open a rust file in the [Extension Development Host]
and try again.
Can't connect to ra_lsp_server
Make sure you have run echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
.
By default this should reset back to 1 everytime you log in.
Breakpoints are never being hit
Check your version of lldb
if it's version 6 and lower use the classic
adapter type.
It's lldb.adapterType
in settings file.
If you're running lldb
version 7 change the lldb adapter type to bundled
or native
.