Usage of StringStubIndexExtension during unit testing

 Hi. I have a plugin for a custom language, it uses stub indexes. Indexing works correctly when run using Run Configuration and in production: stub indexes are built fine and there is no problem here.

 

However, among other usages like class/methods indexing, I have an index for PsiFile instances in project and use it to do various types of between-file resolution(module imports, etc), it works, but the issue is that I cannot test those features with more than one file, because all stub indexes are always empty on unit testing. My code is like:

public class GoToDeclarationTest extends LightCodeInsightFixtureTestCase {
    public void testUseExternalReference() {
        myFixture.configureByFiles("IdeaFoo/Baz.pm6", "IdeaFoo/Bar.pm6");
        PsiElement usage = myFixture.getFile().findElementAt(25); // Element is present
        foo(); // I am doing resolution here which deep in plugin code includes "ProjectModulesStubIndex.getInstance().get(name, project, GlobalSearchScope.projectScope(project))"
        ...    }
}

 

Where "ProjectModulesStubIndex" is "ProjectModulesStubIndex extends StringStubIndexExtension<Perl6File>", that works when using full idea instance.

I have tried various methods on FileBasedIndex, but hardly any luck (sounds obvious, because we work with StringStubIndexExtension here).

 

So the question is: How to test things that require indexed stubs? Are there any means to force building index for particular test method/class? Should it work by default and something is wrong with the way my test is written? Is testing out features that rely on stub creation possible at all?

 

Thanks.

0

Please sign in to leave a comment.