-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand analyzer's resolution of Dartdoc comment references #47444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…a CommentReference * Replace `identifier` field with `expression`, which means deprecating `identifier`, redirecting users to `expression`. For now, `expression` always returns an Identifier. In a future breaking release, it will return other CommentReferableExpressions. * SimpleIdentifier, PrefixedIdentifier, PropertyAccess, ConstructorReference, FunctionReference, and TypeLiteral are all CommentReferableExpressions, but support is not implemented yet to parse CommentReferences with those contained expressions. Bug: #47444 Change-Id: I1905afecf3878cd7dca6e275ef0a2ab80500eb4d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216320 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Janice Collins <[email protected]>
This expands the front_end's and analyzer's support for doc comment references to include `/// [a.b.c]`. Such a reference must be to a getter, setter, method, or constructor of a class or extension which is referenced with an import prefix, such as `[async.Future.value]`. In the existing support for two words, the two words are named "prefix" and "token". In a three-word reference, the _first_ word must be an import prefix, but I've chosen the new names, "leadingPrefix", "prefix", and "token", to minimize the change. If an improved change is desirable, considering the names from scratch, I might choose something like "prefix", "container", and "identifier". But these names will be applied to one-word and two-word references as well, so `[async.Future]`, a reference to the Future class provided by an import prefixed as 'async', would have a 'prefix' of null, a 'container' of 'async', and an identifier of 'Future'. Bug: #47444 Change-Id: I7758ec16872677221c456dd1dd6dc2a4df0f6102 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/223661 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
CC @bwilkerson for any comments. |
CC @eernstg who cited the spec in another recent issue about comment reference resolution. |
Right, that would be #56259 (comment). |
I was thinking about this, it would be good to support /// Works with a [List<T>] internally
void foo<T>() {
var list = <T>[];
} |
Are there examples of places where users are using type annotations as references (as opposed to simple type names)? I don't want to add features that nobody wants to use. If we were to add support for type annotations then we might need to support all type annotations, not just those involving a type name and a list of type arguments. In particular, we'd need to consider function types and record types. |
I think I've seen (in Flutter SDK IIRC) a reference to
I'm unsure. Probably not, but that may be because of this and #60417. With type parameters having little to no use on docs today, this answer may be biased since people may notice that it doesn't work as expected and remove this part from the docs or replace it with something else. |
Yes, the lack of support might be biasing users. I could hope that if users want to use type annotations in comment references and then notice that it doesn't work, that they'd open a request for it, though I know that that won't always be the case. Even so, we don't have unlimited resources so we can't add support for everything that someone might want. |
I've seen |
Yeah, grepping the Flutter codebase as one example, there are 16 cases of |
I've just noticed at dart-lang/test#2481 (comment) that I think I've seen some references to it like that. I've not yet looked at the resulting HTML to see what happens, but I was wondering if this is just a "non-"reference visual or if this is also not supported. |
I don't believe that we support the use of |
Yeah we made an explicit decision to stop supporting |
Currently the set of allowed comment references is very very small. Something like:
foo.bar
), for an import prefix and library-level element pair, for a named constructor, and for a static methodWe'll expand the set to include:
foo.bar.baz
)foo<...>
)foo.bar<...>
), including constructor on a prefixed library-level elementfoo<...>
) for top-level functions and static methodsAll identifiers, including type arguments, should be hoverable and jumpable. Dartdoc's comment reference resolution is already separate from analyzer's and supports more expressions; it can be separately updated to match (or use) analyzer's resolution more closely.
This will be accomplished with a new interface,
CommentReferableExpression
, and a new member onCommentReference
, calledexpression
.Steps to get there:
CommentReferableExpression get expression
toCommentReference
; deprecateCommentReference.newKeyword
andCommentReference.identifier
; change implementation ofCommentReference.identifier
to returnexpression as Identifier
.expression
.CommentReference
s; removeCommentReference.newKeyword
andCommentReference.identifier
.The text was updated successfully, but these errors were encountered: