Add ctrl-mouse event on twig template string
This code is workey:
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
final String regexp = "['\"][\\w]*:[\\w]*:[\\w]+\\.[a-z]+\\.twig[\"']";
PsiElementPattern.Capture<StringLiteralExpression> psiElementCapture = PlatformPatterns.psiElement(
StringLiteralExpression.class).withText(StandardPatterns.string().matches(regexp));
registrar.registerReferenceProvider(
psiElementCapture,
new TwigViewPsiReferenceProvider(),
PsiReferenceRegistrar.DEFAULT_PRIORITY);
I choose StringLiteralExpression because PSIViewer show this:
For experiment I try change StringLiteralExpression to LeafPsiElement:
final String regexp = "['\"][\\w]*:[\\w]*:[\\w]+\\.[a-z]+\\.twig[\"']";
PsiElementPattern.Capture<LeafPsiElement> psiElementCapture = PlatformPatterns.psiElement(
LeafPsiElement.class).withText(StandardPatterns.string().matches(regexp));
registrar.registerReferenceProvider(
psiElementCapture,
new TwigViewPsiReferenceProvider(),
PsiReferenceRegistrar.DEFAULT_PRIORITY);
And it does not work. By debugger I set break points to initialize of TwigViewPsiReferenceProvider(), no action was found on this. But if type of PSI set in StringLiteralExpression action has been.
I choose LeafPsiElement because this:
Also I try to use else types of psiElement, and no one didn't work.
I try this types:
com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment
com.intellij.psi.impl.source.tree.LeafPsiElement
com.jetbrains.php.lang.psi.elements.Variable
com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag
What do I wrong?
Please sign in to leave a comment.