is it possible to override CTRL + mouse click for specific SpiElement ?

Answered

Hi Everybody.

 

I already wrote a quickNavigateInfo for some specific PsiElement that show me the translation corresponding to the java variable (the same way that I18n works)

 

Now i'm looking for the CTRL + click to open the file containing the translation. Currently IntelliJ handle this the normal way and propose to open the declaration of the variable, but this is not what i want to open.

Is there something similare to quickNavigateInfo but for goToReference ?

 

Thanks in advance for your answer.

 

Best regards,

Alain

0
11 comments

Thank you Yann.

I already came to this example and I still don't really know where to start.

The example is for a custom language where I need to define a lot of stuff. 

I'm not sure how to proceed here. Indeed I don't plan to use a new language, only to override the reference of some existing psiElement .

I was thinking of overriding the JavaLangClassMemberReference resolve method, but I guess this is not the correct approach.

 

If you have a bit more details that would be very helpful .

And sorry that I bother you so much.

0

By the way as the example deals with a properties plugin i have another small question : 

 

my translations are available within a property file. 

I currently read and write the file with within the load and store method of the Property object what is working fine, but the "undo" does not seems to detect this changes.

 

I first wanted to read the PsiElement directly with Intellij, as these Psi elements where shown on PsiViewer.

But somehow I guess I need to tell my plugin that it should compile the properties plugin too.

Indeed I can't access com.intellij.lang.properties.psi.... 

 

any idea how to access the psiElement from the properties file ? Or how to make the Undo aware that the property file was change ?

0

I managed to add the dependency thanks :)

but i'm still fighting with the CTRL + click

 

here is what I have done

1: I created a contributor

 

public class MultiLangContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiIdentifier.class).
withText("APPLICATION_TXT"), new TranslationClickProvider());
}
}

 

I registered it within my plugin.xml with following line

<psi.referenceContributor order="first"  language="JAVA" implementation="com.swissas.contributor.MultiLangContributor" />

and I created the clickProvider class

public class TranslationClickProvider extends PsiReferenceProvider {

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
System.out.println("i'm here");
return new PsiReference[0];
}
}

 

I added a breakpoint on the contributor and on the provider

I could confirm that the contributor code is indeed done

but it never went in my provider :/ 

 

psiViewer told me that what I'm looking is correct, but somehow the Pattern does not seems to match as it never enter the TranslationClickProvider class


 

If I leave my pattern empty 

PlatformPatterns.psiElement()

Then the breakpoint within my Provider is triggered. But of couse I don't want to register the provider for all possible psiElements ...

 

 

Any clue of what I'm doing wrong ? 

0

someone has an idea ? 
Maybe I should use something else different than PlatformPatterns ? 
I have the feeling that my solution is nearly ok, but like said I'm missing something to make it work.

0

ok I got it :) i was using the wrong approach .

I needed to use gotToDeclaration and implement one class for that :) 

0

Hi Alain

Which class the mehtod of gotToDeclaration?

0

zjbhnay Could you please clarify your question?

0

Hi Alan, sorry to bother you.

I attempt resolve task like you'r: I need create functional for navigate to definition of annotation (ex. @Something("UNIQUE_TEXT") ) via CTRL+Click from different file with custom extension (like .some_extension)
However, i cannot understand, what you mean

I needed to use gotToDeclaration and implement one class for that

When i search this in JetBrains plugin development documentation, i no found anything relevant. So, may be you can show solution or github?

0

Please sign in to leave a comment.