From d802d6487eb3139a4e9707868a3490aa1fbda4ec Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 23 Nov 2011 18:09:43 +0400 Subject: [PATCH] if FileBasedIndex.processValues is invoked with virtual file restricted (out of scope) then indexUnsavedDocument should index its current content --- .../util/indexing/FileBasedIndex.java | 20 ++++++++++++------- 1 file changed, 13 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 ddd44b1fec11..4f213891a0a1 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -741,6 +741,11 @@ public class FileBasedIndex implements ApplicationComponent { * The method is internal to indexing engine end is called internally. The method is public due to implementation details */ public void ensureUpToDate(final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter) { + ensureUpToDate(indexId, project, filter, null); + } + + private void ensureUpToDate(final ID indexId, @Nullable Project project, @Nullable GlobalSearchScope filter, + @Nullable VirtualFile restrictedFile) { if (!needsFileContentLoading(indexId)) { return; //indexed eagerly in foreground while building unindexed file list } @@ -760,7 +765,7 @@ public class FileBasedIndex implements ApplicationComponent { try { checkRebuild(indexId, false); myChangedFilesCollector.forceUpdate(project, filter, false); - indexUnsavedDocuments(indexId, project, filter); + indexUnsavedDocuments(indexId, project, filter, restrictedFile); } catch (StorageException e) { scheduleRebuild(indexId, e); @@ -867,7 +872,7 @@ public class FileBasedIndex implements ApplicationComponent { } final Project project = filter.getProject(); //assert project != null : "GlobalSearchScope#getProject() should be not-null for all index queries"; - ensureUpToDate(indexId, project, filter); + ensureUpToDate(indexId, project, filter, restrictToFile); final Lock readLock = index.getReadLock(); try { @@ -1114,8 +1119,8 @@ public class FileBasedIndex implements ApplicationComponent { return docs; } - private void indexUnsavedDocuments(ID indexId, @Nullable Project project, GlobalSearchScope filter) throws StorageException { - + private void indexUnsavedDocuments(ID indexId, @Nullable Project project, GlobalSearchScope filter, + VirtualFile restrictedFile) throws StorageException { if (myUpToDateIndices.contains(indexId)) { return; // no need to index unsaved docs } @@ -1133,7 +1138,7 @@ public class FileBasedIndex implements ApplicationComponent { boolean allDocsProcessed = true; try { for (Document document : documents) { - allDocsProcessed &= indexUnsavedDocument(document, indexId, project, filter); + allDocsProcessed &= indexUnsavedDocument(document, indexId, project, filter, restrictedFile); } } finally { @@ -1210,12 +1215,13 @@ public class FileBasedIndex implements ApplicationComponent { } // returns false if doc was not indexed because the file does not fit in scope - private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID requestedIndexId, final Project project, GlobalSearchScope filter) throws StorageException { + private boolean indexUnsavedDocument(@NotNull final Document document, @NotNull final ID requestedIndexId, final Project project, + GlobalSearchScope filter, VirtualFile restrictedFile) throws StorageException { final VirtualFile vFile = myFileDocumentManager.getFile(document); if (!(vFile instanceof VirtualFileWithId) || !vFile.isValid()) { return true; } - if (filter != null && !filter.accept(vFile)) { + if (filter != null && (!filter.accept(vFile) && vFile != restrictedFile)) { return false; } final PsiFile dominantContentFile = findDominantPsiForDocument(document, project);