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.

0

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

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
Avatar
Permanently deleted user

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

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
Avatar
Permanently deleted user

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

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
Avatar
Permanently deleted user

Ah, i'd fixed that on my local machine, but git hadn't recorded the change but i've gone and fixed that now.

The *Gist* of the issue is that i can't see why, CMD+B isn't resolving correctly, manually calling the resolve() function works correctly, but for what ever reason I dont think the function is ever called on the reference, since neither the Go To declaration nor find usages activated the breakpoint on the function.  So i have a suspicion that I am missing some major machinery, but i can't see it in the documentation (unless i'm blind).

Current Issue: Goto Declaration & Find Usages do not resolve to the correct location ("Can't find declaration").
Expected: They go to the declaration.

Odd behaviour: .resolve() is never called.

0
Avatar
Permanently deleted user

Sure.

0

请先登录再写评论。