Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @No
}
);

// service('<caret>'), ref('<caret>') (ref is deprecated)
psiReferenceRegistrar.registerReferenceProvider(
PhpElementsUtil.getFunctionWithFirstStringPattern("service", "ref"),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
return new PsiReference[0];
}

return new PsiReference[]{ new ServiceReference((StringLiteralExpression) psiElement, true) };
}
}
);

psiReferenceRegistrar.registerReferenceProvider(
PlatformPatterns.psiElement(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE),
new PsiReferenceProvider() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.adrienbrault.idea.symfony2plugin.dic.registrar;

import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.patterns.XmlPatterns;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
Expand All @@ -28,10 +28,9 @@ public class DicGotoCompletionRegistrar implements GotoCompletionRegistrar {

@Override
public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

// getParameter('FOO')
registrar.register(
XmlPatterns.psiElement().withParent(PhpElementsUtil.getMethodWithFirstStringPattern()), psiElement -> {
PlatformPatterns.psiElement().withParent(PhpElementsUtil.getMethodWithFirstStringPattern()), psiElement -> {

PsiElement context = psiElement.getContext();
if (!(context instanceof StringLiteralExpression)) {
Expand All @@ -52,6 +51,17 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {
}
);

// param('<caret>')
registrar.register(
PlatformPatterns.psiElement().withParent(PhpElementsUtil.getFunctionWithFirstStringPattern("param")), psiElement -> {
PsiElement context = psiElement.getContext();
if (!(context instanceof StringLiteralExpression)) {
return null;
}

return new ParameterContributor((StringLiteralExpression) context);
}
);
}

private static class ParameterContributor extends GotoCompletionProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.openapi.project.Project;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PatternCondition;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ProcessingContext;
import com.intellij.util.Processor;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.codeInsight.PhpCodeInsightUtil;
Expand All @@ -29,6 +31,7 @@
import fr.adrienbrault.idea.symfony2plugin.dic.MethodReferenceBag;
import fr.adrienbrault.idea.symfony2plugin.util.psi.PsiElementAssertUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -296,6 +299,26 @@ static public PsiElementPattern.Capture<StringLiteralExpression> getMethodWithFi
.withLanguage(PhpLanguage.INSTANCE);
}

static public PsiElementPattern.Capture<StringLiteralExpression> getFunctionWithFirstStringPattern(@NotNull String... functionName) {
return PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(ParameterList.class)
.withFirstChild(
PlatformPatterns.psiElement(PhpElementTypes.STRING)
)
.withParent(
PlatformPatterns.psiElement(FunctionReference.class).with(new PatternCondition<FunctionReference>("function match") {
@Override
public boolean accepts(@NotNull FunctionReference functionReference, ProcessingContext processingContext) {
return ArrayUtils.contains(functionName, functionReference.getName());
}
})
)
)
.withLanguage(PhpLanguage.INSTANCE);
}

/**
* $foo->bar('<caret>')
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ private PsiReference[] getPsiReferenceBase(PsiElement psiElement) {
return new PsiReference[0];
}

private class Call {
private String className;
private String methodName;
private static class Call {
private final String className;
private final String methodName;
private int index = 0;

public Call(String className, String methodName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void setUp() throws Exception {
super.setUp();
myFixture.copyFileToProject("classes.php");
myFixture.copyFileToProject("tags.yml");
myFixture.copyFileToProject("services.yml");
}

public String getTestDataPath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
services:
my_nice_service: ~
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ public void testParameterContributorProxied() {
);
}
}

public void testParameterContributorFor() {
assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" +
"param('<caret>')",
"foo"
);

assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
"param('fo<caret>o')",
PlatformPatterns.psiElement()
);
}
}