VSCode: Debugging, breakpoints and stepping through Motoko code

I’d like to be able to step through my Motoko code and inspect variables using VSCode’s Debug Console instead of relying on debugPrint statements to observe flow. Is this currently possible?

What’s the recommended workflow for VSCode? I’ve been doing what is done in the quickstart and tutorials, which is to make changes to the code then run dfx deploy and then run dfx canister call ... to test a function or refresh a browser page at either http://127.0.0.1:8000/?canisterId=... or http://127.0.0.1:8000/candid?canisterId=... to test the frontend or candid interface.

I could set up launch configs in VSCode to automate those steps, but it wouldn’t allow me to add breakpoints and step through code.

I’m using the vscode-motoko extension.

2 Likes

While we are busily working on better debugging, it’s not quite ready for developer consumption, and a lot more yaks need to be shaved until you can just debug a canister running in the thing started with dfx start directly from your VSCode’s console.

The best step-through debugging we have right now is for “pure” Motoko code (i.e. no interaction with the Internet Computer), compiled to a self-contained, stand-alone Wasm module (no IC-specific imports), and then running that in the browser, where you can use the browser’s develpoment tools to set breakpoints.

So as I said, not quite there yet :wink:

2 Likes

Got it, thanks! Carry on; those yaks won’t shave themselves!

1 Like