Skip to content

Commit 066a876

Browse files
docs(contributing): Add "Setting up a Debugger" section (#4421)
Co-authored-by: GitHub Action <[email protected]>
1 parent c07a241 commit 066a876

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

.vscode/launch.example.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "bun",
6+
"request": "attach",
7+
"name": "opencode (attach)",
8+
"url": "ws://localhost:6499/"
9+
}
10+
]
11+
}

.vscode/settings.example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"oven.bun-vscode"
4+
]
5+
}

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ Want to take on an issue? Leave a comment and a maintainer may assign it to you
4242
> [!NOTE]
4343
> After touching `packages/opencode/src/server/server.ts`, run "./packages/sdk/js/script/build.ts" to regenerate the JS sdk.
4444
45+
### Setting up a Debugger
46+
47+
Bun debugging is currently rough around the edges. We hope this guide helps you get set up and avoid some pain points.
48+
49+
The most reliable way to debug OpenCode is to run it manually in a terminal via `bun run --inspect=<url> dev ...` and attach
50+
your debugger via that URL. Other methods can result in breakpoints being mapped incorrectly, at least in VSCode (YMMV).
51+
52+
Caveats:
53+
54+
- `*.tsx` files won't have their breakpoints correctly mapped. This seems due to Bun currently not supporting source maps on code transformed
55+
via `BunPlugin`s (currently necessary due to our dependency on `@opentui/solid`). Currently, the best you can do in terms of debugging `*.tsx`
56+
files is writing a `debugger;` statement. Debugging facilities like stepping won't work, but at least you will be informed if a specific code
57+
is triggered.
58+
- If you want to run the OpenCode TUI and have breakpoints triggered in the server code, you might need to run `bun dev spawn` instead of
59+
the usual `bun dev`. This is because `bun dev` runs the server in a worker thread and breakpoints might not work there.
60+
61+
Other tips and tricks:
62+
63+
- You might want to use `--inspect-wait` or `--inspect-brk` instead of `--inspect`, depending on your workflow
64+
- Specifying `--inspect=ws://localhost:6499/` on every invocation can be tiresome, you may want to `export BUN_OPTIONS=--inspect=ws://localhost:6499/` instead
65+
66+
#### VSCode Setup
67+
68+
If you use VSCode, you can use our example configurations [.vscode/settings.example.json](.vscode/settings.example.json) and [.vscode/launch.example.json](.vscode/launch.example.json).
69+
70+
Some debug methods that can be problematic:
71+
72+
- Debug configurations with `"request": "launch"` can have breakpoints incorrectly mapped and thus unusable
73+
- The same problem arises when running OpenCode in the VSCode `JavaScript Debug Terminal`
74+
75+
With that said, you may want to try these methods, as they might work for you.
76+
4577
## Pull Request Expectations
4678

4779
- Try to keep pull requests small and focused.

0 commit comments

Comments
 (0)