-
Notifications
You must be signed in to change notification settings - Fork 128
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
Improve heuristic for extending return value with "on failure" info #1096
Improve heuristic for extending return value with "on failure" info #1096
Conversation
…about Objective-C return values for bridged API rdar://139432674
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.
Overall it's looking good, there's some small typos and I've got a question on the implementation of the pattern matching.
Sources/docc/DocCDocumentation.docc/documenting-api-with-different-language-representations.md
Outdated
Show resolved
Hide resolved
Sources/docc/DocCDocumentation.docc/documenting-api-with-different-language-representations.md
Outdated
Show resolved
Hide resolved
Sources/docc/DocCDocumentation.docc/documenting-api-with-different-language-representations.md
Outdated
Show resolved
Hide resolved
5fdbf78
to
40724b1
Compare
…d return value documentation. Also, rephrase note as tip
40724b1
to
d5aea7f
Compare
@swift-ci please test |
The requested changes have been made
@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.
The documentation looks great.
I left a comment about using Regex
instead of NSRegularExpression
, but I don't think that should block merge if you don't think it's relevant.
/// These words only match at word boundaries or when surrounded by single backticks ("`"). | ||
/// | ||
/// This is used as a heuristic to give an indication if the return value documentation possibly documents what happens when an error occurs. | ||
private let returnValueDescribesErrorRegex = try! NSRegularExpression(pattern: "(\\b|`)(error|fail(ure)?s?|nil|null)(\\b|`)", options: .caseInsensitive) |
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.
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.
Regex
is available as of macOS 13 and we currently support macOS 12 (bumped very recently).
We probably could bump to macOS 13 but I didn't do that for this fix because this regular expression wasn't all that complicated.
I think it's relevant and it would make the code more readable but it would require bumping the supported platform versions. Still, I think that it's a topic that's worth revisiting in a separate PR. Then we could update all the regular expressions at the same time. |
Bug/issue #, if applicable: rdar://139465971
Summary
This improves the heuristic for when DocC extends authored return value documentation with "On failure, ..." information for Objective-C API that corresponds to Swift API that throws errors.
Dependencies
None.
Testing
In a mixed Swift and Objective-C project, add a Swift method that returns a value and throws errors.
Give a basic description of the return value.
Preview the documentation and navigate to the Objective-C representation of that method.
nil
."Rephrase the return value documentation to something like:
nil
instead."nil
if something goes wrong."Preview the documentation again and navigate to the Objective-C representation of that method.
nil
."Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded