Skip to content

constraint message property linemarker should only be triggered on smallest (leaf) elements #1952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2022
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 @@ -3,6 +3,7 @@
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.lexer.PhpTokenTypes;
import com.jetbrains.php.lang.psi.elements.Field;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionContributor;
Expand Down Expand Up @@ -33,7 +34,10 @@ public void register(@NotNull GotoCompletionRegistrarParameter registrar) {

@NotNull
public static PsiElementPattern.Capture<PsiElement> getConstraintPropertyMessagePattern() {
return PlatformPatterns.psiElement().withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
return PlatformPatterns.psiElement().withElementType(PlatformPatterns.elementType().or(
PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE,
PhpTokenTypes.STRING_LITERAL
)).withParent(PlatformPatterns.psiElement(StringLiteralExpression.class)
.withParent(PlatformPatterns.psiElement(Field.class)
.withName(PlatformPatterns.string().startsWith("message"))
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.intellij.patterns.PatternCondition;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.PsiFile;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.lang.PhpFileType;
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
Expand All @@ -13,9 +12,6 @@
import org.jetbrains.yaml.YAMLFileType;
import org.jetbrains.yaml.psi.YAMLKeyValue;

import java.util.Arrays;
import java.util.Collection;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
*
Expand All @@ -25,6 +21,8 @@ public class ServiceLineMarkerProviderTest extends SymfonyLightCodeInsightFixtur

public void setUp() throws Exception {
super.setUp();

myFixture.copyFileToProject("validators.de.yml", "translations/validators.de.yml");
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("ServiceLineMarkerProvider.php"));
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("SymfonyPhpReferenceContributor.php"));
}
Expand Down Expand Up @@ -211,4 +209,20 @@ public void testThatAutowireConstructorIsGivenALineMarker() {
"}"
), markerInfo -> markerInfo.getLineMarkerTooltip() != null && markerInfo.getLineMarkerTooltip().toLowerCase().contains("autowire"));
}

public void testNavigateToTranslationForConstraintMessage() {
assertLineMarker(myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
"class LessThan extends \\Symfony\\Component\\Validator\\Constraint\n" +
"{\n" +
" public $message = 'validator_message';\n" +
"}"
), new LineMarker.ToolTipEqualsAssert("Navigate to translation"));

assertLineMarker(myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
"class LessThan extends \\Symfony\\Component\\Validator\\Constraint\n" +
"{\n" +
" public $message = \"validator_message\";\n" +
"}"
), new LineMarker.ToolTipEqualsAssert("Navigate to translation"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ interface ContainerInterface
{
public function get();
}
}

namespace Symfony\Component\Validator
{
abstract class Constraint
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo_yaml:
symfony.great: 'YAML Symfony2 is really great'
validator_message: 'YAML Symfony2 is really great'