I wanna generate arrow-optics lens for data class ...
# arrow
l
I wanna generate arrow-optics lens for data class by using plugin https://arrow-kt.io/docs/optics/lens/#generating-lenses It makes lens variable well, but Android Studio can not find the variable
Copy code
@optics
data class Company(val name: String, val address: Address) {
	companion object
}
Copy code
// Auto generated code

public inline val com.example.contextreceiversample.Company.Companion.name: arrow.optics.Lens<com.example.contextreceiversample.Company, kotlin.String> inline get() = arrow.optics.Lens(
  get = { company: com.example.contextreceiversample.Company -> company.`name` },
  set = { company: com.example.contextreceiversample.Company, value: kotlin.String -> company.copy(`name` = value) }
)

public inline val com.example.contextreceiversample.Company.Companion.address: arrow.optics.Lens<com.example.contextreceiversample.Company, com.example.contextreceiversample.Address> inline get() = arrow.optics.Lens(
  get = { company: com.example.contextreceiversample.Company -> company.`address` },
  set = { company: com.example.contextreceiversample.Company, value: com.example.contextreceiversample.Address -> company.copy(`address` = value) }
)
I tried to reference
Company.name
, but Android Studio can not find it. Still, build and run normally. How can I solve this problem? I had tried
Invalid Caches and Restart
.
s
That is an issue of KSP, and you need to make Android Studio (or IntelliJ) aware of your generated KSP code. https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code
l
Ah, so thank you!! I modify the code snippet like below
Copy code
applicationVariants.all { variant ->
		kotlin {
			sourceSets {
				main.kotlin.srcDirs += "build/generated/ksp/${variant.name}/kotlin"
			}
		}
	}