Infinite recursion (and stack overflow) when using StubIndex from within reference code

Hello,

I tried to call the StubIndex from within the multiResolve function in my class inheriting from PsiReferenceBase. I was hoping to be able to find all externally defined (but visible) elements from other classes in my code like that, to be able to perform the resolve in a better way. My resolution unit tests seem to work, however, when I run the plugin in reality I get an infinite recursion going on, not when I just place the 'caret' on the variable I like to resolve, but as soon as I use the navigation shortcuts, so Ctrl-B or Alt - F7 or so. Is this expected because I shouldn't use the StubIndex that way or am I doing something wrong? The invocation of the StubIndex looks like this :

 
//        GlobalSearchScope scope = GlobalSearchScope.allScope(project);
//        Collection<HaskellNamedElement> namedElements = StubIndex.getElements(HaskellAllNameIndex.KEY, name, project, scope, HaskellNamedElement.class);


Kasper

4 comments
Comment actions Permalink

Can you show the full stacktrace you're getting? There is no rule that prevents using StubIndex in resolve (and in fact we do use it in some of our plugins).

0
Comment actions Permalink

The complete stack trace in attach, the repetetive part is this :

 at com.haskforce.psi.HaskellFile.getBody(HaskellFile.java:62)
 at com.haskforce.utils.HaskellUtil.definitionNode(HaskellUtil.java:142)
 at com.haskforce.utils.HaskellUtil.definitionNode(HaskellUtil.java:113)
 at com.haskforce.utils.HaskellUtil.definitionNode(HaskellUtil.java:186)
 at com.haskforce.stubs.types.HaskellVaridStubElementType.shouldCreateStub(HaskellVaridStubElementType.java:28)
 at com.intellij.psi.impl.source.PsiFileImpl$1.visitNode(PsiFileImpl.java:271)
 at com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor.visitComposite(RecursiveTreeElementWalkingVisitor.java:80)
 at com.intellij.psi.impl.source.tree.CompositeElement.acceptTree(CompositeElement.java:157)
 at com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor$1.visit(RecursiveTreeElementWalkingVisitor.java:66)
 at com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor$1.visit(RecursiveTreeElementWalkingVisitor.java:58)
 at com.intellij.util.WalkingState.walkChildren(WalkingState.java:65)
 at com.intellij.util.WalkingState.elementStarted(WalkingState.java:52)
 at com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor.visitNode(RecursiveTreeElementWalkingVisitor.java:85)
 at com.intellij.psi.impl.source.PsiFileImpl$1.visitNode(PsiFileImpl.java:287)
 at com.intellij.psi.impl.source.tree.RecursiveTreeElementWalkingVisitor.visitComposite(RecursiveTreeElementWalkingVisitor.java:80)
 at com.intellij.psi.impl.source.tree.CompositeElement.acceptTree(CompositeElement.java:157)
 at com.intellij.psi.impl.source.PsiFileImpl.calcStubAstBindings(PsiFileImpl.java:261)
 at com.intellij.psi.impl.source.PsiFileImpl.loadTreeElement(PsiFileImpl.java:193)
 at com.intellij.psi.impl.source.PsiFileImpl.calcTreeElement(PsiFileImpl.java:749)
 at com.intellij.psi.impl.source.PsiFileImpl.getFirstChild(PsiFileImpl.java:760)
 at com.intellij.psi.util.PsiTreeUtil.getChildOfType(PsiTreeUtil.java:298)
 at com.haskforce.psi.HaskellFile.getBody(HaskellFile.java:62)

It seems to call getBody recursively. I expect this means that the implementation of the StubElement interface is wrong then, but I don't really see where.



Attachment(s):
stackTraceStubInde.zip
0
Comment actions Permalink

Looks like your implementation of IStubElementType.shouldCreateStub() tries to access the PSI. It needs to work exclusively over the ASTNode tree.

0
Comment actions Permalink

Okay, I'll try this out as soon as I find time and try to confirm this. Might take some time before I come 'round to it, but I will be back.

0

Please sign in to leave a comment.