dartdoc icon indicating copy to clipboard operation
dartdoc copied to clipboard

[private-named-parameters] Dartdoc Support

Open munificent opened this issue 2 months ago • 3 comments

This issue tracks the work needed to support "Private Named Parameters" in Dartdoc.

This feature does impact Dartdoc in that we want a private named parameter to be documented as its public name. Given a class like:

class C {
  int _x;
  C({required this._x});
}

Then the dartdoc for the constructor should look something like:

C({required int x});

munificent avatar Oct 01 '25 20:10 munificent

Also, all visible textual references to the parameter in the actual generated DartDoc should use the public name, so

class Baz {
  final int foo, _bar;
  /// Creates `Baz` from [foo] and [_bar].
  new(this.foo, {this._bar}) : asset(_bar != 0);
}

will generate a documentation of:

Creates <code>Baz</code> from
<code>foo</code> and <code>bar</code>.

(It would be nice if DartDoc did the same thing for positional private initializing or declaring parameters, otherwise I'll still have to do (int foo): _foo = foo;. That needs to check if there is another parameter which has the corresponding make already, but otherwise it would be the same.)

lrhn avatar Oct 06 '25 05:10 lrhn

@johnniwinther this sounds like the analyzer api should provide a "external name" of parameters somehow?

sigurdm avatar Oct 06 '25 08:10 sigurdm

Yes. To the extent that we use AST nodes for printing the constructor parameters we need this. The element should show the public name in all cases.

johnniwinther avatar Oct 06 '25 09:10 johnniwinther