microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.57k stars 29.01k forks source link

[debug] DebugConfigurationProvider not invoked on debug session restart #212005

Closed connectdotz closed 4 months ago

connectdotz commented 5 months ago

Type: Bug

  1. Setup: Clone the vscode-mock-debug from GitHub. Although this bug also affects the vscode-jest extension, the vscode-mock-debug is used here for demonstration because it is easier to set up and reproduce.
  2. Breakpoint in Extension: Open the cloned repository in VS Code, navigate to src/activateMockDebug.ts, and place a breakpoint at MockConfigurationProvider.resolveDebugConfiguration.
  3. Start Debugging: Press F5 to start the extensionHost, which initiates the debugging session for the extension itself. This should open the "sampleWorkspace" with a readme.md file.
  4. Debug Session: Open the readme.md file and place a breakpoint in any line. Start a debug session that triggers this breakpoint. (use the inline menu on the top of the editor, choose "Debug File".)
  5. Verify Extension Invocation: Upon debug session creation, the MockConfigurationProvider.resolveDebugConfiguration will be invoked and breakpoint will be hit. Let it continue.
  6. Session Restart: Next it should hit the readme.md breakpoint. Use the restart button in the debug toolbar to restart the session.
  7. Observation of Bug: Observe that upon restarting, MockConfigurationProvider.resolveDebugConfiguration is not invoked, which deviates from the expected behavior where configuration methods should be invoked for every session initiation, including restarts.

This has caused an issue jest-community/vscode-jest#1148, where the "unresolved" debug config was used upon debug session restart.

VS Code version: Code 1.89.0 (b58957e67ee1e712cebf466b995adf4c5307b2bd, 2024-05-01T02:10:10.196Z) OS version: Darwin x64 23.4.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz (12 x 3200)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|5, 5, 5| |Memory (System)|32.00GB (4.01GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Extensions (47) Extension|Author (truncated)|Version ---|---|--- better-comments|aar|3.0.2 vscode-color-pick|ada|0.6.2 vscode-markdownlint|Dav|0.55.0 vscode-eslint|dba|2.4.4 xml|Dot|2.5.1 gitlens|eam|14.9.1 prettier-vscode|esb|10.4.0 vscode-commands|fab|2.0.2 flow-for-vscode|flo|2.2.1 shell-format|fox|7.2.5 html-preview-vscode|geo|0.2.5 copilot|Git|1.186.856 copilot-chat|Git|0.15.0 vscode-pull-request-github|Git|0.88.0 go|gol|0.41.4 svg|joc|1.5.3 vscode-insertdatestring|jsy|2.3.1 vscode-colorize|kam|0.11.1 json-lines-viewer|leh|0.0.4 git-graph|mhu|1.30.0 vscode-docker|ms-|1.29.1 debugpy|ms-|2024.6.0 isort|ms-|2023.10.1 python|ms-|2024.6.0 vscode-pylance|ms-|2024.4.1 jupyter|ms-|2024.4.0 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.17 vscode-jupyter-cell-tags|ms-|0.1.9 vscode-jupyter-slideshow|ms-|0.1.6 remote-containers|ms-|0.362.0 wordcount|ms-|0.1.0 vscode-jest|Ort|6.2.5 material-icon-theme|PKi|5.1.0 java|red|1.30.0 markdown-preview-enhanced|shd|0.8.13 code-spell-checker|str|3.0.1 pdf|tom|1.2.2 intellicode-api-usage-examples|Vis|0.2.8 vscodeintellicode|Vis|1.3.1 vscode-java-debug|vsc|0.57.0 vscode-java-dependency|vsc|0.23.6 vscode-java-pack|vsc|0.26.0 vscode-java-test|vsc|0.41.1 vscode-maven|vsc|0.44.0 vim|vsc|1.27.2 markdown-all-in-one|yzh|3.6.2 (1 theme extensions excluded)
roblourens commented 5 months ago

It looks like maybe you register your own debug adapter type, and resolve to the 'node' type, is that what's happening in this scenario?

roblourens commented 5 months ago

What should happen in mock-debug is that the config provider isn't called for each restart, but it restarts reusing the original resolved config.

But also, restarting actually works differently in the node debug adapter.

Possible that this is related to https://github.com/microsoft/vscode/issues/212823 too but that might be a different scenario

roblourens commented 5 months ago

I pushed a fix for a related bug here https://github.com/microsoft/vscode/pull/212991 and I think it might fix your issue, but I'm not sure.

Our Insiders releases are paused for the Build conference, so this won't be in an Insiders until around next Thursday. You can try then, or build the vscode repo if you want to try it earlier.

connectdotz commented 5 months ago

@roblourens, thanks for looking into this. While we wait for the insider build, let me answer your question below:

It looks like maybe you register your own debug adapter type, and resolve to the 'node' type, is that what's happening in this scenario?

We registered the provider twice, once for 'node', and the other for our own type:

      // this provides the opportunity to inject test names into the DebugConfiguration
      vscode.debug.registerDebugConfigurationProvider('node', this.debugConfigurationProvider),

      // this provides the snippets generation
      vscode.debug.registerDebugConfigurationProvider(
        'vscode-jest-tests',
        this.debugConfigurationProvider
      ),

On the restart, the debug session seems to only look for the providers by debug type "pwa-node" instead of "node". Is that an expected behavior?

roblourens commented 5 months ago

Ah, that could be related to what I fixed too.

vscodenpa commented 4 months ago

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!