sdk
sdk copied to clipboard
Is that possible to set breakpoints in the macro code itself?
Hi!
I'm wondering - what are the possible ways to debug we have while developing new macros? The main question - is that possible somehow to put breakpoints into the code of macros itself to introspect something inside?
Like, for example:
import 'dart:async';
import 'dart:developer';
import 'package:macros/macros.dart';
macro class EmptyMacro implements ClassDeclarationsMacro {
@override
FutureOr<void> buildDeclarationsForClass(ClassDeclaration clazz, MemberDeclarationBuilder builder) async {
debugger(message: 'I want to see, what the inside of "clazz"'); // <- I wanna put a breakpoint here to see, what the inside of "clazz"
}
}
The way with Builder.report is something, at least, but definitely not the best. Maybe there is something better already?
The macro implementation code will be run, so it should be technically possible to attach a debugger to it during the compilation process, just like any other Dart code being run.
It's a tooling question whether we allow it, and if so, how. Marking as area-dart-cli since the way macro code is run by end users will be through dart compiler, dart run or dart analyze.
There's currently no way to set breakpoints in macros as we're still finalizing implementation details for the feature and haven't started much serious investigation into what the macro development tooling will look like. We'll be able to provide more details once the design of the macros feature is locked down and we figure out what our options for debugging are.