-
Notifications
You must be signed in to change notification settings - Fork 118
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
handle dartdoc references to non-imported symbols (was: dartdoc-specific imports) #1153
Comments
cc @keertip for thoughts. |
Here's an example as food for thought from rendering.dart:
lints to:
|
The latest thinking on this is to support something like fully qualified symbol references in square brackets (dartdoc specific imports might get a little hairy). Something like /cc @pq @bwilkerson |
👍 I'm in favor in taking the cue from Java's qualified names. Curious where you weigh in @bwilkerson ? |
I could totally work with fully-qualified identifiers in square brackets (assuming they don't render that way, at least). |
@bwilkerson, @scheglov : how does this proposal sit with you? |
I like the idea of fully qualified names. |
FWIW this came up again tonight. https://docs.flutter.io/flutter/material/Icons-class.html Icon and IconButton (the classes which consume the data in icons.dart) can't be linked since they're not imported. |
@scheglov : am I right that this wouldn't be too hard to add? |
Yes, I think it wouldn't be too hard. |
In case it's helpful, here is the output of running flutter analyze with the comment_references lint on. Currently its disabled with a comment saying it's blocked by this bug: I don't think this is a huge deal by any means, just wanted you to have full context. |
We're also getting feedback from the UX team that the missing links in the Flutter API docs is a usability problem. @scheglov Ping. Is there a plan to fix this issue? |
I don't have any specific plans about fixing this issue yet. |
If we fix this, we'll probably also help crossdart.info link to more names. Right now, I can't link to Widget from Button's crossdart page: https://www.crossdart.info/p/flutter/0.0.21/src/material/button.dart.html I'd imagine that Widget would be a link. |
That last thing seems like a separate bug. The code knows what Widget it so the hyperlink should work. This bug is just about hyperlinks from dartdocs themselves to identifiers that are otherwise not in scope. |
I think @devoncarew and @keertip have an idea of how to handle this? Comments here can help speed up implementation :) |
I believe where this was left:
|
That would rock!
I'd argue that we'd want to avoid too much (or any?) logic in dartdoc that
does magic lookup. We'd want the editing experience to clearly align with
what dartdoc does. We want the link to warn if they are referencing
something that doesn't exist, etc...
…On Thu, Dec 1, 2016 at 8:57 AM, Devon Carew ***@***.***> wrote:
I believe where this was left:
- for resolving references to symbols that are not currently imported
(think referencing a material component from the flutter widget layer), we
would need those dartdoc referenced to be fully qualified - to include
enough information for us to resolve them. Something like [package:flutter/material.dart
MaterialApp]
- when the analyzer is not able to resolve a symbol reference in some
dartdoc, dartdoc itself will try to resolve; it should be able to locate
anything currently being documented in that session (so, anything in the
current context). It the above example, it would resolve to
material/MaterialApp-class.html
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1153 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCiis8_K32xzHMk1uiABLTho_-PkLNks5rDvxtgaJpZM4ISYYT>
.
|
Is there an issue open on the analyzer for this "extended link" syntax and support? |
There isn't an issue - putting the logic into dartdoc was the resolution in order to avoid implementation complexity in the analyzer and analysis server (see dart-lang/sdk#27471 (comment)). |
I really would like to avoid having to fully qualify every reference. That would make the dartdocs unreadable, and it turns out that people look at the source a LOT. (Yay jump to definition.) If there is only one identifier with the given name in the entire session, why not just assume that's what it means? And if there are duplicates, then require disambiguation. If we do this then we can even have it fail the entire process if any reference can't be resolved. |
So, |
That would be sufficiently concise for me I think. |
I'm looking into it |
@Hixie noticed, that sometimes, a library, like the Flutter rendering library, wants to refer to another library, like the Flutter widgets library, in the documentation, but doesn't want to introduce a dependency in the code. Currently, there’s no mechanisms in dartdoc, which allows that. This commit adds that. You can use either a short name (e.g. [icon]) or a fully qualified name (like, [material.Icon.icon]), in the HTML docs, it always will be shown as a short name though (is that a desired behavior?). Dartdoc will go over all the libraries, classes, methods, properties, constants of the package that is being documented, and will try to resolve the symbol. If it’s successful, it will add the link to it, same way as when the symbol is in scope. Some outstanding questions: * What to do in case of ambiguity here? Show a warning, crash with an error message, ignore? * Do we want to show short name in case a fully qualified name is provided? I saw in the comments in the ticket (dart-lang#1153 (comment)) that @Hixie would want that. * Anything else? Testing: Unit tests, of course, also tried to generate Flutter docs with that, and observed that the links for previously non-resolved symbols work.
Created initial PR for that. There's still some outstanding questions:
Thanks! |
In case of ambiguity, I would fail hard. Please always give just the short name in the output, yes. BTW once we have this we'll ideally also want to fail hard if there's every a [link] that is not resolvable. (Again, ideally, with an analyzer warning to let us know it'll happen before we try to run the docs.) |
* Resolve non-imported symbols in comments [#1153] @Hixie noticed, that sometimes, a library, like the Flutter rendering library, wants to refer to another library, like the Flutter widgets library, in the documentation, but doesn't want to introduce a dependency in the code. Currently, there’s no mechanisms in dartdoc, which allows that. This commit adds that. You can use either a short name (e.g. [icon]) or a fully qualified name (like, [material.Icon.icon]), in the HTML docs, it always will be shown as a short name though (is that a desired behavior?). Dartdoc will go over all the libraries, classes, methods, properties, constants of the package that is being documented, and will try to resolve the symbol. If it’s successful, it will add the link to it, same way as when the symbol is in scope. Some outstanding questions: * What to do in case of ambiguity here? Show a warning, crash with an error message, ignore? * Do we want to show short name in case a fully qualified name is provided? I saw in the comments in the ticket (#1153 (comment)) that @Hixie would want that. * Anything else? Testing: Unit tests, of course, also tried to generate Flutter docs with that, and observed that the links for previously non-resolved symbols work. * Address @devoncarew feedback * Add types to declarations * Add filename/line number to the warnings * Move the code for gathering all the model elements of a package to the package's accessor and cache it. * Address another round of feedback From now on, if the reference was, for example, `[key]`, we won't match `material.Widget.key`, we will only match `material.key` (i.e. top-level `key` symbol). If you still want to match `Widget.key`, you should use either `[Widget.key]` or `[material.Widget.key]`.
Thanks!! |
For cross-reference: the idea early in this thread of having a way to make imports only for dartdoc purposes now has a proposed design at: The dartdoc tool resolves these references anyway, ever since this issue was resolved in 2016. But the analyis server (and hence jump-to-definition in one's editor) doesn't, which is tracked at: |
Sometimes, a library, like the Flutter rendering library, wants to refer to another library, like the Flutter widgets library, in the documentation, but doesn't want to introduce a dependency in the code. In this case, for example, we definitely do not want any sort of runtime relationship from the rendering library to the widgets library.
We can't use
import
for this because it risks code accidentally depending through the import.One possible solution would be to have something like
/// @import
which would cause the dartdoc code to import it. Another would be for the dartdoc tool to be able to receive a list of imports to imply at the top of every file. I don't really mind how we solve this.The text was updated successfully, but these errors were encountered: