Activate sibling inheritance in configuration loading
This commit is contained in:
53
internal/engine/inheritance_load.go
Normal file
53
internal/engine/inheritance_load.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package engine
|
||||
|
||||
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
||||
|
||||
func containsInheritanceDirective(root *document.Node) bool {
|
||||
found := false
|
||||
walkDocument(root, Path{}, func(path Path, _ *document.Node) {
|
||||
if len(path.segments) != 0 && path.segments[len(path.segments)-1].kind == pathSegmentKey &&
|
||||
path.segments[len(path.segments)-1].key == inheritanceKey {
|
||||
found = true
|
||||
}
|
||||
})
|
||||
return found
|
||||
}
|
||||
|
||||
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 = documentAtPath(operation.parent, relative)
|
||||
} 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 expanded.operations
|
||||
}
|
||||
Reference in New Issue
Block a user