/** * Attach all parent array keys to list (foo:\n bar:): [foo, bar] * * @param yamlKeyValue current key value context * @param key the key list */ public static void getParentArrayKeys(YAMLKeyValue yamlKeyValue, List<String> key) { key.add(yamlKeyValue.getKeyText()); PsiElement yamlCompount = yamlKeyValue.getParent(); if(yamlCompount instanceof YAMLCompoundValue) { PsiElement yamlKeyValueParent = yamlCompount.getParent(); if(yamlKeyValueParent instanceof YAMLKeyValue) { getParentArrayKeys((YAMLKeyValue) yamlKeyValueParent, key); } } }
PsiElement yamlMapping = yamlKeyValue.getParent(); if(yamlMapping instanceof YAMLMapping) { PsiElement parent = yamlMapping.getParent();
@Override protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) { YAMLKeyValue yamlKeyValue = PsiTreeUtil.getParentOfType(completionParameters.getOriginalPosition(), YAMLKeyValue.class); if(yamlKeyValue != null) { PsiElement compoundValue = yamlKeyValue.getParent(); if(compoundValue instanceof YAMLCompoundValue) { // path and pattern are valid String pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "path", false); if(pattern == null) { pattern = YamlHelper.getYamlKeyValueAsString((YAMLCompoundValue) compoundValue, "pattern", false); } if(pattern != null) { Matcher matcher = Pattern.compile("\\{(\\w+)}").matcher(pattern); while(matcher.find()){ completionResultSet.addElement(LookupElementBuilder.create(matcher.group(1))); } } } } } }