-
Notifications
You must be signed in to change notification settings - Fork 147
Add logic to look for overload groups when emitting warnings #885
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
Add logic to look for overload groups when emitting warnings #885
Conversation
suggestions about ambiguous symbols. If exactly one of the ambiguous symbols is an overload group, then suggest the author simply remove the incorrect disambiguation.
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be special behavior for overload groups. It should be a general behavior whenever there is only one candidate who isn't disfavored in collisions (and therefore doesn't need disambiguation in its link).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this! There are a few tweaks i spotted that i'd like to see, but overall i'm super glad to see this change.
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
Tests/SwiftDocCTests/Infrastructure/DocumentationBundleInfoTests.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Find.swift
Outdated
Show resolved
Hide resolved
84db713
to
2f756bf
Compare
about selecting the preferred symbol without any disambiguation hash, followed by a list of all the remaining symbols to select from with their hashes.
9520ba7
to
d610548
Compare
@swift-ci please test |
I've refactored this to display all the ambiguous links like before, but showing the preferred ("favored") symbol first. Example:
|
Did we stop displaying the full declaration or is that something you simplified in this example? Without the full declaration there's no way to know which disambiguation refers to which symbol. |
|
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
- PathHierarchy.makePartialResultError checks for a preferred symbol, normally an overload group, when throwing processing unknownDisambiguation errors. - Simplify makeTopicReferenceResolutionErrorInfo and limit it to formatting the warning message.
@swift-ci please test |
let candidates = disambiguationTree.disambiguatedValues() | ||
let favoredSuffix = favoredSuffix(from: candidates) | ||
let suffixes = candidates.map { suffix(for: $0.disambiguation) } | ||
let candidatesAndSuffixes = zip(candidates, suffixes).map { (candidate, suffix) in | ||
if suffix == favoredSuffix { | ||
return (node: candidate.value, disambiguation: "") | ||
} else { | ||
return (node: candidate.value, disambiguation: suffix) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be useful for this logic to happen in disambiguatedValues()
. That way, for example, the URL for the overloads page wouldn't need a hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree! I investigated this a bit and I think it will lead to cleaner code and simpler URLs. However, I'd suggest we make this additional change in a separate PR in the near future. Changing the URLs will require updating a large number of unit test expectations, and also will lead to moving pages around in production, leading to more testing, creating the necessary redirects and generally more risk.
For now, I think updating the warning is a good first step.
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Find.swift
Outdated
Show resolved
Hide resolved
Replacement(range: replacementRange, replacement: "-" + disambiguation) | ||
]) | ||
// Suggest removing the disambiguation hash entirely | ||
if disambiguation.isEmpty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would happen automatically, without the special check here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that we need to keep this check. It is possible to remove this check entirely, but then we would have to add the -
prefix to all the unknownDisambiguation warnings throughout all the unit tests.
Example:
Replace '-abc123' with '-method' for\n'func `init`()'"
I think this reads fine for users, but I wouldn't want to make this change across all the unit test expectations unless you like this idea,
Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift
Outdated
Show resolved
Hide resolved
PathHierarchy.makePartialResultError further.
@swift-ci please test |
- Further simplify logic for displaying unknown disambiguation warnings
@swift-ci please test |
@d-ronnqvist I simplified PathHierarchy+Error.swift even more, and updated some unit test expectations to account for the extra hyphen in the warning message. I think the code looks very clean now, and also the warnings read even better or the same as before. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wonderful, great work!
@swift-ci please test |
…ng#885) * Add logic to look for overload groups when emitting warnings and suggestions about ambiguous symbols. If exactly one of the ambiguous symbols is an overload group, then suggest the author simply remove the incorrect disambiguation. * Refactor logic for ambiguous symbol warnings to first emit a message about selecting the preferred symbol without any disambiguation hash, followed by a list of all the remaining symbols to select from with their hashes. * PR Feedback: - PathHierarchy.makePartialResultError checks for a preferred symbol, normally an overload group, when throwing processing unknownDisambiguation errors. - Simplify makeTopicReferenceResolutionErrorInfo and limit it to formatting the warning message. * PR Feedback: Simplify PathHierarchy+Error.swift and PathHierarchy.makePartialResultError further. * PR Feedback: - Further simplify logic for displaying unknown disambiguation warnings (cherry picked from commit 1357a2d)
…ng#885) * Add logic to look for overload groups when emitting warnings and suggestions about ambiguous symbols. If exactly one of the ambiguous symbols is an overload group, then suggest the author simply remove the incorrect disambiguation. * Refactor logic for ambiguous symbol warnings to first emit a message about selecting the preferred symbol without any disambiguation hash, followed by a list of all the remaining symbols to select from with their hashes. * PR Feedback: - PathHierarchy.makePartialResultError checks for a preferred symbol, normally an overload group, when throwing processing unknownDisambiguation errors. - Simplify makeTopicReferenceResolutionErrorInfo and limit it to formatting the warning message. * PR Feedback: Simplify PathHierarchy+Error.swift and PathHierarchy.makePartialResultError further. * PR Feedback: - Further simplify logic for displaying unknown disambiguation warnings
…906) * Add logic to look for overload groups when emitting warnings and suggestions about ambiguous symbols. If exactly one of the ambiguous symbols is an overload group, then suggest the author simply remove the incorrect disambiguation. * Refactor logic for ambiguous symbol warnings to first emit a message about selecting the preferred symbol without any disambiguation hash, followed by a list of all the remaining symbols to select from with their hashes. * PR Feedback: - PathHierarchy.makePartialResultError checks for a preferred symbol, normally an overload group, when throwing processing unknownDisambiguation errors. - Simplify makeTopicReferenceResolutionErrorInfo and limit it to formatting the warning message. * PR Feedback: Simplify PathHierarchy+Error.swift and PathHierarchy.makePartialResultError further. * PR Feedback: - Further simplify logic for displaying unknown disambiguation warnings (cherry picked from commit 1357a2d)
Add logic to look for overload groups when emitting warnings and suggestions about ambiguous symbols. If exactly one of the ambiguous symbols is an overload group, then suggest the author simply remove the incorrect disambiguation instead of selecting a different disambiguation hash.
rdar://126382989
Summary
Today when an author links to a page using an invalid disambiguation hash, DocC emits a warning similar to this listing all of the valid disambiguation hashes:
However, we expect that most of the time authors need to specify disambiguation hashes when they are linking directly to one member of a set of overloaded symbols. (Symbols that have the same parameters but different types).
Therefore, this PR changes the diagnostic logic for ambiguous symbols to emit a warning similar to this instead:
Now DocC will encourage writers to use simpler paths when possible, allowing readers to navigate to overload group pages.
We might consider adding logic in a follow-on PR to emit warnings for valid links that use disambiguation hashes unnecessarily.
Dependencies
None
Testing
Steps:
--enable-experimental-overloaded-symbol-presentation
command line argument to enable the experimental overloads feature flag.Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded[ ] Updated documentation if necessary