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 @@ -716,21 +716,43 @@ public static ElementPattern<PsiElement> getTaggedServicePattern() {
* _defaults:
* bind:
* $<caret>: ''
*
* _defaults:
* bind:
* $<caret>
*/
static PsiElementPattern.Capture<PsiElement> getNamedDefaultBindPattern() {
return PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withText(PlatformPatterns.string().startsWith("$")).withParent(
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
@Override
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
return "bind".equals(yamlKeyValue.getKeyText());
}
}).withParent(PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
@Override
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
return "_defaults".equals(yamlKeyValue.getKeyText());
}
})))))
static ElementPattern<PsiElement> getNamedDefaultBindPattern() {
// "__defaults" key
PsiElementPattern.Capture<YAMLMapping> defaultsKey = PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
@Override
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
return "_defaults".equals(yamlKeyValue.getKeyText());
}
}));

// "bind" bind
PsiElementPattern.Capture<YAMLMapping> bindKey = PlatformPatterns.psiElement(YAMLMapping.class).withParent(PlatformPatterns.psiElement(YAMLKeyValue.class).with(new PatternCondition<YAMLKeyValue>("KeyText") {
@Override
public boolean accepts(@NotNull YAMLKeyValue yamlKeyValue, ProcessingContext context) {
return "bind".equals(yamlKeyValue.getKeyText());
}
}).withParent(defaultsKey));

// complete code
// bind:
// $<caret>: ''
PsiElementPattern.Capture<PsiElement> argumentPattern = PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withText(PlatformPatterns.string().startsWith("$")).withParent(
PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(bindKey)
);

// incomplete code
// bind:
// $<caret>
PsiElementPattern.Capture<PsiElement> incompleteCodePattern = PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).withText(PlatformPatterns.string().startsWith("$")).withParent(
PlatformPatterns.psiElement(YAMLScalar.class).withParent(bindKey)
);

return PlatformPatterns.or(argumentPattern, incompleteCodePattern);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package fr.adrienbrault.idea.symfony2plugin.tests.config.yaml;

import com.intellij.patterns.PlatformPatterns;
import com.jetbrains.php.lang.PhpFileType;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlCompletionContributor;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;
import org.jetbrains.yaml.YAMLFileType;

import java.io.File;
import java.net.URL;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
*
Expand Down