shared index: process files on project open even if they're marked as indexed (to restore chunks required for project) IDEA-246395

GitOrigin-RevId: f6c74612c7d40ec4384887f7bfb80c8e1bd61b2d
This commit is contained in:
Dmitry Batkovich
2020-07-23 14:16:43 +03:00
committed by intellij-monorepo-bot
parent e8fbb5a569
commit bd2431412b
5 changed files with 39 additions and 12 deletions

View File

@@ -1434,7 +1434,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
}
}
boolean needsFileContentLoading(@NotNull ID<?, ?> indexId) {
public boolean needsFileContentLoading(@NotNull ID<?, ?> indexId) {
return !myRegisteredIndexes.isNotRequiringContentIndex(indexId);
}

View File

@@ -30,6 +30,12 @@ public interface FileBasedIndexInfrastructureExtension {
void noFilesFoundToProcessIndexingProject(@NotNull Project project, @NotNull ProgressIndicator indexingIndicator);
interface FileIndexingStatusProcessor {
/**
* Serves as an optimization when time-consuming {@link FileIndexingStatusProcessor#processUpToDateFile(VirtualFile, int, ID)}
* should not be called because takes no effect.
*/
boolean shouldProcessUpToDateFiles();
/**
* Processes up to date file for given content-dependent index while "scanning files to index" in progress.
*/

View File

@@ -71,7 +71,7 @@ public final class FileBasedIndexProjectHandler implements IndexableFileSet {
// schedule dumb mode start after the read action we're currently in
if (fileBasedIndex instanceof FileBasedIndexImpl) {
DumbService.getInstance(project).queueTask(new UnindexedFilesUpdater(project, IndexInfrastructure.isIndexesInitializationSuspended()));
DumbService.getInstance(project).queueTask(new UnindexedFilesUpdater(project, IndexInfrastructure.isIndexesInitializationSuspended(), true));
}
for (Class<? extends IndexableFileSet> indexableSetClass : getProjectIndexableSetClasses()) {

View File

@@ -10,6 +10,7 @@ import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.openapi.vfs.VirtualFileWithId;
import com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -27,12 +28,16 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
private final FileBasedIndexImpl myFileBasedIndex;
private final UpdatableIndex<FileType, Void, FileContent> myFileTypeIndex;
private final Collection<FileBasedIndexInfrastructureExtension.FileIndexingStatusProcessor> myStateProcessors;
private final boolean myRunExtensionsForFilesMarkedAsIndexed;
private final boolean myShouldProcessUpToDateFiles;
UnindexedFilesFinder(@NotNull Project project,
@NotNull FileBasedIndexImpl fileBasedIndex) {
@NotNull FileBasedIndexImpl fileBasedIndex,
boolean runExtensionsForFilesMarkedAsIndexed) {
myProject = project;
myFileBasedIndex = fileBasedIndex;
myFileTypeIndex = fileBasedIndex.getIndex(FileTypeIndex.NAME);
myRunExtensionsForFilesMarkedAsIndexed = runExtensionsForFilesMarkedAsIndexed;
myStateProcessors = FileBasedIndexInfrastructureExtension
.EP_NAME
@@ -40,16 +45,27 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
.map(ex -> ex.createFileIndexingStatusProcessor(project))
.filter(Objects::nonNull)
.collect(Collectors.toList());
myShouldProcessUpToDateFiles = ContainerUtil.find(myStateProcessors, p -> p.shouldProcessUpToDateFiles()) != null;
}
@Override
public boolean accept(VirtualFile file) {
return ReadAction.compute(() -> {
if (myProject.isDisposed()
|| !file.isValid()
|| file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()
|| !(file instanceof VirtualFileWithId)
) {
if (myProject.isDisposed() || !file.isValid() || !(file instanceof VirtualFileWithId)) {
return false;
}
else if (file instanceof VirtualFileSystemEntry && ((VirtualFileSystemEntry)file).isFileIndexed()) {
if (myRunExtensionsForFilesMarkedAsIndexed && myShouldProcessUpToDateFiles) {
int inputId = Math.abs(FileBasedIndexImpl.getIdMaskingNonIdBasedFile(file));
List<ID<?, ?>> ids = IndexingStamp.getNontrivialFileIndexedStates(inputId);
for (FileBasedIndexInfrastructureExtension.FileIndexingStatusProcessor processor : myStateProcessors) {
for (ID<?, ?> id : ids) {
if (myFileBasedIndex.needsFileContentLoading(id)) {
processor.processUpToDateFile(file, inputId, id);
}
}
}
}
return false;
}
@@ -63,6 +79,7 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
if (myFileTypeIndex.getIndexingStateForFile(inputId, fileContent) == FileIndexingState.OUT_DATED) {
myFileBasedIndex.dropNontrivialIndexedStates(inputId);
shouldIndexFile.set(true);
} else {
final List<ID<?, ?>> affectedIndexCandidates = myFileBasedIndex.getAffectedIndexCandidates(file);
//noinspection ForLoopReplaceableByForEach
@@ -72,7 +89,9 @@ final class UnindexedFilesFinder implements VirtualFileFilter {
if (myFileBasedIndex.needsFileContentLoading(indexId)) {
FileIndexingState fileIndexingState = myFileBasedIndex.shouldIndexFile(fileContent, indexId);
if (fileIndexingState == FileIndexingState.UP_TO_DATE) {
myStateProcessors.forEach(p -> p.processUpToDateFile(file, inputId, indexId));
if (myShouldProcessUpToDateFiles) {
myStateProcessors.forEach(p -> p.processUpToDateFile(file, inputId, indexId));
}
} else if (fileIndexingState.updateRequired()) {
if (myDoTraceForFilesToBeIndexed) {
LOG.trace("Scheduling indexing of " + file + " by request of index " + indexId);

View File

@@ -58,12 +58,14 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
private final FileBasedIndexImpl myIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
private final Project myProject;
private final boolean myStartSuspended;
private final boolean myRunExtensionsForFilesMarkedAsIndexed;
private final PushedFilePropertiesUpdater myPusher;
public UnindexedFilesUpdater(@NotNull Project project, boolean startSuspended) {
public UnindexedFilesUpdater(@NotNull Project project, boolean startSuspended, boolean runExtensionsForFilesMarkedAsIndexed) {
super(project);
myProject = project;
myStartSuspended = startSuspended;
myRunExtensionsForFilesMarkedAsIndexed = runExtensionsForFilesMarkedAsIndexed;
myPusher = PushedFilePropertiesUpdater.getInstance(myProject);
project.getMessageBus().connect(this).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
@@ -75,7 +77,7 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
}
public UnindexedFilesUpdater(@NotNull Project project) {
this(project, false);
this(project, false, false);
}
private void updateUnindexedFiles(ProgressIndicator indicator) {
@@ -223,7 +225,7 @@ public final class UnindexedFilesUpdater extends DumbModeTask {
if (providers.isEmpty()) {
return Collections.emptyMap();
}
VirtualFileFilter unindexedFileFilter = new UnindexedFilesFinder(project, myIndex);
VirtualFileFilter unindexedFileFilter = new UnindexedFilesFinder(project, myIndex, myRunExtensionsForFilesMarkedAsIndexed);
Map<IndexableFilesProvider, List<VirtualFile>> providerToFiles = new IdentityHashMap<>();
ConcurrentBitSet visitedFileSet = new ConcurrentBitSet();