idea-plugin / arrow.meta.ide.dsl.editor.lineMarker / LineMarkerSyntax / addLineMarkerProvider

addLineMarkerProvider

open fun <A : PsiElement> MetaIde.addLineMarkerProvider(transform: (PsiElement) -> A?, lineMarkerInfo: (a: A) -> LineMarkerInfo<*>?, slowLineMarker: (a: A) -> LineMarkerInfo<*>? = Noop.nullable1()): ExtensionPhaseopen fun <A : PsiElement> MetaIde.addLineMarkerProvider(icon: Icon, transform: (PsiElement) -> A?, message: (element: A) -> String = Noop.string1(), placed: Alignment = GutterIconRenderer.Alignment.RIGHT, navigate: (event: MouseEvent, element: PsiElement) -> Unit = Noop.effect2, clickAction: AnAction? = null): ExtensionPhase

Due tu performance reason’s it is advised that A is a leaf element (e.g: Psi(Identifier)) and not composite PsiElements such as KtClass. The identifying PsiElement of the latter is the class name. The PsiViewer Plugin may help to verify that A is a leaf element, by observing the tree structure of the PsiElement. Nonetheless, IntelliJ will automatically send warnings during the runIde gradle task, if an implementation doesn’t comply with this premise.

//Unresolved: arrow.meta.ide.plugins.optics.opticsIdePlugin

See Also

com.intellij.codeInsight.daemon.LineMarkerProvider

open fun <A : PsiNameIdentifierOwner> MetaIde.addLineMarkerProvider(icon: Icon, transform: (PsiElement) -> A?, composite: Class<A>, message: DescriptorRenderer.Companion.(A) -> String = Noop.string2(), placed: Alignment = GutterIconRenderer.Alignment.RIGHT, navigate: (event: MouseEvent, element: PsiElement) -> Unit = Noop.effect2, clickAction: AnAction? = null): ExtensionPhase

addLineMarkerProvider is a convenience extension, which registers the Leaf element of a composite PsiElement A e.g.: KtClass and circumvents effort’s to find the right PsiElement. In addition, plugin developer’s can compose sophisticated messages, as the whole scope of A can be exploited.

import arrow.meta.ide.IdePlugin
import arrow.meta.ide.MetaIde
import arrow.meta.ide.resources.ArrowIcons
import arrow.meta.ide.invoke
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
import org.jetbrains.kotlin.utils.addToStdlib.safeAs

val MetaIde.descriptorLineMarker: IdePlugin
  get() = "Render Descriptor Plugin" {
    meta(
      addLineMarkerProvider(
        transform = { e: PsiElement -> e.safeAs() },
        composite = KtNamedFunction::class.java,
        icon = ArrowIcons.ICON2,
        message = { f ->
          HTML.withOptions { // check out DescriptorRenderer's companion for more options
            unitReturnType = true // renders Unit Type
            classifierNamePolicy = classifierNamePolicy() // define your own policies
            parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
          }.let { renderer ->
            f.resolveToDescriptorIfAny()?.let(renderer::render) ?: "Unresolved Descriptor"
          }
        }
      )
    )
  }

Parameters

composite - In Contrast, lineMarkers constructed without this parameter have a clearly constrained message.

message - you may use a DescriptorRenderer for rendering descriptors see descriptorRender

Do you like Arrow?

Arrow Org
<