Skip to content

Expand dartdoc macros when looking at the source #4240

Open

Description

@rrousselGit

Related to #3527

Is your feature request related to a problem? Please describe.

When inspecting the source code of a Dart API, sometimes we come across APIs that use {@macro}/{@template}:

/// {@template example}
/// Hello world
/// {@endtemplate}
void fn() {}

/// {@macro example}
void another() {}

VSCode handles them nicely, where by hovering another we correctly see the documentation instead of {@macro}.

But when we read the source, we don't.
Reading that {@macro} when we have the source in front of us isn't very helpful.

Describe the solution you'd like

Since VScode has proved to be able to add virtual non-editable text blocks to improve readability, like with nested classes.
Where writing:

@override
Widget build(BuildContext context) {
  return Container(
    child: Center(),
  );
}

renders as

@override
Widget build(BuildContext context) {
  return Container(
    child: Center(),
  ); // Container
}

(cf the extra // Container)

What about doing the same with dartdoc macros?

We could do that writing:

/// {@template example}
/// Hello world
/// {@endtemplate}
void fn() {}


/// Before
/// {@macro example}
/// After
void example() {}

would render as:

/// Before
/// {@macro example}
/// Hello world
/// After
void example() {}

Of course, we'd need something to differentiate the macro content from the "actual" doc.

So maybe the /// Hello world should show up in grey instead of green ; to highlight that it is dynamically injected by VSCode.
And it would also be uneditable

Activity

  1. added
    is enhancement
    on Nov 2, 2022
  2. DanTup commented on Nov 2, 2022

    @DanTup
    Member

    I don't think we can replace the @macro text, but we could likely inject the docs after it (or maybe in between it and the following line).

    It would be nice to do this in an LSP-standard way, but right now the closest we have is InlayHints, and right now their styling is not customisable for custom types. I have an open issue at microsoft/vscode#151920 (since I'd like to move Closing Labels to something standard too) that would appreciate your 👍 s!

    I'm not against adding custom messages, but I'd like to try and avoid it where possible (and ensure where it is done, it adds reasonable value). I've added a comment to that issue to see whether VS Code / LSP think InlayHints is the right thing for this (and if not, whether a new API would make sense).

    (@bwilkerson FYI)

  3. added this to the Backlog milestone on Nov 2, 2022
  4. added
    in editor
    on Nov 2, 2022
  5. added
    blocked on vs code / lsp / dap
    on Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked on vs code / lsp / dapin editoris enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions