Skip to content

Conversation

@basvandriel
Copy link
Contributor

Problem

When debugging Rust tests and pressing the restart button (⟳), the debugger would use stale binaries instead of recompiling with the latest code changes.

Previously, this worked using onDidTerminateDebugSession, but this event no longer fires on restaart in recent VS Code versions.

Solution

Uses DebugAdapterTracker.onWillReceiveMessage to intercept the Debug Adapter Protocol (DAP) restart command and trigger recompilation.

Implementation

  • Intercepts restart: Listens for DAP restart command via DebugAdapterTracker
  • Stops session: Terminates the debug session to clear cached binaries/symbols
  • Recompiles: Runs cargo build --all-targets with 2-minute timeout
  • Shows progress: Displays notification during compilation
  • Fresh start: Launches a new debug session with the updated binary
  • Error handling: Catches and displays compilation errors

The stop + recompile + fresh start approach is necessary because debug adapters cache binaries and symbols. A simple restart would continue using stale data.

Changes

  • ✅ Updated debug.ts with DebugAdapterTracker implementation
  • ✅ Added user documentation in README.md
  • ✅ Created unit tests in debug_restart.test.ts
  • ✅ Added integration test documentation in debug_restart_integration.md
  • ✅ Removed unused activeDebugSessionIds variable
  • ✅ Added comprehensive code comments explaining DAP behavior

Testing

  • Unit tests verify restart command handling
  • Integration test documentation covers manual testing procedures
  • Tested with CodeLLDB debug adapter

User Experience

When users modify code during a debug session and press restart:

  1. Debug session stops
  2. "Recompiling before debug restart" notification appears
  3. Code recompiles in background
  4. Fresh debug session starts with new binary
  5. Latest code changes are reflected in the debugger

When users press the restart button while debugging Rust tests, the debugger
now automatically recompiles the code to ensure the latest changes are used.

Previously, onDidTerminateDebugSession was used to detect restarts, but this
event no longer fires on restart in recent VS Code versions. The solution now
uses DebugAdapterTracker.onWillReceiveMessage to intercept the DAP 'restart'
command.

Key implementation details:
- Intercepts 'restart' command via Debug Adapter Protocol tracker
- Stops the debug session to clear cached binaries/symbols
- Runs 'cargo build --all-targets' with progress notification
- Starts a fresh debug session with the new binary
- Includes error handling and timeout protection (2 minutes)

The stop + recompile + fresh start approach is required because debug
adapters cache binaries and symbols, so a simple restart would use stale data.

Changes:
- Updated debug.ts with DebugAdapterTracker implementation
- Added user documentation in README.md
- Added unit tests in debug_restart.test.ts
- Added integration test documentation in debug_restart_integration.md
- Removed unused activeDebugSessionIds variable
- Added comprehensive code comments explaining DAP behavior
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2025
@ChayimFriedman2
Copy link
Contributor

Is this PR AI-generated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants