diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index cf9a0e8c8d2f..93ce6f2c0d53 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1038,51 +1038,66 @@ public class FileBasedIndex implements ApplicationComponent { } } - // returns false if doc was not indexed because the file does not fit in scope - private boolean indexUnsavedDocument(final Document document, final ID requestedIndexId, Project project, GlobalSearchScope filter) throws StorageException { - final VirtualFile vFile = myFileDocumentManager.getFile(document); - if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { - return true; - } - if (filter != null && !filter.accept(vFile)) { - return false; - } - final PsiFile dominantContentFile = findDominantPsiForDocument(document, project); - - DocumentContent content; - if (dominantContentFile != null && dominantContentFile.getModificationStamp() != document.getModificationStamp()) { - content = new PsiContent(document, dominantContentFile); - } - else { - content = new AuthenticContent(document); - } - - final long currentDocStamp = content.getModificationStamp(); - if (currentDocStamp != myLastIndexedDocStamps.getAndSet(document, requestedIndexId, currentDocStamp).longValue()) { - final FileContent newFc = new FileContent(vFile, content.getText(), vFile.getCharset()); - - if (dominantContentFile != null) { - dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, true); - newFc.putUserData(PSI_FILE, dominantContentFile); - } - - if (content instanceof AuthenticContent) { - newFc.putUserData(EDITOR_HIGHLIGHTER, document instanceof DocumentImpl - ? ((DocumentImpl)document).getEditorHighlighterForCachesBuilding() : null); - } - - if (getInputFilter(requestedIndexId).acceptInput(vFile)) { - newFc.putUserData(PROJECT, project); - final int inputId = Math.abs(getFileId(vFile)); - getIndex(requestedIndexId).update(inputId, newFc); - } - - if (dominantContentFile != null) { - dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, null); - } - } +// returns false if doc was not indexed because the file does not fit in scope +private boolean indexUnsavedDocument(final Document document, final ID requestedIndexId, final Project project, + GlobalSearchScope filter) throws StorageException { + final VirtualFile vFile = myFileDocumentManager.getFile(document); + if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; } + if (filter != null && !filter.accept(vFile)) { + return false; + } + final PsiFile dominantContentFile = findDominantPsiForDocument(document, project); + + final DocumentContent content; + if (dominantContentFile != null && dominantContentFile.getModificationStamp() != document.getModificationStamp()) { + content = new PsiContent(document, dominantContentFile); + } + else { + content = new AuthenticContent(document); + } + + final long currentDocStamp = content.getModificationStamp(); + if (currentDocStamp != myLastIndexedDocStamps.getAndSet(document, requestedIndexId, currentDocStamp).longValue()) { + final Ref exRef = new Ref(null); + ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { + public void run() { + try { + final FileContent newFc = new FileContent(vFile, content.getText(), vFile.getCharset()); + + if (dominantContentFile != null) { + dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, true); + newFc.putUserData(PSI_FILE, dominantContentFile); + } + + if (content instanceof AuthenticContent) { + newFc.putUserData(EDITOR_HIGHLIGHTER, document instanceof DocumentImpl + ? ((DocumentImpl)document).getEditorHighlighterForCachesBuilding() : null); + } + + if (getInputFilter(requestedIndexId).acceptInput(vFile)) { + newFc.putUserData(PROJECT, project); + final int inputId = Math.abs(getFileId(vFile)); + getIndex(requestedIndexId).update(inputId, newFc); + } + + if (dominantContentFile != null) { + dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, null); + } + } + catch (StorageException e) { + exRef.set(e); + } + } + }); + final StorageException storageException = exRef.get(); + if (storageException != null) { + throw storageException; + } + } + return true; +} public static final Key PSI_FILE = new Key("PSI for stubs"); public static final Key EDITOR_HIGHLIGHTER = new Key("Editor"); @@ -1257,7 +1272,21 @@ public class FileBasedIndex implements ApplicationComponent { final UpdatableIndex index = getIndex(indexId); assert index != null; - index.update(inputId, currentFC); + final Ref exRef = new Ref(null); + ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { + public void run() { + try { + index.update(inputId, currentFC); + } + catch (StorageException e) { + exRef.set(e); + } + } + }); + final StorageException storageException = exRef.get(); + if (storageException != null) { + throw storageException; + } ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { if (file.isValid()) {