Skip to content

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

Open
srawlins opened this issue Oct 12, 2021 · 12 comments
Open

Expand analyzer's resolution of Dartdoc comment references #47444

srawlins opened this issue Oct 12, 2021 · 12 comments
Assignees
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-ux P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

Currently the set of allowed comment references is very very small. Something like:

  • simple identifier (one word)
  • prefixed identifier (foo.bar), for an import prefix and library-level element pair, for a named constructor, and for a static method

We'll expand the set to include:

  • static method or constructor on a prefixed library element (foo.bar.baz)
  • type literal with type arguments (foo<...>)
  • constructor tear-offs with type arguments (foo.bar<...>), including constructor on a prefixed library-level element
  • function tear-offs with type arguments (foo<...>) for top-level functions and static methods

All 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 on CommentReference, called expression.

Steps to get there:

  1. Add new node; update Identifier, PropertyAccess, TypeLiteral, ConstructorReference, FunctionReference to implement new node; add CommentReferableExpression get expression to CommentReference; deprecate CommentReference.newKeyword and CommentReference.identifier; change implementation of CommentReference.identifier to return expression as Identifier.
  2. Publish and update clients to use expression.
  3. Update resolution to resolve more comment text to resolve to CommentReferences; remove CommentReference.newKeyword and CommentReference.identifier.
@srawlins srawlins added legacy-area-analyzer Use area-devexp instead. devexp-ux labels Oct 12, 2021
@srawlins srawlins self-assigned this Oct 12, 2021
@jcollins-g jcollins-g added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Oct 13, 2021
copybara-service bot pushed a commit that referenced this issue Oct 29, 2021
…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]>
copybara-service bot pushed a commit that referenced this issue Dec 14, 2021
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]>
@srawlins
Copy link
Member Author

srawlins commented Jul 1, 2024

CC @bwilkerson for any comments.

@srawlins
Copy link
Member Author

CC @eernstg who cited the spec in another recent issue about comment reference resolution.

@eernstg
Copy link
Member

eernstg commented Jul 19, 2024

Right, that would be #56259 (comment).

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 27, 2025
@FMorschel
Copy link
Contributor

I was thinking about this, it would be good to support

/// Works with a [List<T>] internally
void foo<T>() {
  var list = <T>[];
}

@bwilkerson
Copy link
Member

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.

@FMorschel
Copy link
Contributor

I think I've seen (in Flutter SDK IIRC) a reference to [List<String>] before (probably got removed because it doesn't work) but never type parameters.

Are there examples of places where users are using type annotations as references (as opposed to simple type names)?

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.

@bwilkerson
Copy link
Member

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.

@lrhn
Copy link
Member

lrhn commented Mar 28, 2025

Are there examples of places where users are using type annotations as references

I've seen [List<int>], or similarly instantiated types, plenty of times.
I think it also accidentally "works" because DartDoc erases the invalid HTML tag <int>. Won't work so well for [List<Div>].

@srawlins
Copy link
Member Author

srawlins commented Mar 28, 2025

Yeah, grepping the Flutter codebase as one example, there are 16 cases of ///.* [List<. I imagine Future<, Map<, etc would be similarly common.

@FMorschel
Copy link
Contributor

I've just noticed at dart-lang/test#2481 (comment) that this is displayed the same as the comment:

image

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.

@bwilkerson
Copy link
Member

I don't believe that we support the use of this as a comment reference. There is no explicit declaration of this, so it isn't clear where the user would expect that to link to.

@srawlins
Copy link
Member Author

Yeah we made an explicit decision to stop supporting [this] in dartdoc, as analyzer does not support it, and it makes sense to not support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-ux P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants