Skip to content

Commit acabcca

Browse files
committed
add yaml routing option completion
1 parent 2c9b22d commit acabcca

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

src/fr/adrienbrault/idea/symfony2plugin/config/yaml/YamlCompletionContributor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void addCompletions(@NotNull CompletionParameters parameters,
115115
extend(CompletionType.BASIC, YamlElementPatternHelper.getSingleLineScalarKey("resource"), new SymfonyBundleFileCompletionProvider("Resources/config", "Controller"));
116116

117117
extend(CompletionType.BASIC, YamlElementPatternHelper.getSuperParentArrayKey("services"), new YamlCompletionProvider(new String[] {"class", "public", "tags", "calls", "arguments", "scope"}));
118+
extend(CompletionType.BASIC, YamlElementPatternHelper.getWithFirstRootKey(), new RouteKeyNameYamlCompletionProvider(new String[] {"pattern", "defaults", "path", "requirements", "methods", "condition", "resource", "prefix"}));
118119

119120
extend(CompletionType.BASIC, StandardPatterns.and(
120121
YamlElementPatternHelper.getInsideKeyValue("tags"),
@@ -389,5 +390,20 @@ public boolean value(PsiElement psiElement) {
389390
}
390391
}
391392

393+
private static class RouteKeyNameYamlCompletionProvider extends YamlCompletionProvider {
394+
395+
public RouteKeyNameYamlCompletionProvider(String[] lookups) {
396+
super(lookups);
397+
}
398+
399+
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
400+
401+
if(!YamlHelper.isRoutingFile(parameters.getOriginalFile())) {
402+
return;
403+
}
404+
405+
super.addCompletions(parameters, context, resultSet);
406+
}
407+
}
392408
}
393409

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

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

3-
import com.intellij.patterns.ElementPattern;
4-
import com.intellij.patterns.PlatformPatterns;
5-
import com.intellij.patterns.PsiElementPattern;
6-
import com.intellij.patterns.StandardPatterns;
3+
import com.intellij.patterns.*;
74
import com.intellij.psi.PsiElement;
85
import com.intellij.psi.PsiFile;
96
import org.jetbrains.yaml.YAMLElementTypes;
@@ -187,6 +184,64 @@ public static ElementPattern<PsiElement> getOrmRoot() {
187184
);
188185
}
189186

187+
public static ElementPattern<PsiElement> getWithFirstRootKey() {
188+
return PlatformPatterns.or(
189+
190+
// match
191+
//
192+
// xxx:
193+
// refer|: xxx
194+
PlatformPatterns
195+
.psiElement(YAMLTokenTypes.SCALAR_KEY)
196+
.withParent(PlatformPatterns
197+
.psiElement(YAMLKeyValue.class)
198+
.withParent(PlatformPatterns
199+
.psiElement(YAMLElementTypes.COMPOUND_VALUE)
200+
.withParent(PlatformPatterns
201+
.psiElement(YAMLKeyValue.class)
202+
.withParent(PlatformPatterns
203+
.psiElement(YAMLDocument.class)
204+
)
205+
)
206+
)
207+
)
208+
.withLanguage(YAMLLanguage.INSTANCE),
209+
210+
// match
211+
//
212+
// xxx:
213+
// xxx: xxx
214+
// refer|
215+
PlatformPatterns
216+
.psiElement(YAMLTokenTypes.TEXT)
217+
.withParent(PlatformPatterns
218+
.psiElement(YAMLElementTypes.COMPOUND_VALUE)
219+
.withParent(PlatformPatterns
220+
.psiElement(YAMLKeyValue.class)
221+
.withParent(PlatformPatterns
222+
.psiElement(YAMLDocument.class)
223+
)
224+
)
225+
)
226+
.withLanguage(YAMLLanguage.INSTANCE),
227+
228+
// match
229+
//
230+
// xxx:
231+
// refer|
232+
// xxx: xxx
233+
PlatformPatterns
234+
.psiElement(YAMLTokenTypes.TEXT)
235+
.withParent(PlatformPatterns
236+
.psiElement(YAMLKeyValue.class)
237+
.withParent(PlatformPatterns
238+
.psiElement(YAMLDocument.class)
239+
)
240+
)
241+
.withLanguage(YAMLLanguage.INSTANCE)
242+
);
243+
}
244+
190245
/**
191246
* provides auto complete on
192247
*
@@ -423,7 +478,6 @@ private static ElementPattern<? extends PsiFile> getOrmFilePattern() {
423478
return PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith("orm.yml"));
424479
}
425480

426-
427481
private static PsiElementPattern.Capture<PsiElement> getKeyPattern(String keyName) {
428482
return PlatformPatterns
429483
.psiElement(YAMLTokenTypes.TEXT)

src/fr/adrienbrault/idea/symfony2plugin/routing/inspection/DuplicateLocalRouteInspection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, bool
2525
// routing.yml
2626
// comment.routing.yml
2727
// routing/foo.yml
28-
if(psiFile.getName().contains("routing") || psiFile.getVirtualFile().getPath().contains("/routing")) {
28+
if(YamlHelper.isRoutingFile(psiFile)) {
2929
YAMLDocument document = PsiTreeUtil.findChildOfType(psiFile, YAMLDocument.class);
3030
if(document != null) {
3131
YamlHelper.attachDuplicateKeyInspection(document, holder);

src/fr/adrienbrault/idea/symfony2plugin/util/yaml/YamlHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,8 @@ public static void attachDuplicateKeyInspection(PsiElement keyContext, @NotNull
539539

540540
}
541541

542+
public static boolean isRoutingFile(PsiFile psiFile) {
543+
return psiFile.getName().contains("routing") || psiFile.getVirtualFile().getPath().contains("/routing");
544+
}
545+
542546
}

0 commit comments

Comments
 (0)