Skip to content

Commit 87d124e

Browse files
authored
Merge pull request #1513 from Haehnchen/feature/yaml-instanceof
add navigation for services inside "_instanceof" yaml keys
2 parents 521c67f + 7fefb55 commit 87d124e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/YamlElementPatternHelper.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.jetbrains.yaml.psi.*;
2222
import org.jetbrains.yaml.psi.impl.YAMLPlainTextImpl;
2323

24+
import java.util.Arrays;
25+
2426
/**
2527
* @author Daniel Espendiller <[email protected]>
2628
*/
@@ -36,7 +38,7 @@ public class YamlElementPatternHelper {
3638
/**
3739
* services: ~
3840
*/
39-
private static PatternCondition<YAMLKeyValue> YAML_KEY_SERVICES = new YAMLKeyValuePatternCondition("services");
41+
private static final PatternCondition<YAMLKeyValue> YAML_KEY_SERVICES = new YAMLKeyValuePatternCondition("services", "_instanceof");
4042

4143
/**
4244
* config.yml, config_dev.yml,
@@ -861,16 +863,17 @@ public boolean accepts(@NotNull YAMLScalar yamlScalar, ProcessingContext process
861863

862864
private static class YAMLKeyValuePatternCondition extends PatternCondition<YAMLKeyValue> {
863865
@NotNull
864-
private final String keyText;
866+
private final String[] keyText;
865867

866-
YAMLKeyValuePatternCondition(@NotNull String keyText) {
867-
super("yaml " + keyText +" key");
868+
YAMLKeyValuePatternCondition(@NotNull String... keyText) {
869+
super("yaml " + Arrays.toString(keyText) +" key");
868870
this.keyText = keyText;
869871
}
870872

871873
@Override
872874
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext processingContext) {
873-
return this.keyText.equals(yamlKeyValue.getKeyText());
875+
return Arrays.stream(this.keyText)
876+
.anyMatch(s -> s.equals(yamlKeyValue.getKeyText()));
874877
}
875878
}
876879
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/config/yaml/YamlGoToDeclarationHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int i, Edit
175175
targets.addAll(getFactoryStringGoto(psiElement));
176176
}
177177

178+
// _instanceof:
179+
// My<caret>Class: ~
178180
// services:
179181
// My<caret>Class: ~
180182
if(YamlElementPatternHelper.getServicesKeyPattern().accepts(psiElement)) {

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/yaml/YamlGoToDeclarationHandlerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,17 @@ public void testNavigateToTaggedServicesForSymfony33Shortcut() {
170170
public void testNavigateToClassServiceAsKeyForSymfony33() {
171171
assertNavigationMatch("services.yml", "" +
172172
"services:\n" +
173-
" Fo<caret>o\\Bar: ~\n" +
173+
" Fo<caret>o\\Bar: ~\n",
174174
PlatformPatterns.psiElement(PhpClass.class)
175175
);
176+
177+
assertNavigationMatch(YAMLFileType.YML, "" +
178+
"services:\n" +
179+
"\n" +
180+
" _instanceof:\n" +
181+
" Fo<caret>o\\Bar:\n" +
182+
" tags: ['console.command']",
183+
PlatformPatterns.psiElement(PhpClass.class));
176184
}
177185

178186
public void testNavigateForCallsMethodIsProvided() {

0 commit comments

Comments
 (0)