Skip to content

Commit eb45790

Browse files
committed
support also incomplete yaml code argument completion
1 parent a8bc032 commit eb45790

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -716,21 +716,43 @@ public static ElementPattern<PsiElement> getTaggedServicePattern() {
716716
* _defaults:
717717
* bind:
718718
* $<caret>: ''
719+
*
720+
* _defaults:
721+
* bind:
722+
* $<caret>
719723
*/
720-
static PsiElementPattern.Capture<PsiElement> getNamedDefaultBindPattern() {
721-
return PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withText(PlatformPatterns.string().startsWith("$")).withParent(
722-
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
723-
@Override
724-
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
725-
return "bind".equals(yamlKeyValue.getKeyText());
726-
}
727-
}).withParent(PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
728-
@Override
729-
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
730-
return "_defaults".equals(yamlKeyValue.getKeyText());
731-
}
732-
})))))
724+
static ElementPattern<PsiElement> getNamedDefaultBindPattern() {
725+
// "__defaults" key
726+
PsiElementPattern.Capture<YAMLMapping> defaultsKey = PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
727+
@Override
728+
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
729+
return "_defaults".equals(yamlKeyValue.getKeyText());
730+
}
731+
}));
732+
733+
// "bind" bind
734+
PsiElementPattern.Capture<YAMLMapping> bindKey = PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
735+
@Override
736+
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
737+
return "bind".equals(yamlKeyValue.getKeyText());
738+
}
739+
}).withParent(defaultsKey));
740+
741+
// complete code
742+
// bind:
743+
// $<caret>: ''
744+
PsiElementPattern.Capture<PsiElement> argumentPattern = PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withText(PlatformPatterns.string().startsWith("$")).withParent(
745+
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(bindKey)
733746
);
747+
748+
// incomplete code
749+
// bind:
750+
// $<caret>
751+
PsiElementPattern.Capture<PsiElement> incompleteCodePattern = PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).withText(PlatformPatterns.string().startsWith("$")).withParent(
752+
PlatformPatterns.psiElement(YAMLScalar.class).withParent(bindKey)
753+
);
754+
755+
return PlatformPatterns.or(argumentPattern, incompleteCodePattern);
734756
}
735757

736758
/**

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package fr.adrienbrault.idea.symfony2plugin.tests.config.yaml;
22

3-
import com.intellij.patterns.PlatformPatterns;
43
import com.jetbrains.php.lang.PhpFileType;
5-
import com.jetbrains.php.lang.psi.elements.PhpClass;
6-
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlCompletionContributor;
74
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
85
import org.jetbrains.yaml.YAMLFileType;
96

10-
import java.io.File;
11-
import java.net.URL;
12-
137
/**
148
* @author Daniel Espendiller <daniel@espendiller.net>
159
*

0 commit comments

Comments
 (0)