Skip to content

Links to the same symbol should not be rendered as links #3149

Open

Description

@gspencergoog

If I have a symbol with documentation:

  /// The style to use for the [helperText].
  ///
  /// If [helperStyle] is a [MaterialStateTextStyle], then the effective
  /// text style can depend on the [MaterialState.focused] state, i.e.
  /// if the [TextField] is focused or not.
  final TextStyle? helperStyle;

Then, when the page is rendered, the bracketed reference to [helperStyle] is rendered as a link to the same page that the user is already viewing.

This means that to have "correctly" authored documentation for that, then we need to write it as `helperStyle` instead. But backticks are not references as far as the IDEs are concerned, so it means that if we rename a symbol in the IDE, then we miss anything that was a "local" reference to the symbol in the documentation, and we have to manually fix those up.

If Dartdoc would simply not render a local reference to the same symbol as a link (and just render it as code), then we could convert all the cases of using backticks to highlight local symbols into proper symbol references, and renaming would get a lot easier/less error prone.

The same is true for arguments to a function. For constructors, this is often not a problem, because linking to [argument] usually winds up linking to a property with the same name, but for regular functions, the IDE considers [argument] to be a link to the argument, but dartdoc will fail if you do that, because it doesn't consider it a symbol that can be linked (it doesn't have a page for each argument, understandably). So, ideally, bracketed references to arguments would be allowed, but if the symbol being documented is not a constructor, or it is, but there's no corresponding property, they simply get rendered as a backtick would. Then, in an IDE renaming of the argument will automatically fix the docs up, even if there's no actual link rendered in the dartdoc output. It could error out if there were no symbol or argument with that name (instead of just looking for a symbol).

This issue has led to style guide recommendations (so that we have correctness) that make renaming symbols more error prone. If dartdoc were to render these in the above ways, we could just say "link symbol and parameter names with brackets", which would also simplify the style guide. EDIT: Actually not true: I was mangling those recommendations in my head.

