void (@NotNull Sdk sdk, @NotNull Disposable parentDisposable, @NotNull Runnable runnable) { final Application app = ApplicationManager.getApplication(); VirtualFileManager.getInstance().addAsyncFileListener(new AsyncFileListener() { @Nullable @Override public ChangeApplier prepareChange(@NotNull List<? extends @NotNull VFileEvent> events) { if (sdk instanceof Disposable && Disposer.isDisposed((Disposable)sdk)) { throw new AlreadyDisposedException("SDK " + sdk + " (" + sdk.getClass() + ") is already disposed"); } final Set<VirtualFile> roots = getPackagingAwareSdkRoots(sdk); if (roots.isEmpty()) return null; allEvents: for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent || event instanceof VFilePropertyChangeEvent) continue; // In case of create event getFile() returns null as the file hasn't been created yet VirtualFile parent = null; if (event instanceof VFileCreateEvent) { parent = ((VFileCreateEvent)event).getParent(); } else { VirtualFile file = event.getFile(); if (file != null) parent = file.getParent(); } if (parent != null && roots.contains(parent)) { InterpreterChangeEvents.LOG.debug("Interpreter change in " + parent + " indicated by " + event + " (all events: " + events + ")"); app.executeOnPooledThread(runnable); break allEvents; } } // No continuation in write action is needed return null; } }, parentDisposable); }