10000 fix global twig name navigation in php files, because of some api cha… · Koc/idea-php-symfony2-plugin@9100dee · GitHub
[go: up one dir, main page]

Skip to content

Commit 9100dee

Browse files
committed
fix global twig name navigation in php files, because of some api changes Haehnchen#450, Haehnchen#456
1 parent 3c48e7d commit 9100dee

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/PhpTemplateGlobalStringGoToDeclarationHandler.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import com.intellij.patterns.PlatformPatterns;
77
import com.intellij.psi.PsiElement;
88
import com.jetbrains.php.lang.PhpLanguage;
9-
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
9+
import com.jetbrains.php.lang.psi.PhpFile;
10+
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1011
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1112
import fr.adrienbrault.idea.symfony2plugin.TwigHelper;
1213
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
14+
import org.apache.commons.lang.StringUtils;
1315
import org.jetbrains.annotations.Nullable;
1416

1517
/**
@@ -21,27 +23,35 @@ public class PhpTemplateGlobalStringGoToDeclarationHandler implements GotoDeclar
2123
@Override
2224
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {
2325

26+
if(!(psiElement.getContainingFile() instanceof PhpFile) || !(psiElement.getContext() instanceof StringLiteralExpression)) {
27+
return new PsiElement[0];
28+
}
29+
2430
if(!Symfony2ProjectComponent.isEnabled(psiElement) || !PlatformPatterns.or(
2531
PlatformPatterns
26-
.psiElement(PhpTokenTypes.STRING_LITERAL)
32+
.psiElement(StringLiteralExpression.class)
2733
.withText(PlatformPatterns.or(
2834
PlatformPatterns.string().endsWith("twig'"),
2935
PlatformPatterns.string().endsWith("twig\"")
3036
))
3137
.withLanguage(PhpLanguage.INSTANCE),
3238
PlatformPatterns
33-
.psiElement(PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE)
39+
.psiElement(StringLiteralExpression.class)
3440
.withText(PlatformPatterns.or(
3541
PlatformPatterns.string().endsWith("twig'"),
3642
PlatformPatterns.string().endsWith("twig\"")
3743
))
3844
.withLanguage(PhpLanguage.INSTANCE)
39-
).accepts(psiElement)) {
45+
).accepts(psiElement.getContext())) {
4046

4147
return new PsiElement[0];
4248
}
4349

4450
String templateName = PsiElementUtils.getText(psiElement);
51+
if(StringUtils.isBlank(templateName)) {
52+
return new PsiElement[0];
53+
}
54+
4555
return TwigHelper.getTemplatePsiElements(psiElement.getProject(), templateName);
4656
}
4757

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fr.adrienbrault.idea.symfony2plugin.tests.templating;
2+
3+
import com.jetbrains.php.lang.PhpFileType;
4+
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
5+
6+
/**
7+
* @author Daniel Espendiller <daniel@espendiller.net>
8+
* @see fr.adrienbrault.idea.symfony2plugin.templating.PhpTemplateGlobalStringGoToDeclarationHandler
9+
*/
10+
public class PhpTemplateGlobalStringGoToDeclarationHandlerTest extends SymfonyLightCodeInsightFixtureTestCase {
11+
12+
public void setUp() throws Exception {
13+
super.setUp();
14+
15+
createDummyFiles(
16+
"app/Resources/views/layout.html.twig"
17+
);
18+
}
19+
20+
public void testTemplateGoTo() {
21+
assertNavigationContainsFile(PhpFileType.INSTANCE, "<?php '::layout.<caret>html.twig'", "layout.html.twig");
22+
assertNavigationContainsFile(PhpFileType.INSTANCE, "<?php \"::layout.<caret>html.twig\"", "layout.html.twig");
23+
assertNavigationContainsFile(PhpFileType.INSTANCE, "<?php 'layout.<caret>html.twig'", "layout.html.twig");
24+
}
25+
}

0 commit comments

Comments
 (0)
0