Skip to content

Commit 2755d53

Browse files
authored
Merge pull request #1450 from Haehnchen/feature/tags-arguments
provide completion support for named argument inside yaml arguments context
2 parents 3e6f8fb + 690b8bb commit 2755d53

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ public static ElementPattern<PsiElement> getPhpConstPattern() {
780780
* _defaults:
781781
* bind:
782782
* $<caret>
783+
*
784+
* my.service:
785+
* arguments:
786+
* $<caret>
783787
*/
784788
static ElementPattern<PsiElement> getNamedDefaultBindPattern() {
785789
// "__defaults" key
@@ -798,18 +802,26 @@ public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext con
798802
}
799803
}).withParent(defaultsKey));
800804

805+
// "arguments" bind
806+
PsiElementPattern.Capture<YAMLMapping> argumentsKey = PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
807+
@Override
808+
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
809+
return "arguments".equals(yamlKeyValue.getKeyText());
810+
}
811+
}));
812+
801813
// complete code
802814
// bind:
803815
// $<caret>: ''
804816
PsiElementPattern.Capture<PsiElement> argumentPattern = PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withText(PlatformPatterns.string().startsWith("$")).withParent(
805-
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(bindKey)
817+
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(PlatformPatterns.or(bindKey, argumentsKey))
806818
);
807819

808820
// incomplete code
809821
// bind:
810822
// $<caret>
811823
PsiElementPattern.Capture<PsiElement> incompleteCodePattern = PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).withText(PlatformPatterns.string().startsWith("$")).withParent(
812-
PlatformPatterns.psiElement(YAMLScalar.class).withParent(bindKey)
824+
PlatformPatterns.psiElement(YAMLScalar.class).withParent(PlatformPatterns.or(bindKey, argumentsKey))
813825
);
814826

815827
return PlatformPatterns.or(argumentPattern, incompleteCodePattern);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,14 @@ public void testNamedArgumentCompletionForDefaultsBinding() {
307307
"$i"
308308
);
309309
}
310+
311+
public void testNamedArgumentCompletionForServiceArguments() {
312+
assertCompletionContains(YAMLFileType.YML, "" +
313+
"services:\n" +
314+
" Foo\\Bar:\n" +
315+
" arguments:\n" +
316+
" $<caret>: ~\n",
317+
"$i"
318+
);
319+
}
310320
}

0 commit comments

Comments
 (0)