Skip to content

Commit

Permalink
Include extension members on the extended type's page (#3863)
Browse files Browse the repository at this point in the history
Fixes #2021

In this feature, we list extension members of an extended type on that extended
type's page. The members are listed inline with other instance members and are
cross-linked over to the extension's member pages.

* Introduce `availableInstanceMethods` as a list combining both instance
  methods declared in a container, and instance methods declared in an
  applicable extension. The same for `availableInstanceOperators` and
  `availableInstanceFields`.
* Introduce some constructors like `Field.providedByExtension` for members that
  are provided by an extension.
* Add lots of documentation clarifying _where_ various members come from.
* We introduce a new getter on ElementType, `nameWithGenericsPlain`, which is
  not HTML-formatted, for use in HTML "title text."
  • Loading branch information
srawlins committed Sep 10, 2024
1 parent 8100ccf commit ca98b89
Show file tree
Hide file tree
Showing 28 changed files with 1,139 additions and 326 deletions.
16 changes: 16 additions & 0 deletions lib/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,22 @@ h1 .category {
vertical-align: middle;
}

/* Do not display "provided by X extension" text on extension pages. */
.main-content.extension-page .from-extension {
display: none;
}

sup.muted {
color: var(--main-sidebar-color);
font-size: 0.6em;
}

.from-extension > span {
background-color: var(--alert-warning);
font-style: italic;
padding: 2px;
}

/* The badge under a declaration for things like "const", "read-only", etc. and for the badges inline like sealed or interface */
/* See https://github.com/dart-lang/dartdoc/blob/main/lib/src/model/feature.dart */
.feature {
Expand Down
18 changes: 16 additions & 2 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ abstract class ElementType with CommentReferable, Nameable {

String get linkedName;

/// Name with generics and nullability indication.
/// Name with generics and nullability indication, in HTML tags.
String get nameWithGenerics;

/// Name with generics and nullability indication, in plain text, with
/// unescaped angle brackets.
String get nameWithGenericsPlain;

@override
String get displayName => throw UnimplementedError();

Expand Down Expand Up @@ -103,11 +107,14 @@ class UndefinedElementType extends ElementType {
return type.documentableElement!.name!;
}

@override
String get linkedName => name;

@override
String get nameWithGenerics => '$name$nullabilitySuffix';

@override
String get linkedName => name;
String get nameWithGenericsPlain => '$name$nullabilitySuffix';

@override
Iterable<ElementType> get typeArguments => const [];
Expand Down Expand Up @@ -241,6 +248,9 @@ class TypeParameterElementType extends DefinedElementType {

@override
String get nameWithGenerics => '$name$nullabilitySuffix';

@override
String get nameWithGenericsPlain => '$name$nullabilitySuffix';
}

/// An [ElementType] associated with an [Element].
Expand Down Expand Up @@ -341,6 +351,10 @@ mixin Rendered implements ElementType {
@override
late final String nameWithGenerics = _renderer.renderNameWithGenerics(this);

@override
late final String nameWithGenericsPlain =
_renderer.renderNameWithGenerics(this, plain: true);

ElementTypeRenderer<ElementType> get _renderer;
}

Expand Down
Loading

0 comments on commit ca98b89

Please sign in to comment.