idea-plugin / arrow.meta.ide.dsl.editor.intention / IntentionSyntax / addIntention

addIntention

open fun IdeMetaPlugin.addIntention(intention: IntentionAction): ExtensionPhase

registers intention

open fun <K : KtElement> IdeMetaPlugin.addIntention(text: String = "", kClass: Class<K> = KtElement::class.java as Class<K>, isApplicableTo: (element: K, caretOffset: Int) -> Boolean = Noop.boolean2False, applyTo: KtPsiFactory.(element: K, editor: Editor) -> Unit = Noop.effect3, priority: Priority = PriorityAction.Priority.LOW): ExtensionPhase

This extension registers an SelfTargetingIntention. The following example renames a helloWorld function to renamed, whenever the user decides to trigger that Intention.

import arrow.meta.Plugin
import arrow.meta.ide.IdeMetaPlugin
import arrow.meta.invoke
// import com.intellij.codeInsight.intention.PriorityAction
import org.jetbrains.kotlin.psi.KtNamedFunction

//sampleStart
val IdeMetaPlugin.example: Plugin
 get() = "SampleIntention"{
  meta(
   addIntention(
    text = "Rename HelloWorld Function",
    isApplicableTo = { f: KtNamedFunction, caretOffset: Int ->
      f.name == "helloWorld"
    },
    kClass = KtNamedFunction::class.java,
    applyTo = { f, editor ->
      f.setName("renamed")
    }
   )
  )
 }
//sampleEnd

IntentionAction are generally on-demand computations, similar to AnAction, unless they’re composed with other workflows, which trigger them, automatically.

See Also

ktIntention

Do you like Arrow?

Arrow Org
<