Saving a file no more trigger local inspection in Intellij 15

Hi guys,

The SonarLint inspection currently works only at filesystem level (ie reading Thats why In the inspection we are checking status of the document (does it contains unsaved changes) to decide if analysis will be executed or not. If not executed we return 0 problems.

- user start typing some code
- local inspection triggered -> no issue since file is not written to disk
- user force save (Ctrl + S)
- local inspection triggered -> SonarLint issues appear

It was far from being perfect (issues were constantly showing/hidding) but was acceptable since there was a consistent way to see your issues => Ctrl + S

The problem with IntelliJ 15 seems that inpections are still trigerred when user type some code, but no more when user hits Ctrl + S... It means inspections are nearly always executed when file is out of sync with filesystem. And as a result it is very hard to make SonarLint issues appear. Even closing then reopening the file don't trigger inspection.

Do you confirm my analysis (that there is a change in behavior of inspection execution in IntelliJ 15)?

Do you have an idea of how we can solve this problem? I would like to avoid forcing a sync of the file each time the inspection is triggered (like is done in Checkstyle plugin) to not kill IntelliJ optimization effort.




Hello Julien,

when (not how) would you like to trigger inspection, ideally?


Hello Imants,

In a perfect world I would like the inspection to be triggered each time file is synchronized to disk (and only at that time to not remove problems too eagerly):

- user start typing, file is out of sync so my inspection is skipped
- at some point IntelliJ decides to write file to disk (or the user force the sync using Ctrl + S) => trigger my inspection
- then user continue to type, file is again out of sync, don't call my inspection and try to keep problems as far as possible (only removing problems in currently edited line / statement)

Note that I also manage to force sync in my inspection using:

  public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) {
    final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
        new Runnable() {
          public void run() {
        }, ModalityState.NON_MODAL

but as I said I understand it will probably be a major performance issue for IntelliJ users not having a very fast hard disk (works fine on my box with SSD :) ).


why not trigger inspection manually via a user action?

users could assign shortcuts and invoke inspection whenever they like.

another possibility is put this in a StartupActivity  :

VirtualFileManager.getInstance().addVirtualFileListener(new CustomVirtualFileAdapter(project));

class CustomVirtualFileAdapter extends VirtualFileAdapter{

    public void contentsChanged(@NotNull VirtualFileEvent event) {


The point of SonarLint versus old SonarQube plugin attempt is to offer on the fly analysis. Having a manual user action to trigger analysis is already supported: this is global inspection. But we beleive that having on the fly inspection is much more valuable.


I think the original problem is that your inspection works only with files on disk. The IntelliJ IDEA framework does not provide any guarantees for when the files will (or will not) be saved to disk. The correct solution is to get the contents of the files through the IntelliJ IDEA document API.


Please sign in to leave a comment.