Skip to content

Commit 43e73a3

Browse files
committed
allow path navigation for Twig templates in all php related navigation handler #1076
1 parent abaf333 commit 43e73a3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
1111
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
1212
import fr.adrienbrault.idea.symfony2plugin.TwigHelper;
13-
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
1413
import org.apache.commons.lang.StringUtils;
1514
import org.jetbrains.annotations.Nullable;
1615

@@ -22,16 +21,16 @@ public class PhpTemplateGlobalStringGoToDeclarationHandler implements GotoDeclar
2221
@Nullable
2322
@Override
2423
public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Editor editor) {
25-
26-
if(!Symfony2ProjectComponent.isEnabled(psiElement)) {
24+
if(!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement.getContainingFile() instanceof PhpFile)) {
2725
return null;
2826
}
2927

30-
if(!(psiElement.getContainingFile() instanceof PhpFile) || !(psiElement.getContext() instanceof StringLiteralExpression)) {
28+
PsiElement stringLiteral = psiElement.getContext();
29+
if(!(stringLiteral instanceof StringLiteralExpression)) {
3130
return new PsiElement[0];
3231
}
3332

34-
if(!Symfony2ProjectComponent.isEnabled(psiElement) || !PlatformPatterns.or(
33+
if(!PlatformPatterns.or(
3534
PlatformPatterns
3635
.psiElement(StringLiteralExpression.class)
3736
.withText(PlatformPatterns.or(
@@ -46,17 +45,19 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
4645
PlatformPatterns.string().endsWith("twig\"")
4746
))
4847
.withLanguage(PhpLanguage.INSTANCE)
49-
).accepts(psiElement.getContext())) {
48+
).accepts(stringLiteral)) {
5049

5150
return new PsiElement[0];
5251
}
5352

54-
String templateName = PsiElementUtils.getText(psiElement);
53+
String templateName = ((StringLiteralExpression) stringLiteral).getContents();
5554
if(StringUtils.isBlank(templateName)) {
5655
return new PsiElement[0];
5756
}
5857

59-
return TwigHelper.getTemplatePsiElements(psiElement.getProject(), templateName);
58+
// file and directory navigation:
59+
// foo.html.twig, foobar/foo.html.twig
60+
return TwigHelper.getTemplateNavigationOnOffset(psiElement.getProject(), templateName, i - psiElement.getTextRange().getStartOffset()).toArray(new PsiElement[0]);
6061
}
6162

6263
@Nullable

0 commit comments

Comments
 (0)