|
40 | 40 | import org.jetbrains.yaml.psi.YAMLKeyValue; |
41 | 41 | import org.jetbrains.yaml.psi.YAMLSequence; |
42 | 42 |
|
| 43 | +import java.util.regex.Matcher; |
| 44 | +import java.util.regex.Pattern; |
| 45 | + |
43 | 46 | /** |
44 | 47 | * @author Daniel Espendiller <daniel@espendiller.net> |
45 | 48 | */ |
@@ -116,6 +119,7 @@ public void addCompletions(@NotNull CompletionParameters parameters, |
116 | 119 |
|
117 | 120 | extend(CompletionType.BASIC, YamlElementPatternHelper.getSuperParentArrayKey("services"), new YamlCompletionProvider(new String[] {"class", "public", "tags", "calls", "arguments", "scope"})); |
118 | 121 | extend(CompletionType.BASIC, YamlElementPatternHelper.getWithFirstRootKey(), new RouteKeyNameYamlCompletionProvider(new String[] {"pattern", "defaults", "path", "requirements", "methods", "condition", "resource", "prefix"})); |
| 122 | + extend(CompletionType.BASIC, YamlElementPatternHelper.getParentKeyName("requirements"), new RouteRequirementsCompletion()); |
119 | 123 |
|
120 | 124 | extend(CompletionType.BASIC, StandardPatterns.and( |
121 | 125 | YamlElementPatternHelper.getInsideKeyValue("tags"), |
@@ -405,5 +409,34 @@ public void addCompletions(@NotNull CompletionParameters parameters, ProcessingC |
405 | 409 | super.addCompletions(parameters, context, resultSet); |
406 | 410 | } |
407 | 411 | } |
| 412 | + |
| 413 | + /** |
| 414 | + * "requirements" on "path/pattern: /hello/{name}" |
| 415 | + */ |
| 416 | + private class RouteRequirementsCompletion extends CompletionProvider<CompletionParameters> { |
| 417 | + @Override |
| 418 | + protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { |
| 419 | + YAMLKeyValue yamlKeyValue = PsiTreeUtil.getParentOfType(completionParameters.getOriginalPosition(), YAMLKeyValue.class); |
| 420 | + if(yamlKeyValue != null) { |
| 421 | + PsiElement compoundValue = yamlKeyValue.getParent(); |
| 422 | + if(compoundValue instanceof YAMLCompoundValue) { |
| 423 | + |
| 424 | + // path and pattern are valid |
| 425 | + String pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "path", false); |
| 426 | + if(pattern == null) { |
| 427 | + pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "pattern", false); |
| 428 | + } |
| 429 | + |
| 430 | + if(pattern != null) { |
| 431 | + Matcher matcher = Pattern.compile("\\{(\\w+)}").matcher(pattern); |
| 432 | + while(matcher.find()){ |
| 433 | + completionResultSet.addElement(LookupElementBuilder.create(matcher.group(1))); |
| 434 | + } |
| 435 | + } |
| 436 | + |
| 437 | + } |
| 438 | + } |
| 439 | + } |
| 440 | + } |
408 | 441 | } |
409 | 442 |
|
0 commit comments