It seems I found the solution!
To make this work will need a tasks in VScode to run the App and a launch option to start a browser (supported by VScode) on debug mode to be able to bind breakpoints for JavaScript.
First add a task to your tasks.json in VScode like this one.
What's important here to make this task run in background is the problemMatcher
configuration property.
It just needs some configuration present to allow the background execution. Under the problemMarcher
property make sure you have defined pattern
with regexp
inside and the background
with all its properties defined.
It is important to for the beginsPattern
and the endsPattern
to match the output of your swift run command, meaning if you have changed the product name from App to something else you will need to adjust the messages.
{
"version": "2.0.0",
"tasks": [
...,
{
"label": "swift: Run Debug App in background",
"detail": "Runs the executable in Background",
"type": "swift",
"args": ["run"],
"env": {},
"disableTaskQueue": true,
"dontTriggerTestDiscovery": true,
"showBuildStatus": "swiftStatus",
"group": "none",
"isBackground": true,
"problemMatcher": {
"pattern": {
"regexp": "."
},
"background": {
"activeOnStart": true,
"beginsPattern": "^\\s*swift build --product App.*",
"endsPattern": "^\\s*Build of product 'App' complete!.*"
}
}
}
]
}
Now let's configure a launch option to be able to debug JavaScript in our vapor project.
{
"version": "2.0.0",
"configurations": [
...,
{
"name": "Debug in Chrome",
"request": "launch",
"type": "chrome",
"runtimeArgs": [
"--remote-debugging-port=9222",
"--user-data-dir=${workspaceFolder:coachingApp}/build/debug/remote-debug-profile"
],
"url": "http://localhost:8080/",
"webRoot": "${workspaceFolder:coachingApp}/Public",
"preLaunchTask": "swift: Run Debug App in background",
"sourceMapPathOverrides": {
"http://localhost:8080/": "${workspaceFolder:coachingApp}/Public"
}
}
]
}
Now everything is ready! let's hit debug and check it out.
First add a breakpoint to any JavaScript file you want to debug.
Then go to your debug panel and make sure you have selected the launch option "Debug in Chrome", and run clicking on the play button.
And now see your breakpoints being hit!