-
Notifications
You must be signed in to change notification settings - Fork 413
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
Merge ObjC categories into docs of the extended class #466
Conversation
@@ -318,8 +318,8 @@ def self.deduplicate_declarations(declarations) | |||
|
|||
# Two declarations get merged if they have the same deduplication key. | |||
def self.deduplication_key(decl) | |||
if decl.type.swift_extensible? || decl.type.swift_extension? | |||
[decl.usr] | |||
if (decl.type.swift_extension? || decl.type.objc_category?) && !decl.extension_parent.nil? |
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.
maybe add a helper method for extension_type?
Thanks for this, Esad! Two families of questions as I digest the code: First, what’s the rationale behind computing the If so, I wonder if perhaps the regexp dance you did in your first crack at this was a better plan. It takes a lot of code in this PR to construct What do those Obj-C USRs look like? Can you provide some examples? Second, I wonder if it might make sense to unify Swift & Obj-C a bit more, e.g. I vaguely remember @jpsim saying that he has a preference for keeping Swift things and Objective-C things somewhat separate, but if he’s amenable to some judicious cross-language generalizing, it could tidy things a bit. If we are going to keep things separate, then Nice idea using the category name as a marker, BTW. |
Hi @pcantrell, thanks for your feedback! Yes, the purpose of going through all extensions to find and set the The USRs itself in Objective-C look like I'll try to refactor this back to a more simple solution, let's see how it looks. |
I've updated the PR with a simpler approach. What I really disliked about my first try was manually twiddling USRs so that they match, now I rely on extracted extended class name instead. Same method that is is used to extract the extended class name also extracts the category name, which is used for the mark. (The new approach should also merge fine with #462) |
Before merging, this will need a rebase to get rid of the merge commit |
# of the extended objc class and the category name itself, i.e. | ||
# ["NSString", "MyMethods"], nil otherwise. | ||
def objc_category_name | ||
type.objc_category? && name.split(/[\(\)]/) || nil |
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 could just be name.split(/[\(\)]/) if type.objc_category?
This warrants adding categories to an integration spec, I think |
I addressed the above PR remarks, but I'm blocked by integration specs not passing on the current master. Waiting to resolve this first before I update them. |
I like the way this ended up. Not too complicated; things makes sense. I'm dropping a few minor notes into the code, and after those I'd say it's good to merge. +1 to Sam’s comment that this warrants an addition to the specs, perhaps just a small addition to |
# of the extended objc class and the category name itself, i.e. | ||
# ["NSString", "MyMethods"], nil otherwise. | ||
def objc_category_name | ||
name.split(/[\(\)]/) if type.objc_category? |
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 name objc_category_name
implies that this returns a string, not an array — and that seems like the right behavior.
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.
Do you think I should split this method into two: one to return the category name and the other to return the extended class name? Or rename the above one to match the method signature?
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.
Now that I understand better how you’re using it, I'd suggest renaming it to make it clear that it returns two values.
@segiddins What would be the best way forward to add integration tests for the above? I tried adding some objc categories to the It seems that jazzy currently doesn't support mixed Swift/ObjC projects? Should I add a new |
Yeah, I think a new |
I've added integration specs for this feature. As pointed out in the child PR, I'm bit unsure how this workflow with 2 dependent separate repos should work. Can you merge the child PR first, so that I can point to it here and we can have CI pass on this PR? |
After integration specs pass I'll address the remaining code style issues. |
The integration specs process is a bit of a mystery to me too at times, but I merged your PR and hopefully that unblocks this merge. As you do the last little tidying work, please feel free to edit Thanks for bearing with this whole process! |
@pcantrell @segiddins I've addressed all issues we discussed above, added integration specs and rebased the PR. Let me know if you feel there's something else missing. |
I just wanted to let you know that we've rebuilt PSPDFKit docs with this patch applied and it worked fine, with categories getting merged nicely into the class docs. |
I'd love to get this merged! It's only blocked on the CI failing. It looks like the integration specs are building Moya with a slightly different version of AF that the expected output recorded. I have to speed-prep a talk I'm doing tonight, but @esad (or anyone else), if you have a chance to update the expected output, I can approve the merges. |
@pcantrell As soon as https://github.com/realm/jazzy-integration-specs/pull/11/commits in jazzy-integration-specs gets merged I will update this PR |
@pcantrell Looks like the specs are passing again! |
Merging! Hooray! Thanks for all the hard work and the patience. |
Merge ObjC categories into docs of the extended class
This is great! Thanks @esad for your hard work, and @pcantrell & @segiddins for the reviews! 👍 |
This is work-in-progress on #457.
The idea was to annotate
SourceDeclaration
s representing extensions (both swift and objc) with a link to the parent declaration that is being extended, and then use this as a deduplication key. This kind of unifies the existing approach for swift extensions with new behaviour needed for objc classes/categories.Furthermore, we found it nice to have category name appear as a mark of the merged methods.