func edgeKindLess(kind1, kind2 string) bool { // General ordering: // anchor edge kinds before non-anchor edge kinds // forward edges before reverse edges // edgeOrdering[i] (and variants) before edgeOrdering[i+1:] // edge variants after root edge kind (ordered lexicographically) // otherwise, order lexicographically if kind1 == kind2 { return false } else if a1, a2 := schema.IsAnchorEdge(kind1), schema.IsAnchorEdge(kind2); a1 != a2 { return a1 } else if d1, d2 := schema.EdgeDirection(kind1), schema.EdgeDirection(kind2); d1 != d2 { return d1 == schema.Forward } kind1, kind2 = schema.Canonicalize(kind1), schema.Canonicalize(kind2) for _, kind := range edgeOrdering { if kind1 == kind { return true } else if kind2 == kind { return false } else if v1, v2 := schema.IsEdgeVariant(kind1, kind), schema.IsEdgeVariant(kind2, kind); v1 != v2 { return v1 } else if v1 { return kind1 < kind2 } } return kind1 < kind2 }
func isRefKind(requestedKind xpb.CrossReferencesRequest_ReferenceKind, edgeKind string) bool { switch requestedKind { case xpb.CrossReferencesRequest_NO_REFERENCES: return false case xpb.CrossReferencesRequest_ALL_REFERENCES: return schema.IsEdgeVariant(edgeKind, revRefEdge) default: panic("unhandled CrossReferencesRequest_ReferenceKind") } }
func isDocKind(requestedKind xpb.CrossReferencesRequest_DocumentationKind, edgeKind string) bool { switch requestedKind { case xpb.CrossReferencesRequest_NO_DOCUMENTATION: return false case xpb.CrossReferencesRequest_ALL_DOCUMENTATION: return schema.IsEdgeVariant(edgeKind, revDocumentsEdge) default: panic("unhandled CrossDocumentationRequest_DocumentationKind") } }
func isDefKind(requestedKind xpb.CrossReferencesRequest_DefinitionKind, edgeKind string) bool { switch requestedKind { case xpb.CrossReferencesRequest_NO_DEFINITIONS: return false case xpb.CrossReferencesRequest_FULL_DEFINITIONS: return edgeKind == revDefinesEdge case xpb.CrossReferencesRequest_BINDING_DEFINITIONS: return edgeKind == revDefinesBindingEdge case xpb.CrossReferencesRequest_ALL_DEFINITIONS: return schema.IsEdgeVariant(edgeKind, revDefinesEdge) default: panic("unhandled CrossReferencesRequest_DefinitionKind") } }