oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.22k stars 2.77k forks source link

[VSCode] Debugger does not start in launch mode #14241

Open elemental-mind opened 1 month ago

elemental-mind commented 1 month ago

What version of Bun is running?

1.1.30-canary.71+af82a446d, VSCode Extension Version v0.0.15

What platform is your computer?

Microsoft Windows NT 10.0.19045.0 x64

What steps can reproduce the bug?

  1. Fresh VSCode project with a single code-file
  2. Add the default launch.json config that the debugger suggests by default for bun:
    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "bun",
            "internalConsoleOptions": "neverOpen",
            "request": "launch",
            "name": "Debug File",
            "program": "${file}",
            "cwd": "${workspaceFolder}",
            "stopOnEntry": false,
            "watchMode": false
        },
        {
            "type": "bun",
            "internalConsoleOptions": "neverOpen",
            "request": "launch",
            "name": "Run File",
            "program": "${file}",
            "cwd": "${workspaceFolder}",
            "noDebug": true,
            "watchMode": false
        },
        {
            "type": "bun",
            "internalConsoleOptions": "neverOpen",
            "request": "attach",
            "name": "Attach Bun",
            "url": "ws://localhost:6499/",
            "stopOnEntry": false
        }
    ]
    }
  3. Run the debugger with the "Debug File" configuration in any code file in the project.

What is the expected behavior?

The debugger launches bun and attaches to it and stops at the first breakpoint set.

What do you see instead?

On the debug console I see the following output:

Failed to start debugger. Program could not be started.

image

Also, the extension host complains about an invalid debug adapter:

2024-09-29 19:16:10.456 [error] Error: Invalid debug adapter at c.p (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2012:95) at c.$acceptDAMessage (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2011:16481) at S (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1903:14635) at S.Q (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1903:14401) at S.M (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1903:13434) at S.L (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1903:12269) at u.value (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1903:10964) at o.B (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:93:732) at o.fire (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:93:949) at s.fire (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:123:15085) at K.onmessage (vscode-file://vscode-app/c:/Users/magnu/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/workbench/workbench.desktop.main.js:1919:8198)

Additional information

No response

elemental-mind commented 1 month ago

For anyone looking for a workaround to the problem use the following setup:

.vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch and attach",
            "type": "bun",
            "request": "attach",
            "url": "ws://127.0.0.1:5000/test",
            "preLaunchTask": "Bun: Start Debugger",
            "internalConsoleOptions": "openOnSessionStart"
        }
    ]
}

.vscode/tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Bun: Start Debugger",
            "type": "shell",
            "command": "bun --inspect-brk=127.0.0.1:5000/test test.ts",
            "isBackground": true,
            "problemMatcher": [
                {
                    "pattern": [
                        {
                            "regexp": ".",
                            "file": 1,
                            "location": 2,
                            "message": 3
                        }
                    ],
                    "background": {
                        "activeOnStart": true,
                        "beginsPattern": "Listening:",
                        "endsPattern": "ws://127.0.0.1:5000/test"
                    }
                }
            ]
        }
    ]
}
MindStudioOfficial commented 2 weeks ago

Can confirm this issue for bun 1.1.33 with VSCode on Windows and extension version v0.0.15.

Workaround works