Skip to content
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

Consider hiding the merged interface #8

Open
vRallev opened this issue Sep 4, 2024 · 3 comments
Open

Consider hiding the merged interface #8

vRallev opened this issue Sep 4, 2024 · 3 comments
Labels
discussion Feedback requested

Comments

@vRallev
Copy link
Contributor

vRallev commented Sep 4, 2024

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.

@vRallev vRallev added the discussion Feedback requested label Sep 4, 2024
@ZacSweers
Copy link
Contributor

This pattern + exposing optional shims has worked well for us in my anvil-ksp fork with dagger components

@bddckr
Copy link

bddckr commented Sep 15, 2024

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?

@ZacSweers
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Feedback requested
Projects
None yet
Development

No branches or pull requests

3 participants