Skip to content
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

drop an "Extended Symbol" page when its children are curated elsewhere #541

Merged

Conversation

QuietMisdreavus
Copy link
Contributor

Bug/issue #, if applicable: rdar://107729630

Summary

When Swift-DocC gets symbol graphs with extension block symbols, it creates "Extended Module/Class/Structure/etc" symbols to automatically curate the extension symbols into. However, if the extension symbols are then curated in the rest of the documentation hierarchy, these extra symbols are left in the topic graph and create empty pages that don't need to be there. This PR adds a pass to DocumentationContext.register(_:) to drop these symbols if all their children have been curated elsewhere. (This pass is done recursively, so "Extended Module" pages will drop if all their child "Extended Class/Structure/etc" pages are also dropped.)

Dependencies

None

Testing

The following code was used to test this functionality:

/// a namespace for organization.
///
/// ## Topics
///
/// - ``Swift/Array/asdf``
public enum MyNamespace {}

public extension Array {
  var asdf: Int { count }
}

Steps:

  1. Build a symbol graph for the above code that includes extension block symbols. (The code above was used to create the ModuleWithSingleExtension test fixture added in this PR, which can be used as a shortcut.)
  2. Add the resulting symbol graphs to a documentation catalog and generate documentation.
  3. Ensure that the resulting documentation doesn't contain the "Extended Module" page for Swift, nor the "Extended Structure" page for Array.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • [ n/a ] Updated documentation if necessary

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@theMomax theMomax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, this is definitely a useful addition!

One thing I'd like to discuss, though, is how this change affects references to extension pages that get dropped. What would happen if you added a (non-curating) reference to ``Swift/Array`` to your test example (on a page that is not removed, e.g. ``ModuleWithSingleExtension``, or on a page that is also removed, e.g. ``Swift``).

Could you please document the intended behavior for both scenarios in a test case? I'm also not sure what the ideal behavior is, really.

In the case where the referencing page is also removed (``Swift`` links to ``Swift/Array``), I think we should just make sure that we don't generate a warning. This might very well already be the case with your implementation.

In the case where the referencing page is not removed (``ModuleWithSingleExtension`` links to ``Swift/Array``), I see three options:

  1. We do not remove the referenced page, because the reference suggests it is still relevant.
  2. We remove the referenced page, and we emit a warning with a specialised diagnostic for the actually "valid" reference.
  3. We remove the referenced page, and silently downgrade the reference to a monospaced text without link.

@QuietMisdreavus
Copy link
Contributor Author

@theMomax Thanks for the review! Right now it looks like the behavior for when you actually curate or reference a page is a bit awkward:

  • If you merely reference an extension page without curating it, the link is still considered "live" but the destination page doesn't exist.
  • If you curate it into the top-level page (i.e. ModuleWithSingleExtension) the same thing happens: The link is still there, but the page is not.
  • If you curate it into a second-level page that's not also an extension (e.g. the MyNamespace enum in the demo project i added) then that copy of the page still exists, alongside all its children! This is because my code doesn't recurse into non-extension pages, so it sees an enum and skips it, despite there being an extension curated in there.

I think what i would want to happen in the case of a non-curating reference is your option (2), with maybe some extra logic for if there are extension files for the extension pages that keep them "live". I'll take a look at adding these suggestions.

@QuietMisdreavus
Copy link
Contributor Author

I just pushed a couple commits to handle @theMomax's review comments. They've added the following functionality:

  1. Links to "Extended Symbol" pages which have been removed will generate a warning: "The topic 'TopicName' is an empty extension page and cannot be linked to." I'm not 100% confident in the diagnostic replacement system to be able to recommend dropping the symbol link to an inline code span (or some other kind of recommendation), so i left that blank for now.
  2. "Extended Symbol" pages which have a documentation extension file of their own are not dropped, even if all their children have been canonically curated elsewhere. This also means that symbol links to them will not generate a warning since they will properly resolve.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@ethan-kusters
Copy link
Contributor

ethan-kusters commented Apr 11, 2023

Screenshot 2023-04-11 at 1 37 59 PM

I'm seeing an issue with symbols that are included in relationships sections. Here I built ArgumentParser with:

swift package --disable-sandbox preview-documentation --target ArgumentParser --include-extended-types --experimental-skip-synthesized-symbols

The resulting docs are much nicer now (they exclude all of the empty Bool, Int64, etc pages) but now I'm seeing broken links in the relationships sections for ExpressibleByArgument. When I click on one of the links I end up on a non-existent page.

Ideally I think these symbols would still appear but as monospace references instead:

### Conforming Types

`Swift.Bool`
`Swift.Double`
...

@QuietMisdreavus
Copy link
Contributor Author

@ethan-kusters Oh right, i wanted to look into that! 😅 I don't know offhand where those are rendered, but i can look at that next.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@ethan-kusters
Copy link
Contributor

I'm not sure if it should be resolved yet, but even with the latest changes I'm still able to reproduce the issue I was seeing with ArgumentParser.

@d-ronnqvist d-ronnqvist self-requested a review April 13, 2023 04:45
@QuietMisdreavus
Copy link
Contributor Author

@ethan-kusters Oh interesting! I fixed the broken links when you reference them from a symbol link, but not when they're automatically inserted like that. Let me take a look.

@QuietMisdreavus
Copy link
Contributor Author

@ethan-kusters I just pushed up a solution. Can you try it now?

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@ethan-kusters
Copy link
Contributor

ethan-kusters commented Apr 13, 2023

@ethan-kusters I just pushed up a solution. Can you try it now?

Woot! Looks great.

Screenshot 2023-04-13 at 3 20 53 PM

In other cases like this we include the module namespace (i.e. Swift.Foo):

Screenshot 2023-04-13 at 3 21 00 PM

Is it simple to do the same thing here? If not – we can definitely leave it for a future PR.

@QuietMisdreavus
Copy link
Contributor Author

That seems doable - the title defers to the LinkTitleResolver, which itself seems to defer to the symbol information. However, i feel like this PR has ballooned a little bit and the current state of things is serviceable for the moment. I can file an issue to follow up if you'd like.

@ethan-kusters
Copy link
Contributor

However, i feel like this PR has ballooned a little bit and the current state of things is serviceable for the moment. I can file an issue to follow up if you'd like.

That would be great. Thank you!

@QuietMisdreavus
Copy link
Contributor Author

@ethan-kusters Just filed #554 to track it.

@QuietMisdreavus QuietMisdreavus dismissed theMomax’s stale review April 14, 2023 15:34

Review comments addressed

@QuietMisdreavus QuietMisdreavus merged commit e135c5b into swiftlang:main Apr 14, 2023
@QuietMisdreavus QuietMisdreavus deleted the drop-empty-extended-symbols branch April 14, 2023 15:48
QuietMisdreavus added a commit to QuietMisdreavus/swift-docc that referenced this pull request Apr 14, 2023
swiftlang#541)

rdar://107729630

Bundles with extension block symbols generate placeholder "Extended Symbol"
pages to automatically curate extension symbols. However, if the symbols are
then curated elsewhere, the "Extended Symbol" pages are left confusingly
empty. Drop these pages if they have no child pages remaining.

An "Extended Symbol" page will remain if an extension markdown file is
provided for it, even if its children are curated elsewhere.

Links to these dropped pages will generate a warning and be converted to code
voice in the final rendering. References in automatically generated
symbol-relationship page sections will not generate a warning, but they will
be converted to code voice as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants