Question about FileBasedIndex.getInstance().getContainingFiles

Hi,

I'm using the code below to get all my custom file in my project, 

Collection<VirtualFile> virtualFiles =
FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, XXXXFileType.INSTANCE,
GlobalSearchScope.allScope(project));

But there is a strange problem, this code only return part of the files in my project while I want all XXXXFile returned.

I created project in this way: On the IDEA welcome page,  I choose Open Project, and select a directory which has sub-directories and XXX files. 

What I missed if I want to get all XXXFile in this way?

Thanks

4 comments

Such behavior can happen for a number of reasons, e.g. when IDE was forcibly terminated, etc
Does the problem reliably appear after running "cache invalidation" action?
Please provide log folder zipped in YouTrack issue for us to investigate the problem.

0

After Invalidate Cache,  the getContainingFiles returns the right count of files.

But the consequent code will fail:

for (VirtualFile virtualFile : virtualFiles) {
XXXFile xxxFile = (XXXFile) PsiManager.getInstance(project).findFile(virtualFile);

It prompts a fatal error:

com.intelliji.psi.impl.source.PsiPlainTextFileImpl cannot be cast to com.xxxplugin.psi.XXXFile.

This error appear before sometime, but now it happens to all my custom file. Even if I create a new custom file, it will show error after close it and reopen.

 

All of this happened on IDEA Linux edition, the windows edition is OK so far. I am sorry I'm not allowed to upload files out of company. But I can offer the IDEA version:

IntelliJ IDEA 2018.2 EAP (Community Edition)
Build #IC-182.2757.3, built on May 29, 2018
JRE: 1.8.0_152-release-1226-b7 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

 

0

If virtualFile in the loop is valid file of your file type then you need to check why you get incorrect PSIFile implementation, there can be variety of reasons mostly nonrelated to indexing. I'd debug why AbstractFileViewProvider.create instantiate  PsiPlainTextFileImpl for your files.

0

Hi Maxim,

I tried a lot methods which cost me at least totally 12 hours, and finally I got why. In my project, there is a XXX file which is more than 2.44 Mb, this shut down the code insight and never make it back. If I remove the big file, everything is OK. So may I advice, the big file only shut down some function within this file? 

0

Please sign in to leave a comment.