Macros: Introspecting Parameter default values and Doc Comments

35 views
Skip to first unread message

Patt O'Brien

unread,
Feb 7, 2024, 7:48:40 AM2/7/24
to Dart Analyzer Discussion
Hi everyone -

TLDR: are default values on parameters and doc comments both planned to be fully unsupported by the macro introspection APIs?

I've been playing around with the latest macro implementation for the past two weeks or so, to experiment with the new APIs to get a feel for the differences from the analyzer APIs.

I've been building two code-gen related packages, and wanted to build them with macros in mind as well (hoping macros could make the UX of the package even better eventually). One of those packages is a cli command/args generator, that can create an ArgParser instance based on the parameters of a function or constructor, like so:

```dart
/// Shows the commit logs.
@CommandMacro()
Future<void> log({
/// Print out the ref names of any commits that are shown.
Decorate decorate = Decorate.auto,
}) async {
await Process.run('git', ['log', decorate.name]);
}

enum Decorate { short, full, auto, no }

// -- GENERATED CODE BELOW --

final logArgParser = ArgParser()
..addOption(
'decorate',
help: 'Print out the ref names of any commits that are shown.',
allowed: ['short', 'full', 'auto', 'no'],
defaultsTo: 'auto',
mandatory: false,
abbr: 'd',
);

``` 
However, I don't see Doc Comments on any of the introspection APIs, and for the `Parameter`/`ParameterDeclaration` classes, there's a comment that says the `ParameterCode` getter wont expose the default value, despite them both being static at compile time (I'm sure"static" was never meant to apply to comments, but I think the intent of my question still stands lol).

Thanks in advance for any info!

Patt



Brian Wilkerson

unread,
Feb 7, 2024, 12:23:14 PM2/7/24
to analyzer...@dartlang.org
Thanks for the question, but that's really about how a language feature is being designed rather than how the analyzer works. You'll probably get a better answer by creating an issue in the 'language' repository (https://github.com/dart-lang/language/issues/new/choose).

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/de1bdcb9-4b6a-45f6-92f2-9644c009b76en%40dartlang.org.

Patt O'Brien

unread,
Feb 7, 2024, 10:09:41 PM2/7/24
to Dart Analyzer Discussion, brianwilkerson
Thanks for the suggestion Brian - I've opened up an issue there (y)
Reply all
Reply to author
Forward
0 new messages