Consider hiding the merged interface
Closed this issue · 3 comments
Right now the API for components looks like this:
@Component
@MergeComponent
@SingleInAppScope
abstract class AppComponent(
@get:Provides val input: Input,
) : AppComponentMerged
We could turn it into the follow and generate the real component ourselves:
@MergeComponent
@SingleInAppScope
abstract class AppComponent(
@get:Provides val input: Input,
)
That saves a step in the setup and avoids running an initial build to generate AppComponentMerged
. The downside is that the IDE doesn't know that AppComponent
will implement the contributed components and inheritance in the IDE doesn't work properly. The inheritance chain from:
ContributedComponent -> AppComponentMerged -> AppComponent
To this:
ContributedComponent -> GeneratedAppComponent
^
AppComponent --------/
There is no connection between ContributedComponent
and AppComponent
.
I personally prefer giving the IDE more power and add the interface manually.
Note that the situation for Anvil itself is different, because it's able to modify source code.
This pattern + exposing optional shims has worked well for us in my anvil-ksp fork with dagger components
Note that the situation for Anvil itself is different, because it's able to modify source code.
I'm curious: Would a compiler plugin be able to automatically add the Merged
component as a base type from which to inherit? I.e., provide the best of both worlds?
That's how anvil's original plugin worked but would require running in FIR to work in K2. KSP will also not run FIR plugins.