ReferenceContributor don't works for existing languages
I am trying to implements a new reference from an existing language, in case, PHP, but it even is catched from debugger. Seems that it just is not initialized.
My problem is the following: the Laravel Frameworks implements a concept called query scopes. With that, when I do a method call like $user->filterAge() it, on reality, calls from a definition declared as User::scopeFilterAge() (briefly).
What I want to do: I like that PhpStorm understand that the "filterAge" points to scopeFilterAge declaration (ctrl+click). Like it does when I do at $user, for instance:
What I tried: I tried to follow the plugin development doc about reference contribuitor. Then I updated my plugin.xml with a new extension. Note: my inspections or completion contribuitors on this same file works fine. My problem is justly with this reference contribuitor over an existing language.
My plugin.xml:
<extensions defaultExtensionNs="com.intellij">
<psi.referenceContributor language="PHP"
implementation="[...].ScopeReferenceContribuitor"/>
</extensions>
And the implementation of ScopeReferenceContribuitor.java:
public class ScopeReferenceContribuitor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
// Breakpoint:
[...]
}
}
This breakpoint just don't works, never is called, nothing. Even if I force an error (like an NPE) it just don't works.
What I am forgiving?
This topic seems solve my problem, but I already tested, and for some reason it just don't call the debugger on breakpoint.
I too commited my code example.
Please sign in to leave a comment.
This will only work if corresponding PSI element supports reference contributions. Historically this is done only for certain literal expressions. For PHP StringLiteralExpression is such an element.
Please elaborate on what you are trying to achieve specifically - e.g. how navigation should work (with complete example) and we'll help you to do it properly (or amend our APIs :)
Thanks for reply.
By default, PS supports references for methods when it is done like that:
class MyClass {
public function myMethod() { } <-------------------------------------------------------.
} |
|
$myClass = new MyClass; |
$myClass->myMethod(); <-- when I hold ctrl, then I can click on "myMethod" to jump to declaration above (on MyClass).
What I need is do the same thing where the method can't be "referenced naturally". For instance, a undefined method as is for the case of query scopes on Laravel (because
myScope()method points on reality toscopeMyMethod()). And I like when I hold ctrl and mouse hover "myScope" it underline then, on click, jump toscopeMyScope()declaration.$user->filterAge() --> should jumps to declaration at User::scopeFilterAge() on ctrl+clickThe code on original post (above) is my real code that doesn't works (even trigger the breakpoint at any place). My idea is that I receive the "ctrl" PsiElement, then with base on that, I could determine where is the declaration of that.
I did a small screen recorder to show what is happening currently (https://youtu.be/z1gFRJZBoKI).
I found a clue by implementing the gotoDeclarationHandler extension point. I will try it and see what I get.