https://kotlinlang.org logo
#arrow
Title
# arrow
l

Lukasz Kalnik

07/08/2022, 2:20 PM
I added to my build.gradle.kts:
Copy code
plugins {
    id("com.google.devtools.ksp")
}

dependencies {
    implementation("io.arrow-kt:arrow-optics:$arrowVersion")
    ksp("io.arrow-kt:arrow-optics-ksp-plugin:$arrowVersion")
}
I have also annotated my data classes:
Copy code
@optics
data class ConnectorWithSensors(
    val connector: Connector,
    val sensors: List<ItemSelection>,
) {
    companion object
}

@optics
data class ItemSelection(
    val id: String,
    val selected: Boolean,
) : {
    companion object
}
However I cannot access the extensions generated on companion object like
ConnectorWithSensors.sensors
.
KSP version 1.6.10-1.0.2
Arrow version 1.1.2
message has been deleted
a

Alejandro Serrano Mena

07/08/2022, 3:04 PM
my suggestion would be to check: 1. does
./gradlew build
work? if so, the KSP plugin is working 2. if the problem is only in the IDE, this means you need to add the generated sources as explained here. My suggestion is to add the following then to your gradle file
Copy code
plugins {
   // ...
   idea
}

idea {
   module {
      // Not using += due to <https://github.com/gradle/gradle/issues/8749>
      sourceDirs = sourceDirs + file("build/generated/ksp/main/kotlin") // or tasks["kspKotlin"].destination
      testSourceDirs = testSourceDirs + file("build/generated/ksp/test/kotlin")
      generatedSourceDirs = generatedSourceDirs + file("build/generated/ksp/main/kotlin") + file("build/generated/ksp/test/kotlin")
   }
}
l

Lukasz Kalnik

07/08/2022, 3:18 PM
So one problem was (which I didn't mention) that my data classes were
internal
. So ksp complained that "public member exposes internal type" in the generated code. After making the data classes public the project builds, however the extension property
ConnectorWithSensors.sensors
is still red. I will try to import the generated sources as you suggested.
Ok, that worked! Thanks so much for your help! 🙏
message has been deleted
🎉 2
On the other hand, it looks like importing the generated sources in a project with build variants doesn't work correctly (it breaks the cache): https://kotlinlang.slack.com/archives/C013BA8EQSE/p1657364970659239?thread_ts=1657364826.656609&amp;cid=C013BA8EQSE So it looks like for now there is no way to have proper IDE support for optics on Android...
4 Views