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
Migrate compiler plugin to KSP #57
Comments
Instead of generating extension properties/functions (which IIRC aren't handled well in JS), it might also be possible to generate an entirely new class that wraps that just wraps the JVM class: // original class
class MyClass {
suspend fun myFun(): String { … }
}
// NativeCoroutines-generated
class MyClassNative(private val delegate: MyClass) {
suspend fun myFun = delegate.myFun()
fun myFunNative() =
nativeSuspend { delegate.myFun() }
} Consumers would have to manually convert |
Hmm alright didn't know about any limitations with extensions in JS. I am actually not a big fan of such wrapper classes. Mainly because:
I guess it would probably need some more code to get a single wrapper object as well, else you'll be creating a lot of wrapper objects in the client code. How exactly are extension functions handled in JS? |
In Kotlin/JS, you need to annotate everything with
|
On further inspection -- it looks like you can The way this gets exposed though is by converting the receiver to a parameter. This can cause naming collisions: class MyClass {
suspend fun myFun(): String { … }
}
@JsExport
fun MyClass.myFunNative() = nativeSuspend { this.myFun() }
// will generate a method that can be called in JS using `myFunNative(myClassInstance)`
class MyOtherClass {
suspend fun myFun(): String { … }
}
@JsExport
fun MyOtherClass.myFunNative() = nativeSuspend { this.myFun() }
// will generate conflicting method that can be called in JS using `myFunNative(myOtherClassInstance)` This likely means that we need to use |
This would be fantastic. I've been really enjoying this plugin but chasing down all the recursive crashes when I switch from Android to iOS builds are really frustrating. Let me know if there is anything I can do to help push this along. |
If the compiler plugin is migrated to KSP we won't be able to modify any of the source code, making #63 impossible. |
When the current compiler plugin was created KSP didn't support Kotlin/Native and a custom compiler plugin would allow us to modify classes instead of creating extension functions (which seemed a great idea at the time).
However the current compiler plugin has some issues:
Using KSP would solve all these issues. The only downside being that we can no longer modify the classes and would need to generate extension properties/functions, which might not be exposed to ObjC/Swift in the same way.
The text was updated successfully, but these errors were encountered: