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

Prefer non-symbols in general documentation links #594

Merged

Conversation

d-ronnqvist
Copy link
Contributor

@d-ronnqvist d-ronnqvist commented May 19, 2023

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

Summary

This restores a previous behavior from the previous link resolver where doc links prioritized non-symbol results without needing disambiguation.

Dependencies

None.

Testing

Build documentation for Swift Markdown. The links to <doc:BlockMarkup> and <doc:InlineMarkup> should resolve to those articles without needing disambiguation.

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
  • Updated documentation if necessary

@d-ronnqvist d-ronnqvist requested a review from ethan-kusters May 19, 2023 22:40
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

Comment on lines +544 to +545
if let symbolOrNonSymbolMatch = collisions.singleMatch({ ($0.node.symbol != nil) == onlyFindSymbols }) {
return symbolOrNonSymbolMatch.node
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm struggling to follow this line. Could it be structured like this or is it doing something different?

Suggested change
if let symbolOrNonSymbolMatch = collisions.singleMatch({ ($0.node.symbol != nil) == onlyFindSymbols }) {
return symbolOrNonSymbolMatch.node
if !onlyFindSymbols, let nonSymbolMatch = (collisions.singleMatch { $0.node.symbol == nil })
return nonSymbolMatch.node

If non-symbols aren't allowed, skip all non-symbols.

Have these not already been filtered out prior to this or do we need to handle that case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only difference is that with onlyFindSymbols inside the closure it checks both ways.

For symbol links (when onlyFindSymbols is true) it checks that the match has a symbol.
For general documentation links (when onlyFindSymbols is false) it checks that the match doesn't have a symbol.

Have these not already been filtered out prior to this or do we need to handle that case here?

It is checked at the start of the search to avoid looking at the article root but as I was writing this I thought that it would be possible to find an article as a child of the module. Now I'm not sure anymore.. I'll have to try it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay sounds good. If it's possible to simplify this I think that would make it easier to follow – but not a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this and in the case where a symbol and an article have the same path, a link that's spelled with the absolute path will have a collisions here. In this case filtering out non-symbols in symbol links in both places (here and where the found node is returned) provides a better experience because it avoids the collisions (and also excludes the non-symbols from diagnostics if there were multiple symbols colliding with an article).

I updated the comment to explain all this, added a test that has this behavior, and added an extra comment that explains that check is a more compact spelling of two comparisons and an if statement.

Comment on lines +544 to +545
if let symbolOrNonSymbolMatch = collisions.singleMatch({ ($0.node.symbol != nil) == onlyFindSymbols }) {
return symbolOrNonSymbolMatch.node
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay sounds good. If it's possible to simplify this I think that would make it easier to follow – but not a blocker.

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@QuietMisdreavus
Copy link
Contributor

@swift-ci Please test

@d-ronnqvist d-ronnqvist merged commit 483297f into swiftlang:main May 25, 2023
@d-ronnqvist d-ronnqvist deleted the prefer-non-symbols-in-doc-links branch May 25, 2023 17:20
d-ronnqvist added a commit to d-ronnqvist/swift-docc that referenced this pull request May 25, 2023
* Prefer non-symbols in general documentation links

rdar://109583745

* Elaborate comment about filtering symbol and non-symbol collisions.

Also, add test where  symbol and non-symbol have same path.
d-ronnqvist added a commit that referenced this pull request May 25, 2023
* Prefer non-symbols in general documentation links

rdar://109583745

* Elaborate comment about filtering symbol and non-symbol collisions.

Also, add test where  symbol and non-symbol have same path.
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.

3 participants