-
Notifications
You must be signed in to change notification settings - Fork 3
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
Resolve multi-preview annotations in other modules #69
Conversation
snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/LocalePreviews.kt
Show resolved
Hide resolved
...ts-processor/src/main/kotlin/com/emergetools/snapshots/processor/utils/PreviewFinderUtils.kt
Show resolved
Hide resolved
...ts-processor/src/main/kotlin/com/emergetools/snapshots/processor/utils/PreviewFinderUtils.kt
Show resolved
Hide resolved
.../snapshots-processor/src/main/kotlin/com/emergetools/snapshots/processor/PreviewProcessor.kt
Outdated
Show resolved
Hide resolved
// We can assume these are multi-preview annotations. | ||
return annotationClassDecls | ||
.filter { | ||
it.annotations.any { annotation -> |
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.
Will this get annotations that are transitively added to this annotation? Ex:
@Preview(...)
annotation class Class1
@Class1
annotation class Class2
Will it pick up Class2 as having a preview annotation? If not can we do this in a loop building up what annotations are eligible to make a preview?
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.
We had discussed v1 of this only supporting a single level of Multipreview nesting (and checked with clients that that was ok), so that means we're only intending to cover your first example here.
But, if it's easy enough to add, we might as well add support for all potential cases here.
} | ||
} | ||
} | ||
.filter { it.classKind == ClassKind.ANNOTATION_CLASS } |
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.
My only potential nit here would be to move this up above .filter { it.annotations.count() > 0 }
, that way we're only working with annotation class declarations at that point, and don't risk running annotation.count()
and getClassDeclarationByName
on classes that are not annotation classes.
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.
Don't think that's possible since it
is a KSDeclaration
for the sequence of symbols with annotations, we haven't mapped to the annotation class declarations yet.
I think the filter is actually redundant since we are flatmap'ing to the annotation class declaration, so it should only be a sequence of annotation classes at this point, but it does make it a little more readable so I'll leave it in.
snapshots/sample/app/src/main/kotlin/com/emergetools/snapshots/sample/ui/TextRowWithIcon.kt
Show resolved
Hide resolved
@@ -25,15 +26,17 @@ fun TextRowWithIcon( | |||
|
|||
@Preview | |||
@FontScalePreviews | |||
@LocalePreviews |
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.
Ran locally and this outputted 5 previews, matching what I expected. Awesome job!
Might be good for us to add a test case in snapshots-processor-test
for this, but inherently that's a bit tough as it currently relies on a single /input
directory producing outputs. Maybe adding an input2
or submodule
containing a multipreview with an import/usage in input
would produce a valid 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.
Yea testing this has proven to be difficult, I'll keep trying some things.
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
Resolves multi-previews that are defined in other modules by:
@Preview
annotation and assumes they are used for multi-previewProduces the following sample output: