Highlight a file with errors during inspection

Answered

Hi everyone,

I am writing a plugin that runs a set of code inspections when a project is first opened. This means all inspections are being run from InspectionEngine.runInspectionOnFile in a StartupActivity class. When these inspections complete, I need to highlight all files that contain errors (preferably underline them with red).

How would I do this?

Thanks!

0
5 comments

Where do want to highlight all files containing errors? PS: Please make sure to provide ability to cancel this automatic run of heavy activity on startup.

0

Sorry for the delayed response.

I would like the files in the project view (left panel) to have the red underlines.

0

You need to provide an instance of EP com.intellij.problemFileHighlightFilter where you implement Condition<VirtualFile> and return true for all files which should be error-highlighted.

0

Hi Yann,

Thanks for the response. I finally had some time to try this out, but unfortunately no files are being highlighted when my StartupActivity class finishes, and at no point is the value method printing anything. Here is what I have:

plugin.xml has this line:

<problemFileHighlightFilter implementation="org.intellij.privacyhelper.codeInspection.highlighters.PrivacyErrorHighlighter"/>

PrivacyErrorHighligher.java:

package org.intellij.privacyhelper.codeInspection.highlighters;

import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;

import java.util.List;

public class PrivacyErrorHighlighter implements Condition<VirtualFile> {
public static List<VirtualFile> errorFiles;

@Override
public boolean value(VirtualFile file) {
System.out.println("We are checking " + file.getName() + " for error");
System.out.println(errorFiles.size() + " error files");
return errorFiles.contains(file);
}
}

It doesn't seem that this EP is running since I am not seeing print statements, and no files are being highlighted.

To be clear, I need to highlight files at the end of my StartupActivity, which gets a list of problem files. I don't know at what point this EP runs. I pretty much copied what I saw in the get gauge project.

Any ideas? Thanks!

0

I need to see the full plugin's sources to determine what could be wrong.

Please note that the Highlighting Condition Filter has no relationship whatsoever to your startup activity, it will just add additional files which do have highlighting results.

0

Please sign in to leave a comment.