idea-plugin / arrow.meta.ide.dsl.editor.intention / IntentionSyntax / addIntention
open fun
MetaIde
.addIntention(intention: IntentionAction): ExtensionPhase
registers intention
open fun <K : KtElement>
MetaIde
.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.ide.IdePlugin
import arrow.meta.ide.MetaIde
import arrow.meta.ide.invoke
// import com.intellij.codeInsight.intention.PriorityAction
import org.jetbrains.kotlin.psi.KtNamedFunction
import com.intellij.openapi.editor.Editor
//sampleStart
val MetaIde.example: IdePlugin
get() = "SampleIntention"{
meta(
addIntention(
text = "Rename HelloWorld Function",
isApplicableTo = { f: KtNamedFunction, caretOffset: Int ->
f.name == "helloWorld"
},
kClass = KtNamedFunction::class.java,
applyTo = { f: KtNamedFunction, editor: 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
Do you like Arrow?
✖