Repository navigation
Description
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
DanTup commentedon Nov 2, 2022
I don't think we can replace the
@macrotext, 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)