shared index: explicit file index rebuild request should recalculate indexes by content

GitOrigin-RevId: 6d23d3f4909131c35ffcc8c362c31ed0f834c127
This commit is contained in:
Dmitry Batkovich
2020-05-14 12:10:19 +00:00
committed by intellij-monorepo-bot
parent 355a64d8da
commit 3e233a6076
4 changed files with 31 additions and 31 deletions
@@ -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<VirtualFile> VIRTUAL_FILE = new Key<>("Context virtual file");
/**
@@ -34,7 +33,5 @@ public class IndexingDataKeys {
public static final Key<PsiFile> PSI_FILE = new Key<>("PSI for stubs");
public static final Key<CharSequence> FILE_TEXT_CONTENT_KEY = Key.create("file text content cached by stub indexer");
public static final Key<LighterAST> LIGHTER_AST_NODE_KEY = Key.create("lighter.ast.node");
private IndexingDataKeys() {
}
public static final Key<Boolean> REBUILD_REQUESTED = Key.create("index.rebuild.requested");
}
@@ -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<Psi> 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 <Psi extends PsiElement> boolean checkType(@NotNull Class<Psi> 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);
@@ -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);
}
@@ -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<Void>() {
@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);
}
}
}