proper way of extending psiReferenceProvider?

Answered

Hi,
i'm trying to write a plugin which basicly would extend a little PsiReference functionality. I've got xml file with smth like:

<validator type="val1">
   <stuff...>
</validator>
<validator type="val2">
  <stuff....>
  <validator-ref-rule ref="val1"/>
</validator>

now i wanna make that when you ctrl+click on the value of attr "ref" /val1/ from validator-ref-rule caret automatically moves to the the value of "type" in proper validator / where type="val1" equals ref="val1" /

I've managed to do that by scanning all xml files on project open and building my own tree of reference but i wanna use the api of idea /Now i don't get underline when i drag over 'ref' mouse/.

In my plugin.xml i've put:

  <extensions defaultExtensionNs="com.intellij">
      <psi.referenceProvider providerClass="pl.outbox.pointer.PointerRefProv" id="pl.outbox.pointer.Pointer"/>
  </extensions>


I've provide a class PointerRefProv which extends PsiReferenceProvider

Now when i try to run this plugin idea gives me a bunch of nullexceptions, just from beginning. Could somebody show me the proper way to provide your own extension to psiReference?

sorry for my english, haven't been using it for a long time x]

thanks in advance.

Kuba Tyburski

0
5 comments
Avatar
Permanently deleted user

Ok, i've managed to properly add my reference provider x] /i've registered the provider in the initComponent() with:

        PointerRefProv p = new PointerRefProv();
        ReferenceProvidersRegistry.getInstance(project).registerReferenceProvider(StandardPatterns.instanceOf(XmlAttributeValue.class), p);


Within PointerRefProv() i override method getReferencesByElement().
But i have problem with resolve() method - GetReferencesByElement() returns PsiReferences[] so i had to return array(new PsiReferenceBase<XmlAttributeValue>(...) { //implemented all needed methods };

I wanna make this work like it is made with GotoDeclaration so i could jump through files [validator refers to the other validator in the other file] but don't know exactly what to use. I know it's already made in intellij but don't know where to search for that or what to use. Anybody knows how to do that? x]
Cause scanning all files every time when somebody tries to jump to validator declaration would be just stupid...

0

Hello J,

Sorry, unfortunately I'm not able to understand what problem exactly you''re
facing. PsiReferenceProvider is the correct API for this task. You do need
to return the element to jump to from the resolve() method of your PsiReference.
There is no "already made solution" in IntelliJ which would help you figure
out what element you should return.

Ok, i've managed to properly add my reference provider x] /i've
registered the provider in the initComponent() with:

 new PointerRefProv();
> 
> ReferenceProvidersRegistry.getInstance(project).registerReferenceProvi
> der(StandardPatterns.instanceOf(XmlAttributeValue.class), p);]]>

Within PointerRefProv() i override method getReferencesByElement().

But i have problem with resolve() method - GetReferencesByElement()
returns PsiReferences[] so i had to return array(new
PsiReferenceBase<XmlAttributeValue>(...) { //implemented all needed
methods };

I wanna make this work like it is made with GotoDeclaration so i could
jump through files [validator refers to the other validator in the
other file] but don't know exactly what to use. I know it's already
made in intellij but don't know where to search for that or what to
use. Anybody knows how to do that? x]

Cause scanning all files every time when somebody tries to jump to
validator declaration would be just stupid...


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

I found solution myself looking at some already made plugins. Thanks

What I was asking for was is there is any way to look into the source of intellij how it is made when i ctrl+click on usage of class,method,field that it automatically show the declaration of it. But nevermind x] It's already done x] Maybe in the future i'll have some more questions cause there is possibility that i'll need to create some more plugins xP

0

Hi J!

I know, is a long time, but I'm trying to implement a plugin, doing the same thing, you did here, years ago. (Click on a value of a attribute and jump to the definition of this attribute). 

You wrote, that you did find a solution, looking at some plugins. Could you please help me out here, with some hint or solutions how you resolved the problem? Is the solutions, to define your own ReferenceProvider or it is more?

Thanks in advice

Zs.

0

Please sign in to leave a comment.