DocumentationElement (@Nullable PsiElement contextElement) { if (contextElement == null) { return null; } final YamlMetaTypeProvider modelProvider = getMetaTypeProvider(contextElement); if (modelProvider == null) { return null; } YAMLPsiElement yamlElement = getTypedAncestorOrSelf(contextElement, YAMLPsiElement.class); if (yamlElement == null) { return null; } final YamlMetaTypeProvider.MetaTypeProxy objectMetatype; // describes the object type YamlMetaTypeProvider.MetaTypeProxy fieldMetatype; // describes the field if (yamlElement instanceof YAMLValue) { fieldMetatype = modelProvider.getMetaTypeProxy(yamlElement); final YAMLMapping mapping = getTypedAncestorOrSelf(yamlElement, YAMLMapping.class); objectMetatype = mapping != null ? modelProvider.getMetaTypeProxy(mapping) : null; // if the element is the value of the key "kind" and there is a "apiVersion" key in the same mapping, // then we show documentation for the resource type, not the field if (mapping != null && fieldMetatype != null && fieldMetatype.getField().getName().equals("kind") && mapping.getKeyValues().stream().anyMatch(kv -> "apiVersion".equals(kv.getKeyText().trim()))) { fieldMetatype = null; } } else if (yamlElement instanceof YAMLKeyValue) { objectMetatype = modelProvider.getMetaTypeProxy(yamlElement); fieldMetatype = modelProvider.getKeyValueMetaType((YAMLKeyValue)yamlElement); } else { objectMetatype = modelProvider.getMetaTypeProxy(yamlElement); fieldMetatype = null; } if (objectMetatype == null) { return null; } return new DocumentationElement(contextElement.getManager(), objectMetatype.getMetaType(), fieldMetatype != null ? fieldMetatype.getField() : null); }