Clearing annotator results for files that are not currently open

Answered

Our plugin runs an analysis that's pretty expensive, so we don't keep it updated all the time and problem annotations resulting from it are cleared when a file is closed. The analysis runs asynchronously in a background process and we implement an ExternalAnnotator to report the results. We trigger updates (when a file is closed or when a new result is available) via

DaemonCodeAnalyzer.getInstance(project).restart(psiFile);

on the affected file.

The problem is, when a file is already closed our annotator doesn't seem to get called anymore. Usually, the annotator's apply method is called shortly after the restart call but on closed files, no call to apply happens.

It's not a huge issue since the "Current File" tab of the problems tool window is cleared but the problems still show up in the "Project Errors" tab where they might go stale.

0
4 comments

Yes, ExternalAnnotator.apply() is not called when the file is closed, by design (to reduce CPU usage and other resources). If you really keen on clearing some internal data structures as soon as the file is closed, you might want to use com.intellij.openapi.editor.event.EditorFactoryListener#editorReleased listener for that

0

Not sure if I understood correctly but I just tried replacing the FileEditorManagerListener I used previously with an EditorFactoryListener that clears our plugin's annotation store and calls restart on the DaemonCodeAnalyzer and it does not look like anything's changed. (The annotator doesn't get called in that case either.) Or did you mean something else by "clearing some internal data structures"?

0

If the file is closed, the external annotators for that file won't be called anymore. To re-run external annotators and refresh the file status you need to open the file again.

0

I see. That's unfortunate but thanks for the help!

0

Please sign in to leave a comment.