idea-plugin / arrow.meta.ide.dsl.application / ApplicationSyntax / replaceAppService


open fun <A : Any> MetaIde.replaceAppService(service: Class<A>, instance: (A?) -> A): ExtensionPhase

replaces an application service with instance. In this example this Annotator needs a different instance for MyService than what is currently provided - see our example in addAppService.

import arrow.meta.ide.MetaIde
import arrow.meta.ide.IdePlugin
import arrow.meta.ide.invoke
import arrow.meta.plugins.higherkind.isHigherKindedType
import com.intellij.lang.annotation.Annotator
import com.intellij.openapi.components.ServiceManager
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.utils.addToStdlib.safeAs

val MetaIde.logAnnotator: IdePlugin
  get() = "Log Function Annotator" {
      replaceAppService( { myOldService ->
        object : MyService {
          override fun printLn(ktclass: KtClass): Unit =
            println("Log ${}, which ${if (isHigherKindedType(ktclass)) "is" else "is not"} a Higher Kinded Type.")
        annotator = Annotator { element, holder ->
          element.safeAs<KtClass>()?.let { f ->

interface MyService {
  fun printLn(f: KtClass): Unit

The same technique applies for every service in the plugin dependencies.

See Also


Do you like Arrow?

Arrow Org