microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 279 forks source link

Breakpoints in Razor class libraries imported in a Blazor WASM project will not bind #1363

Open EricCornelson opened 2 years ago

EricCornelson commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

In a Blazor WebAssembly project, if a user creates a Razor class library with some javascript interop, they will be unable to hit breakpoints in those javascript files that are not in the main project (hitting breakpoints on javascript in the main Blazor WASM project works fine).

It seems that when the javascript is coming from a path other than the project root, the debug adapter can't map the script URL back to the file on disk, and so it's not finding the scriptId to set with (the setBreakpointByURL request with the file:/// url doesn't work at all in either case).

It's possible we could try to make BlazorSourcePathResolver smarter, and only send file URLs for razor/c# files, and the typical URL for javascript (which does work).

To Reproduce

  1. Create a Blazor WebAssembly project
  2. Add a Razor class library project to the solution
  3. Add some JavaScript interop to the razor class library
  4. try to set a breakpoint in the JavaScript, and launch the Blazor app

(also, See https://github.com/aspnet/AspNetCore-ManualTests/issues/284)

Log File

successful (javascript is in the main Blazor WASM project): visualstudio-js-debugger.txt

unsuccessful (javascript is in a razor class lib): visualstudio-js-debugger_bad.txt

connor4312 commented 1 year ago

I repro'd this following the instructions on https://github.com/aspnet/AspNetCore-ManualTests/issues/284.

In that case, a script that happened to be in libs/RazorLib1/wwwroot/exampleJsInterop.js was served directly in http://localhost:5200/_content/RazorLib1/exampleJsInterop.js. There's nothing for the debugger to go on to locate the source file -- the URL is the same regardless of where the original file is from.

The most natural fix for this would be for the Blazor dev server to add a sourceURL, like //# sourceURL=file:///original/source/path/libs/RazorLib1/wwwroot/exampleJsInterop.js. This would let the debugger deterministically and easily map back to the right location without requiring js-debug changes. The downside is the breakpoint would not get set before the script is parsed, so early on breakpoints could be missed, but this could be tweaked. Thoughts?