sway
sway copied to clipboard
Adds a DAP server with support for debugging sway unit tests
Description
Related https://github.com/FuelLabs/sway-vscode-plugin/pull/166
Adds a DAP server as a new forc plugin, forc-debug
. This enables a UI debugging experience in IDEs such as VSCode.
For now, only debugging forc tests is supported. Users can:
- set breakpoints inside of forc tests
- step through the test, one VM instruction at a time, or continue to the next breakpoint
- debug through multiple tests sequentially
- see the VM register values in the IDE while debugging
- see the current VM opcode, its inputs, and/or immediate value when when the VM is stopped
Screenshots
https://github.com/FuelLabs/sway/assets/47993817/24e2016c-d96c-4ef6-931f-8a4ce4f1386b
https://github.com/FuelLabs/sway/assets/47993817/5f0fed49-b278-4074-a1a1-d37de00776f8
Local testing
- Install
forc-debug
- Copy this sample launch.json in the VSCode workspace with sway code to debug:
{
"version": "0.2.0",
"configurations": [
{
"type": "sway",
"request": "launch",
"name": "Debug Sway",
"program": "${file}"
}]
}
- Follow the steps for testing the VSCode extension
Limitations
- Breakpoints only work inside of the project/workspace being debugged
- Stack trace support is limited
- Not every line has source maps. Once debugging, "verified" breakpoints will show red and "unverified" (no source maps) will be greyed out.
- Watch/repl expressions are not yet supported
- Step into/out of is not supported
- If you click "step over" many times in rapid succession, the server takes a while to catch up.
Closes https://github.com/FuelLabs/sway/issues/5394
Checklist
- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book).
- [ ] I have added tests that prove my fix is effective or that my feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
Breaking*
orNew Feature
labels where relevant. - [ ] I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
- [ ] I have requested a review from the relevant team or maintainers.
Nice one, looking really good. Just a couple of nits.
Have just been playing around locally with this and it feels really great!
Just had a thought, would it be possible to print a message to the debug console saying "this feature is currently not supported" or similar if the user clicks on either step into or step out?
Benchmark for 89b3e02
Click to view benchmark
Test | Base | PR | % |
---|---|---|---|
code_action | 5.2±0.11ms | 5.2±0.19ms | 0.00% |
code_lens | 295.3±7.85ns | 306.8±9.43ns | +3.89% |
compile | 3.1±0.04s | 3.1±0.03s | 0.00% |
completion | 4.8±0.05ms | 4.9±0.27ms | +2.08% |
did_change_with_caching | 3.0±0.03s | 3.0±0.05s | 0.00% |
document_symbol | 1003.9±39.44µs | 956.7±19.92µs | -4.70% |
format | 89.7±1.04ms | 90.0±0.74ms | +0.33% |
goto_definition | 364.1±9.39µs | 360.8±7.27µs | -0.91% |
highlight | 9.0±0.14ms | 8.9±0.20ms | -1.11% |
hover | 544.3±5.81µs | 537.7±7.16µs | -1.21% |
idents_at_position | 122.3±0.66µs | 122.2±1.67µs | -0.08% |
inlay_hints | 659.9±22.44µs | 650.6±19.39µs | -1.41% |
on_enter | 482.1±18.08ns | 498.6±18.23ns | +3.42% |
parent_decl_at_position | 3.6±0.09ms | 3.6±0.04ms | 0.00% |
prepare_rename | 358.1±10.54µs | 361.0±5.61µs | +0.81% |
rename | 9.6±0.17ms | 9.4±0.28ms | -2.08% |
semantic_tokens | 1062.1±24.90µs | 1031.2±20.57µs | -2.91% |
token_at_position | 358.3±4.78µs | 354.5±4.37µs | -1.06% |
tokens_at_position | 3.6±0.04ms | 3.6±0.06ms | 0.00% |
tokens_for_file | 417.4±2.53µs | 418.3±4.35µs | +0.22% |
traverse | 39.3±0.88ms | 38.7±0.84ms | -1.53% |
Benchmark for 15ffa7f
Click to view benchmark
Test | Base | PR | % |
---|---|---|---|
code_action | 5.1±0.14ms | 5.1±0.09ms | 0.00% |
code_lens | 286.7±7.31ns | 293.4±8.73ns | +2.34% |
compile | 2.9±0.03s | 3.1±0.13s | +6.90% |
completion | 4.7±0.04ms | 4.8±0.01ms | +2.13% |
did_change_with_caching | 2.8±0.02s | 2.8±0.02s | 0.00% |
document_symbol | 1030.8±47.76µs | 981.1±30.83µs | -4.82% |
format | 71.4±0.81ms | 72.2±1.00ms | +1.12% |
goto_definition | 353.7±5.95µs | 361.6±7.92µs | +2.23% |
highlight | 8.8±0.20ms | 8.7±0.02ms | -1.14% |
hover | 524.0±9.16µs | 535.8±6.76µs | +2.25% |
idents_at_position | 122.9±0.26µs | 121.3±0.71µs | -1.30% |
inlay_hints | 637.4±8.39µs | 658.8±21.46µs | +3.36% |
on_enter | 491.1±11.14ns | 478.1±9.51ns | -2.65% |
parent_decl_at_position | 3.6±0.04ms | 3.6±0.04ms | 0.00% |
prepare_rename | 348.5±6.25µs | 361.9±7.46µs | +3.85% |
rename | 9.1±0.15ms | 9.1±0.13ms | 0.00% |
semantic_tokens | 1020.7±10.38µs | 1015.5±15.85µs | -0.51% |
token_at_position | 350.5±3.57µs | 357.9±2.28µs | +2.11% |
tokens_at_position | 3.6±0.02ms | 3.6±0.06ms | 0.00% |
tokens_for_file | 408.4±4.67µs | 409.6±2.29µs | +0.29% |
traverse | 37.5±0.89ms | 37.2±0.78ms | -0.80% |
Benchmark for 25eb563
Click to view benchmark
Test | Base | PR | % |
---|---|---|---|
code_action | 5.2±0.01ms | 5.4±0.14ms | +3.85% |
code_lens | 286.0±4.84ns | 286.4±7.47ns | +0.14% |
compile | 2.9±0.02s | 3.0±0.03s | +3.45% |
completion | 4.7±0.11ms | 5.0±0.24ms | +6.38% |
did_change_with_caching | 2.8±0.02s | 2.9±0.03s | +3.57% |
document_symbol | 1032.5±48.70µs | 970.8±8.26µs | -5.98% |
format | 75.0±1.19ms | 75.7±0.57ms | +0.93% |
goto_definition | 359.7±6.09µs | 364.5±5.94µs | +1.33% |
highlight | 8.8±0.20ms | 9.0±0.23ms | +2.27% |
hover | 532.0±7.17µs | 543.7±10.61µs | +2.20% |
idents_at_position | 121.3±0.41µs | 122.4±0.44µs | +0.91% |
inlay_hints | 645.5±27.78µs | 658.3±21.86µs | +1.98% |
on_enter | 500.3±7.18ns | 492.3±8.43ns | -1.60% |
parent_decl_at_position | 3.7±0.05ms | 3.6±0.08ms | -2.70% |
prepare_rename | 370.0±7.78µs | 361.1±7.48µs | -2.41% |
rename | 9.1±0.02ms | 9.4±0.13ms | +3.30% |
semantic_tokens | 1014.9±10.38µs | 1056.2±11.85µs | +4.07% |
token_at_position | 365.7±2.45µs | 355.9±4.61µs | -2.68% |
tokens_at_position | 3.7±0.03ms | 3.6±0.05ms | -2.70% |
tokens_for_file | 492.3±5.01µs | 411.6±3.47µs | -16.39% |
traverse | 37.3±1.13ms | 37.0±0.91ms | -0.80% |
Great to see this one merged, awesome work :heart: