diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index e57161d0a3df..54f68c7416d5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -502,12 +502,32 @@ public class FileBasedIndexImpl extends FileBasedIndex { @Override public PersistentHashMap> create() { try { - return ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable>, IOException>() { - @Override - public PersistentHashMap> compute() throws IOException { - return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + // this factory method may be called either on index creation from dispatch thread, or on index rebuild + // from arbitrary thread and under some existing progress indicator + final ProgressManager progressManager = ProgressManager.getInstance(); + final ProgressIndicator currentProgress = progressManager.getProgressIndicator(); + if (currentProgress == null && ApplicationManager.getApplication().isDispatchThread()) { + return progressManager.runProcessWithProgressSynchronously( + new ThrowableComputable>, IOException>() { + @Override + public PersistentHashMap> compute() throws IOException { + return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + } + }, LangBundle.message("compacting.indices.title"), false, null); + } + if (currentProgress != null) { + // reuse existing progress indicator if available + currentProgress.pushState(); + currentProgress.setText(LangBundle.message("compacting.indices.title")); + } + try { + return createIdToDataKeysIndex(indexId, keyDescriptor, storage); + } + finally { + if (currentProgress != null) { + currentProgress.popState(); } - }, LangBundle.message("compacting.indices.title"), false, null); + } } catch (IOException e) { throw new RuntimeException(e);