Skip to content

Allow comment introspection #59842

@Pebkac03

Description

@Pebkac03

Allow comment introspection

I propose adding a property for comments to the Declaration class. I imagine it looking somethings like this:

/// This is the doc comment
final String someVar = 'some value';

void main() {
  // field = the declaration for someVar
  final FieldDeclaration field;
  print(field.comments.toString());
}
dart run
This is the doc comment
Exited.

Usecase

The usecase I have is creating a macro to generate a vscode json-schema file for a config service but I believe access to comments would be very useful in any kind of automatic file generation.

Resources

Implementation of similar functionality in code generation package dartgenerate: https://pub.dev/documentation/dartgenerate/latest/dartgenerate/FieldDeclaration-class.html.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-pkgUsed for miscellaneous pkg/ packages not associated with specific area- teams.feature-macrosImplementation of the macros featurepkg-macrosThe experimental package:_macros librarytype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions