Runnable (@NotNull CommitTask task, boolean synchronously, @NotNull PsiDocumentManagerBase documentManager) { Document document = task.document; Project project = task.project; List<BooleanRunnable> finishProcessors = new SmartList<>(); List<BooleanRunnable> reparseInjectedProcessors = new SmartList<>(); FileViewProvider viewProvider = documentManager.getCachedViewProvider(document); if (viewProvider == null) { finishProcessors.add(handleCommitWithoutPsi(task, documentManager)); } else { // while we were messing around transferring things to background thread, the ViewProvider can become obsolete // when e.g. virtual file was renamed. store new provider to retain it from GC task.cachedViewProvider = viewProvider; for (PsiFile file : viewProvider.getAllFiles()) { FileASTNode oldFileNode = file.getNode(); if (oldFileNode == null) { throw new AssertionError("No node for " + file.getClass() + " in " + file.getViewProvider().getClass() + " of size " + StringUtil.formatFileSize(document.getTextLength()) + " (is too large = " + SingleRootFileViewProvider .isTooLargeForIntelligence(viewProvider.getVirtualFile(), (long)document.getTextLength()) + ")"); } ProperTextRange changedPsiRange = ChangedPsiRangeUtil .getChangedPsiRange(file, document, task.myLastCommittedText, document.getImmutableCharSequence()); if (changedPsiRange != null) { BooleanRunnable finishProcessor = doCommit(task, file, oldFileNode, changedPsiRange, reparseInjectedProcessors, documentManager); finishProcessors.add(finishProcessor); } } } return () -> { if (project.isDisposed()) { return; } boolean success = documentManager.finishCommit(document, finishProcessors, reparseInjectedProcessors, synchronously, task.reason); if (synchronously) { assert success; } if (synchronously || success) { assert !documentManager.isInUncommittedSet(document); } if (!success && viewProvider != null && viewProvider.isEventSystemEnabled()) { // add document back to the queue commitAsynchronously(project, documentManager, document, "Re-added back", task.myCreationModality, viewProvider); } }; }