Cannot find classes after change branches
I have custom language plugin with language which based on Java language. In Java syntax just added new keywords. Therefore, most features of java implementation reuse.
final public class CustomLanguage extends Language {
public static final String LANGUAGE_ID = "CustomJava";
public static final CustomLanguage INSTANCE = new CustomLanguage();
private CustomLanguage() {
super(JavaLanguage.INSTANCE, LANGUAGE_ID, "text/x-java-source", "text/java", "application/x-java", "text/x-java");
}
}
And I have a project written in this Custom language. I have two committed versions: in one, the source code is stored in a directory "src/java", in another - "src".
I checkout branch from "src/java" to "src" and I lost mark source directory (as expected) so I marked it manually. After I opened file written on custom language, and all imports on custom language classes is invalid (could not resolve) but all java classes are valid. Before the checkout all classes was valid (resolved).
JavaFileManagerImpl cannot find custom class (file). com.intellij.psi.impl.file.impl.JavaFileManagerImpl#doFindClasses
final Collection<PsiClass> classes = JavaFullClassNameIndex.getInstance().get(qName.hashCode(), myManager.getProject(), scope);
Method call returns empty collection.
Are there any ideas why after the checkout (and mark source directory) the JavaFileManager can not find the file (class)?
Thanks for any help!
Please sign in to leave a comment.
Were your files reindexed after you switched branches? Can you reproduce this reliably in a debug IDEA instance so that you can put breakpoints?
I saw a message on indexation in the bottom of the IDE.
Where do I must put the breakpoint to find out reindex or not?
Yes, I can reproduce it in the debug mode.
In "map" in com.intellij.psi.stubs.StubUpdatingIndex#getIndexer, you can check if inputData.getFile() is one of yours.
Only java files reindexed after switched branches (after marked directory src as source directory).
UPD
Thanks for the reference!
Do you have your own file element type? Does it extend IStubFileElementType and override shouldBuildStubFor like JavaFileElementType does? Is this shouldBuildStubFor called during reindexing?
Yes, I have. And no, shouldBuildStubFor didn't call during reindexing. It extends JavaFiledElementType.
I believe the cause is that we have JavaLanguageLevelPusher#persistAttribute which only schedules for reindexing java files. You could try to copy this class, register as an extension and modify so that it handles your files. If this helps, we can think of a way to generalize it to process your files out of the box.
Thank you, it works!
I register extension as first and handle custom and java files. IDEA doesn't call JavaLanguageLevelPusher after my pusher.
It would be cool to get a way to make it out of the box.
Pushed a fix into master
Thank you.