From 3e233a607691c00890124e080f3bbc31721177f9 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Thu, 14 May 2020 14:41:03 +0300 Subject: [PATCH] shared index: explicit file index rebuild request should recalculate indexes by content GitOrigin-RevId: 6d23d3f4909131c35ffcc8c362c31ed0f834c127 --- .../util/indexing/IndexingDataKeys.java | 9 +++---- .../psi/stubs/StubProcessingHelperBase.java | 26 +++++++------------ .../util/indexing/FileBasedIndexImpl.java | 4 ++- .../util/indexing/IndexedFilesListener.java | 23 +++++++++++----- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java index 76200a2a5b20..438f06f63a81 100644 --- a/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java +++ b/platform/core-impl/src/com/intellij/util/indexing/IndexingDataKeys.java @@ -20,10 +20,9 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.ApiStatus; -/** - * @author yole - */ +@ApiStatus.Internal public class IndexingDataKeys { public static final Key VIRTUAL_FILE = new Key<>("Context virtual file"); /** @@ -34,7 +33,5 @@ public class IndexingDataKeys { public static final Key PSI_FILE = new Key<>("PSI for stubs"); public static final Key FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer"); public static final Key LIGHTER_AST_NODE_KEY = Key.create("lighter.ast.node"); - - private IndexingDataKeys() { - } + public static final Key REBUILD_REQUESTED = Key.create("index.rebuild.requested"); } diff --git a/platform/indexing-impl/src/com/intellij/psi/stubs/StubProcessingHelperBase.java b/platform/indexing-impl/src/com/intellij/psi/stubs/StubProcessingHelperBase.java index 1527249d0750..af5dd35ce659 100644 --- a/platform/indexing-impl/src/com/intellij/psi/stubs/StubProcessingHelperBase.java +++ b/platform/indexing-impl/src/com/intellij/psi/stubs/StubProcessingHelperBase.java @@ -15,10 +15,7 @@ */ package com.intellij.psi.stubs; -import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.ide.plugins.PluginManagerCore; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiBinaryFile; @@ -52,15 +49,10 @@ public abstract class StubProcessingHelperBase { @NotNull Class requiredClass) { PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile == null) { - //TODO shared stub indexes are overcomplicated for kotlin for some reason. - //TODO dmitro.batko: it must! be investigated as soon as possible - IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("intellij.indexing.shared")); - if (plugin == null || !plugin.isEnabled()) { - LOG.error("Stub index points to a file without PSI: " + - getFileTypeInfo(file, project) + ", " + - "used scope = " + scope); - onInternalError(file); - } + LOG.error("Stub index points to a file without PSI: " + + getFileTypeInfo(file, project) + ", " + + "used scope = " + scope); + onInternalError(file); return true; } @@ -88,13 +80,13 @@ public abstract class StubProcessingHelperBase { if (!(psiFile instanceof PsiFileImpl) && psiFile instanceof PsiFileWithStubSupport) { return Collections.singletonList(((PsiFileWithStubSupport)psiFile).getStubbedSpine()); } - + return ContainerUtil.map(StubTreeBuilder.getStubbedRoots(psiFile.getViewProvider()), t -> ((PsiFileImpl)t.second).getStubbedSpine()); } private boolean checkType(@NotNull Class requiredClass, PsiFile psiFile, PsiElement psiElement) { if (requiredClass.isInstance(psiElement)) return true; - + StubTree stubTree = ((PsiFileWithStubSupport)psiFile).getStubTree(); if (stubTree == null && psiFile instanceof PsiFileImpl) stubTree = ((PsiFileImpl)psiFile).calcStubTree(); inconsistencyDetected(stubTree, (PsiFileWithStubSupport)psiFile); @@ -127,10 +119,10 @@ public abstract class StubProcessingHelperBase { } if (psiFile instanceof PsiBinaryFile) { - // a file can be indexed as containing stubs, - // but then in a specific project FileViewProviderFactory can decide not to create stub-aware PSI + // a file can be indexed as containing stubs, + // but then in a specific project FileViewProviderFactory can decide not to create stub-aware PSI // because the file isn't in expected location - return true; + return true; } ObjectStubTree objectStubTree = StubTreeLoader.getInstance().readFromVFile(psiFile.getProject(), file); 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 bb59c5420e24..59f6c8fa17ce 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -292,7 +292,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { //myChangedFilesCollector.invalidateIndicesRecursively(file, false); //myChangedFilesCollector.buildIndicesForFileRecursively(file, false); ChangedFilesCollector changedFilesCollector = getChangedFilesCollector(); - changedFilesCollector.invalidateIndicesRecursively(file, true, changedFilesCollector.getEventMerger()); + changedFilesCollector.invalidateIndicesRecursively(file, true, true, changedFilesCollector.getEventMerger()); if (myRegisteredIndexes.isInitialized()) { changedFilesCollector.ensureUpToDateAsync(); } @@ -1251,6 +1251,8 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx { } } }); + + file.putUserData(IndexingDataKeys.REBUILD_REQUESTED, null); return Pair.create(setIndexedStatus.get(), perIndexerTimes); } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/IndexedFilesListener.java b/platform/lang-impl/src/com/intellij/util/indexing/IndexedFilesListener.java index 5c51ee572ff9..3285f079be50 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/IndexedFilesListener.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/IndexedFilesListener.java @@ -46,10 +46,16 @@ abstract class IndexedFilesListener implements AsyncFileListener { } } - private static boolean invalidateIndicesForFile(@NotNull VirtualFile file, boolean contentChange, @NotNull VfsEventsMerger eventMerger) { + private static boolean invalidateIndicesForFile(@NotNull VirtualFile file, + boolean contentChange, + boolean forceRebuildRequested, + @NotNull VfsEventsMerger eventMerger) { if (isUnderConfigOrSystem(file)) { return false; } + if (forceRebuildRequested) { + file.putUserData(IndexingDataKeys.REBUILD_REQUESTED, Boolean.TRUE); + } ProgressManager.checkCanceled(); eventMerger.recordBeforeFileEvent(file, contentChange); return !file.isDirectory() || FileBasedIndexImpl.isMock(file) || ManagingFS.getInstance().wereChildrenAccessed(file); @@ -57,11 +63,14 @@ abstract class IndexedFilesListener implements AsyncFileListener { protected abstract void iterateIndexableFiles(@NotNull VirtualFile file, @NotNull ContentIterator iterator); - void invalidateIndicesRecursively(@NotNull VirtualFile file, boolean contentChange, @NotNull VfsEventsMerger eventMerger) { + void invalidateIndicesRecursively(@NotNull VirtualFile file, + boolean contentChange, + boolean forceRebuildRequested, + @NotNull VfsEventsMerger eventMerger) { VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { - return invalidateIndicesForFile(file, contentChange, eventMerger); + return invalidateIndicesForFile(file, contentChange, forceRebuildRequested, eventMerger); } @Override @@ -77,10 +86,10 @@ abstract class IndexedFilesListener implements AsyncFileListener { VfsEventsMerger tempMerger = new VfsEventsMerger(); for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent) { - invalidateIndicesRecursively(((VFileContentChangeEvent)event).getFile(), true, tempMerger); + invalidateIndicesRecursively(((VFileContentChangeEvent)event).getFile(), true, false, tempMerger); } else if (event instanceof VFileDeleteEvent) { - invalidateIndicesRecursively(((VFileDeleteEvent)event).getFile(), false, tempMerger); + invalidateIndicesRecursively(((VFileDeleteEvent)event).getFile(), false, false, tempMerger); } else if (event instanceof VFilePropertyChangeEvent) { final VFilePropertyChangeEvent pce = (VFilePropertyChangeEvent)event; @@ -89,10 +98,10 @@ abstract class IndexedFilesListener implements AsyncFileListener { // indexes may depend on file name // name change may lead to filetype change so the file might become not indexable // in general case have to 'unindex' the file and index it again if needed after the name has been changed - invalidateIndicesRecursively(pce.getFile(), false, tempMerger); + invalidateIndicesRecursively(pce.getFile(), false, false, tempMerger); } else if (propertyName.equals(VirtualFile.PROP_ENCODING)) { - invalidateIndicesRecursively(pce.getFile(), true, tempMerger); + invalidateIndicesRecursively(pce.getFile(), true, false, tempMerger); } } }