From 64112b0b61cd842f2186240374a89ae05a8d0bb9 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 16 Feb 2020 22:58:17 +0200 Subject: [PATCH] docs: update debugging.md with the freshest VSCode debugging information --- docs/dev/debugging.md | 61 ++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/docs/dev/debugging.md b/docs/dev/debugging.md index f868e6998f..5a942ba5de 100644 --- a/docs/dev/debugging.md +++ b/docs/dev/debugging.md @@ -1,34 +1,58 @@ # Debugging vs Code plugin and the Language Server -Install [LLDB](https://lldb.llvm.org/) and the [LLDB Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb). +## Prerequsities -Checkout rust rust-analyzer and open it in vscode. +- Install [LLDB](https://lldb.llvm.org/) and the [LLDB Extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) VSCode extensions. +- Open the root folder in VSCode. Here you can access the preconfigured debug setups. + + Debug options view + +- Install all TypeScript dependencies + ```bash + cd editors/code + npm i + ``` + +## Common knowledge + +* All debug configurations open new `[Extension Development Host]` VSCode instance +where **only** your `rust-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 globally installed `ra_lsp_server` binary. +- `Run Extension (Dev Server)` - runs extension with binary from your locally built `target/debug/ra_lsp_server`. + +TypeScript debugging is configured to watch your source edits and recompile. +To apply changes to already running debug process press Ctrl+Shift+P and run the following command in your `[Extension Development Host]` ``` -$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1 -$ cd rust-analyzer -$ code . +> Developer: Reload Window ``` +## Debug Rust LSP server + - To attach to the `lsp server` in linux you'll have to run: - `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope` + ``` + echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope + ``` - This enables ptrace on non forked processes + This enables ptrace on non-forked processes -- Ensure the dependencies for the extension are installed, run the `npm: install - editors/code` task in vscode. +- Enable debug symbols in `Cargo.toml`: + ```toml + [profile.dev] + debug = 2 + ``` -- Launch the `Debug Extension`, this will build the extension and the `lsp server`. +- Select `Run Extension (Dev Server)` to run your local built `target/debug/ra_lsp_server`. -- A new instance of vscode with `[Extension Development Host]` in the title. +- In the original VSCode window once again select `Attach To Server` debug configuration. - Don't worry about disabling `rls` all other extensions will be disabled but this one. - -- In the new vscode instance open a rust project, and navigate to a rust file - -- In the original vscode start an additional debug session (the three periods in the launch) and select `Debug Lsp Server`. - -- A list of running processes should appear select the `ra_lsp_server` from this repo. +- 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 the `on_task` function. @@ -36,7 +60,8 @@ $ code . ## Demo -![demonstration of debugging](https://user-images.githubusercontent.com/1711539/51384036-254fab80-1b2c-11e9-824d-95f9a6e9cf4f.gif) +- [Debugging TypeScript VScode extension](https://www.youtube.com/watch?v=T-hvpK6s4wM). +- [Debugging Rust LSP server](https://www.youtube.com/watch?v=EaNb5rg4E0M). ## Troubleshooting