Activity

  1. changed the title [-]Links to the same symbol should not be links[/-] [+]Links to the same symbol should not be rendered as links[/+] on Sep 9, 2022
  2. srawlins commented on Sep 9, 2022

    @srawlins
    Member

    I'm in favor of this for general UX, but I have some questions:

    This means that to have "correctly" authored documentation for that, then we need to write it as helperStyle instead.

    What is incorrect about a link that routes to the current page?

    If Dartdoc would simply not render a local reference to the same symbol as a link (and just render it as code), then we could convert all the cases of using backticks to highlight local symbols into proper symbol references, and renaming would get a lot easier/less error prone.

    Why shouldn't this be done, regardless of dartdoc's priorities?

    This issue has led to style guide recommendations (so that we have correctness) that make renaming symbols more error prone.

    I read the link but cannot find what you're referring to, as far as self-referential references. There's a bit about parameters, unrelated.

  3. gspencergoog commented on Sep 9, 2022

    @gspencergoog
    CollaboratorAuthor

    What is incorrect about a link that routes to the current page?

    It appears to be a no-op from the user's perspective (it causes a "hey, why didn't that link take me anywhere?" moment), and by being a link, it implies that there is more information to be found, but really, they've already found it.

    Why shouldn't this be done, regardless of dartdoc's priorities?

    Because it results in the above confusion.

    I read the link but cannot find what you're referring to, as far as self-referential references. There's a bit about parameters, unrelated.

    Well, I was referring to that parameter text, which highlights the other issue that it's ambiguous to link a parameter (I wasn't attempting to address that here, although it is somewhat related). I was mainly referring to the recommendation to use backticks for parameters. I guess you're right that it's not really directly related to this issue, since it probably would continue to be the recommendation without a resolution to #1486

  4. srawlins commented on Sep 9, 2022

    @srawlins
    Member

    FWIW, this amazes me a little bit. There are two choices, right?

    • Refer to this declaration with square brackets. If a user visits the docs in a browser, and clicks such a link, it may result in momentary confusion.
    • Refer to this declaration with backticks. This means the identifier will not be rewritten in a dart fix, or a refactoring, and may get lost in refactorings.

    The Flutter team has decided that the latter option is the lesser of two evils?

  5. srawlins commented on Sep 9, 2022

    @srawlins
    Member

    To fix this, given a class instance method m with dartdoc text like /// [m] returns something really exciting., we want to either conditionally parse the text as a link:

    • In the page documenting the containing class, we do want to render [m] as a link.
    • In the page documenting m, we do not want to render [m] as a link.

    Which I think would be very hard to do. Or just always do the second thing, and not create a link for self-referential references. The UX there isn't that bad. I don't think there are more complicated cases than what I've listed above.

  6. gspencergoog commented on Sep 9, 2022

    @gspencergoog
    CollaboratorAuthor

    The Flutter team has decided that the latter option is the lesser of two evils?

    Apparently so. I wasn't part of that decision, so I'm not quite sure what all of the considerations were. It probably had something to do with the confusion between links to parameters and links to members in constructor documentation. Maybe @Hixie can comment.

    Part of the reason I filed this was because I wanted to reverse that, but wanted to make it more of a no brainer by eliminating the confusion that self-linking links might cause.

    Couldn't you just skip emitting links when generating the HTML if the link matches the current page's URL and write a <code> section instead? Of course, I say that glibly without a clue about what the details of generating the HTML in Dartdoc are.

  7. srawlins commented on Sep 9, 2022

    @srawlins
    Member

    Part of the reason I filed this was because I wanted to reverse that, but wanted to make it more of a no brainer by eliminating the confusion that self-linking links might cause.

    Yeah this would be the best case scenario.

    Couldn't you just skip emitting links when generating the HTML if the link matches the current page's URL and write a <code> section instead? Of course, I say that glibly without a clue about what the details of generating the HTML in Dartdoc are.

    The code that parses a string of Markdown text is unconnected to the HTML file(s) where it will be written to.

  8. gspencergoog commented on Sep 9, 2022

    @gspencergoog
    CollaboratorAuthor

    Actually, it does say why in the style guide: "We want to avoid cases where a parameter that happens to be named the same as a property despite having no relationship to that property gets linked to the property."

  9. Hixie commented on Sep 9, 2022

    @Hixie
    Contributor

    My intent was that we would use square brackets, not backticks, for self-references. I'm not particularly worried about self-links being confusing, though I don't have an objection to dartdoc noticing they are redundant self-links and rendering them as non-links. The benefits of being consistent far outweigh anything else going on here.

    Parameters are a special case. Dartdoc is ambiguous in its handling of [...] in the presence of parameters with names that conflict with members. It's much more important to be able to link to members than parameters (there's nothing for the parameters to even link to), and in many cases in Flutter parameters correspond to identically-named members which we actually do want to link to. As a result, Flutter is supposed to use the convention that [...] does not refer to parameters.

    As with any project with hundreds of contributors, I'm sure we've made mistakes in practice, but the above is what I intended the style guide to say.

  10. gspencergoog commented on Sep 9, 2022

    @gspencergoog
    CollaboratorAuthor

    I (and maybe others) have often referred to the member itself with backticks inside of its own documentation, since otherwise it self-links to the page it's already on. (So, in the case at the top of this issue, I would use `helperStyle` to avoid this).

    It seems like I may have incorrectly expanded the intent of the style guide in that case, since that doesn't appear to be the point of the rule in the style guide at all. As penance, I'll go find all the places I did that and fix them. :-)

    If it's just too hard to implement prevention of the self-linking in dartdoc, then I guess just close this issue, and I'll not worry about it anymore.

  11. Hixie commented on Sep 10, 2022

    @Hixie
    Contributor

    I agree that self-references are mildly confusing. I think the inconsistency of sometimes using [] and sometimes using ` is even more confusing though, and we can't consistently use ` because of templates. (Also, it makes copy and paste harder. Also, it means we don't get static analysis. But of course that's why you filed this bug. :-) )

  12. added
    type-enhancementA request for a change that isn't a bug
    P3A lower priority bug or feature request
    on Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requesttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions