Intention action: how to create a submenu with custom actions?

Answered

Hi,

I'm trying to add an intention action with a submenu where the user can choose a proper option based on their context. As I can see for the Kotlin some actions has a submenu with "fix all" / "suppress" options.

Is there any way to create an action with custom submenu options list?

0
7 comments

Hi,

See com.intellij.codeInsight.intention.IntentionActionWithOptions.

0

Are you sure it works in the context of quick fixes added to the annotation builder?

I tried to use `IntentionActionWithOptions`, but it didn't work for me.

0

I didn't implement this API, but looking at its docs, it should work with quick fixes.

Please share what you tried to do.

0

Sure, I created an action that extends "IntentionActionWithOptions" and passed an instance when setting a fix to the annotation builder

builder.withFix(DCMWrapInIntention(action, priority))

Unfortunately, while the action appeared in the IDE, the options are not shown when the action is selected.

0

Karol Lewandowski or you need a more detailed example?

0

It seems to be available for third-party plugins since 2023.1.

You also have to implement:

@Override
public @NotNull CombiningPolicy getCombiningPolicy() {
return CombiningPolicy.IntentionOptionsOnly;
}

 

0

Thanks, I see how it can be implemented for the annotation builder now.

But looks like it does not work for "<intentionAction>" declared in the plugins.xml. Can you suggest any solution here?

0

Please sign in to leave a comment.