Adding quick fix or intention to existing problems fround through other inspections

Answered

Is there a way to add quick fix or intentions from a plugin? For example:


I'd like to add either a quickfix or an intention that perhaps shows up under "More actions".
Current I'm using the `errorQuickFixProvider` extension point but that only seems to work with syntatical errors that the IDE finds. I'd like my intention/quickfix to show up for all the problems on the page.

Is there some API that I could use to do this?

Thanks!

3
6 comments

Hi,

Unfortunately, there is no API that would allow achieving it.

1

I managed to get it working using the HighlightInfoFilter extension point - I understand this is meant for filtering out highlights but I'm using it to mutate the highlightInfo and register a quickfix using `highlightInfo#registerFix`. Do you see any problems with using it this way? Appreciate any comments, and thanks for responding!

0

Using API in an unintentional way is a bad idea. Its behavior may be changed in a way that may break your code, e.g., HighlightInfo may become immutable by wrapping it after it is created/registered.

1

Noted, thanks! Is there any other way I could get a list of all the problems in the current file to do something with them? Perhaps maybe I could Gutter Icons with actions for each problem, or just show them in a separate Pane with the actions I want.

0

Is there any update in API to do it now ?

I achieved it that way, which is clearly ugly

public class ExceptionHighlightInfoFilter implements HighlightInfoFilter {
    @Override
    public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile file) {
       if (file == null) return true;

       if (highlightInfo.getDescription() != null &&
             highlightInfo.getDescription().toLowerCase().contains("exception")) {

          QuickFixAction.registerQuickFixAction(highlightInfo, new AddExceptionTransactionIntention());
       }

       return true;
    }
}

 

I tried to use following code, but registerErrorQuickFix is never get executed

Inspired from com.intellij.codeInsight.daemon.impl.analysis.JavaErrorQuickFixProvider

public class AddExceptionTransactionFix implements ErrorQuickFixProvider {

	@Override
	public void registerErrorQuickFix(@NotNull final PsiErrorElement errorElement, final HighlightInfo.@NotNull Builder info) {
		System.out.println(errorElement.getErrorDescription());
		// ...
	}
}

 

Declared that way

<idea-plugin>
    <depends>com.intellij.modules.platform</depends>
    <depends>com.intellij.java</depends>
    <depends>JavaScript</depends>
    <depends>com.intellij.database</depends>

    <extensions defaultExtensionNs="com.intellij">
	    <errorQuickFixProvider implementation="com.my.plugin.AddExceptionTransactionFix"/>
<!--	    <daemon.highlightInfoFilter implementation="com.my.plugin.ExceptionHighlightInfoFilter"/>-->
    </extensions>
</idea-plugin>

 

0

Please sign in to leave a comment.