Issue with Reference Contributor

Hi,

Sorry to bother you, but i am at wits end now with writing my own reference contributor. I've tried following the custom language tutorial on confluence and all of that works fine on my system. But i've been haing issues adapting that to my own plugin, it appears to create references correctly (they are visible in the PsiViewer and they resolve fine (in the debugger), but i cannot get it to actually use them. Highlighting related items doesnt work, neither does find usages or goto declaration, or any of the other related features.

I've implemented it as getReference() and it doesnt seem to do what i expect.

@Override
public PsiReference getReference() {
    if (!(this.getParent() instanceof EBNFAssignment)) {
        return new EBNFReference(this, this.getTextRange());
    
} else {
        return super.getReference();
    
}
}
  

I can't actually tell what i am missing? I cant puzzle out exactly what i need to do so that this actually works. This section is just the tutorial followed to the word and the method bodies changed to support this languages structure and using this instead of a contributor.

I've tried a mixture of different PlatformPatterns but had no luck there, maybe i missed something obvious.

I would really appreciate any help.

9 comments
Comment actions Permalink

Can you post a link to your plugin's full sources? A quite common source of errors is getting TextRanges wrong, so make sure they actually match the context on which the reference should be registered on.

0
Comment actions Permalink

Unfortunately the tutorial is misleading; I've edited it to make it less so. PsiReferenceContributor is the API to use when you need elements in other languages to reference elements in your language. For references within the same language, you need to implement PsiElement.getReferences() in your PsiElement implementation.

0
Comment actions Permalink

Hi,

Mind if I give you access to the private repo in Github?

Also, I've removed the reference contributor so now the only bit left is the getReference() method.Honestly, I cant see whats wrong with it, so I would really appreciate a quick look over.

Thanks.

0
Comment actions Permalink

I've checked out the project but it is full of compilation errors. Please include /gen/ in your git repository and fix all other errors (missing imports etc). Please also point me to the exact source code where getReference() is implemented, couldn't find it.

0
Comment actions Permalink

Oh, sorry. Here you go (and thanks again!). Its mixed into identifier here:

identifier ::= ID {
   mixin="uk.ac.gla.teamL.psi.impl.EBNFNamedElementImpl"
   
implements="uk.ac.gla.teamL.psi.EBNFNamedElement"
   
methods=[
      toString
      getName
      setName
      getNameIdentifier
   ]
}
0
Comment actions Permalink

Ok, while this branch is also full of errors (make sure your package names are all lowercase as directory names, otherwise nobody on file-sensitive FS will be able to work with your project) I found it now.

Please provide me with a sample file where this PSI is created and provide detailed instructions what current vs. expected results are.

0

Please sign in to leave a comment.