Files
ConfigKit/internal/engine/inheritance_load.go

68 lines
1.8 KiB
Go

package engine
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
func containsInheritanceDirective(root *document.Node) bool {
var visit func(*document.Node) bool
visit = func(node *document.Node) bool {
if node == nil {
return false
}
switch node.Kind {
case document.Mapping:
for _, entry := range node.Mapping {
if entry.Key == inheritanceKey || visit(entry.Value) {
return true
}
}
case document.Sequence:
for _, child := range node.Sequence {
if visit(child) {
return true
}
}
}
return false
}
return visit(root)
}
func inheritanceVersionDiagnostic(rule *VersionRule, expanded *inheritanceScope) *Diagnostic {
if rule == nil || expanded == nil {
return nil
}
for _, operation := range expanded.operations {
var location Location
var affected bool
if operation.control != nil {
affected = pathsIntersect(operation.control.path, rule.Path)
if len(operation.control.locations) != 0 {
location = operation.control.locations[0]
}
} else if operation.transfer != nil {
if relative, within := relativeHistoryPath(operation.transfer.to, rule.Path); within {
affected = fragmentVersionClaim(operation.parent, &VersionRule{Path: relative}) != nil
} else if pathContains(rule.Path, operation.transfer.to) {
affected = true
}
if len(operation.transfer.locations) != 0 {
location = operation.transfer.locations[0]
}
}
if affected {
return &Diagnostic{
Code: CodeInheritanceVersion, Severity: SeverityError, Path: rule.Path.clone(),
Message: "inheritance cannot change the schema-version path", Primary: &location,
}
}
}
return nil
}
func inheritanceOperations(expanded *inheritanceScope) []inheritanceOperation {
if expanded == nil {
return nil
}
return cloneInheritanceOperations(expanded.operations)
}