aboutsummaryrefslogtreecommitdiff
path: root/docs/dev/debugging.md
blob: 5a942ba5de38bbba6faf755f516efe3000b7a25d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Debugging vs Code plugin and the Language Server

## Prerequsities

- 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.

  <img height=150px src="https://user-images.githubusercontent.com/36276403/74611090-92ec5380-5101-11ea-8a41-598f51f3f3e3.png" alt="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 <kbd>Ctrl+Shift+P</kbd> and run the following command in your `[Extension Development Host]`

```
> 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
  ```

  This enables ptrace on non-forked processes

- Enable debug symbols in `Cargo.toml`:
  ```toml
    [profile.dev]
    debug = 2
  ```

- Select `Run Extension (Dev Server)` to run your local built `target/debug/ra_lsp_server`.

- In the original VSCode window once again select `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 the `on_task` function.

- Go back to the `[Extension Development Host]` instance and hover over a rust variable and your breakpoint should hit.

## Demo

- [Debugging TypeScript VScode extension](https://www.youtube.com/watch?v=T-hvpK6s4wM).
- [Debugging Rust LSP server](https://www.youtube.com/watch?v=EaNb5rg4E0M).

## 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`.