From eebf87db276c1e13a7d05434bcd6447d3cd168a5 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 8 Oct 2009 15:25:32 +0400 Subject: [PATCH] consider GlobalSearchScope when indexing unsaved docs --- .../com/intellij/util/indexing/FileBasedIndex.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 c38046e527..57fcf73186 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -549,7 +549,7 @@ public class FileBasedIndex implements ApplicationComponent { try { checkRebuild(indexId, false); myChangedFilesUpdater.forceUpdate(filter); - indexUnsavedDocuments(indexId, project); + indexUnsavedDocuments(indexId, project, filter); } catch (StorageException e) { scheduleRebuild(indexId, e); @@ -917,7 +917,7 @@ public class FileBasedIndex implements ApplicationComponent { return docs; } - private void indexUnsavedDocuments(ID indexId, Project project) throws StorageException { + private void indexUnsavedDocuments(ID indexId, Project project, GlobalSearchScope filter) throws StorageException { if (myUpToDateIndices.contains(indexId)) { return; // no need to index unsaved docs @@ -928,11 +928,12 @@ public class FileBasedIndex implements ApplicationComponent { // now index unsaved data final StorageGuard.Holder guard = setDataBufferingEnabled(true); try { + boolean allDocsProcessed = true; final Semaphore semaphore = myUnsavedDataIndexingSemaphores.get(indexId); semaphore.down(); try { for (Document document : documents) { - indexUnsavedDocument(document, indexId, project); + allDocsProcessed &= indexUnsavedDocument(document, indexId, project, filter); } } finally { @@ -943,7 +944,9 @@ public class FileBasedIndex implements ApplicationComponent { break; // hack. Most probably that other indexing threads is waiting for PsiLock, which we're are holding. } } - myUpToDateIndices.add(indexId); // safe to set the flag here, becase it will be cleared under the WriteAction + if (allDocsProcessed) { + myUpToDateIndices.add(indexId); // safe to set the flag here, becase it will be cleared under the WriteAction + } } } finally { @@ -996,12 +999,15 @@ public class FileBasedIndex implements ApplicationComponent { } } - private void indexUnsavedDocument(final Document document, final ID requestedIndexId, Project project) throws StorageException { + // 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; + return true; + } + if (filter != null && !filter.accept(vFile)) { + return false; } - final PsiFile dominantContentFile = findDominantPsiForDocument(document, project); DocumentContent content; @@ -1036,6 +1042,7 @@ public class FileBasedIndex implements ApplicationComponent { dominantContentFile.putUserData(PsiFileImpl.BUILDING_STUB, null); } } + return true; } public static final Key PSI_FILE = new Key("PSI for stubs"); -- 2.11.4.GIT