supply project while file indexing using project file filter if it's not available

GitOrigin-RevId: da4778f12ec417f8c6660d0d546228d1dec9bf67
This commit is contained in:
Dmitry Batkovich
2021-07-30 14:29:58 +00:00
committed by intellij-monorepo-bot
parent 2b0ec6b8c4
commit 0c36e030eb
3 changed files with 17 additions and 9 deletions
@@ -20,10 +20,6 @@ public class IndexedFileImpl extends UserDataHolderBase implements IndexedFile {
private final @Nullable FileType myType;
public IndexedFileImpl(@NotNull VirtualFile file) {
this(file, null);
}
public IndexedFileImpl(@NotNull VirtualFile file, Project project) {
this(file, null, project);
}
@@ -1372,14 +1372,16 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
Set<ID<?,?>> indexesProvidedByExtensions = new HashSet<>();
Ref<Boolean> wasFullyIndexedByInfrastructureExtensions = Ref.create(true);
Ref<FileType> fileTypeRef = Ref.create();
Project guessedProject = project != null ? project : ProjectUtil.guessProjectForFile(file);
//todo check file still from project
int inputId = getFileId(file);
Project guessedProject = project != null ? project : myIndexableFilesFilterHolder.findProjectForFile(inputId);
IndexedFileImpl indexedFile = new IndexedFileImpl(file, guessedProject);
FileTypeManagerEx.getInstanceEx().freezeFileTypeTemporarilyIn(file, () -> {
ProgressManager.checkCanceled();
FileContentImpl fc = null;
int inputId = getFileId(file);
Set<ID<?, ?>> currentIndexedStates = new HashSet<>(IndexingStamp.getNontrivialFileIndexedStates(inputId));
List<ID<?, ?>> affectedIndexCandidates = getAffectedIndexCandidates(indexedFile);
//noinspection ForLoopReplaceableByForEach
@@ -1648,8 +1650,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
boolean includeFilesFromOtherProjects = restrictedTo == null && project == null;
List<VirtualFile> virtualFilesToBeUpdatedForProject = ContainerUtil.filter(
allFilesToUpdate,
new ProjectFilesCondition(projectIndexableFiles(project), filter, restrictedTo,
includeFilesFromOtherProjects)
new ProjectFilesCondition(projectIndexableFiles(project), filter, restrictedTo, includeFilesFromOtherProjects)
);
if (!virtualFilesToBeUpdatedForProject.isEmpty()) {
@@ -1789,7 +1790,7 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
// handle 'content-less' indices separately
boolean fileIsDirectory = file.isDirectory();
IndexedFileImpl indexedFile = new IndexedFileImpl(file, ProjectUtil.guessProjectForFile(file));
IndexedFileImpl indexedFile = new IndexedFileImpl(file, myIndexableFilesFilterHolder.findProjectForFile(fileId));
if (!contentChange) {
FileContent fileContent = null;
@@ -32,6 +32,8 @@ internal sealed class ProjectIndexableFilesFilterHolder {
abstract fun removeFile(fileId: Int)
abstract fun findProjectForFile(fileId: Int): Project?
abstract fun runHealthCheck()
}
@@ -84,6 +86,15 @@ internal class IncrementalProjectIndexableFilesFilterHolder : ProjectIndexableFi
}
}
override fun findProjectForFile(fileId: Int): Project? {
for ((project, filter) in myProjectFilters) {
if (filter.containsFileId(fileId)) {
return project
}
}
return null
}
override fun runHealthCheck() {
for ((project, filter) in myProjectFilters) {
val errors = ReadAction