Allow configuration names in application paths

This commit is contained in:
2026-11-02 00:35:37 +00:00
parent 5b03ca6278
commit 1fd0adc571
8 changed files with 73 additions and 35 deletions

View File

@@ -108,7 +108,7 @@ func prepareOverrideBatch(base overridePreparationInput, sources []SourceInfo, o
})
continue
}
if pathContainsDirective(override.Path) || pathContainsInheritanceDirective(override.Path) {
if pathContainsInheritanceDirective(override.Path) {
diagnostics = append(diagnostics, Diagnostic{
Code: CodeOverrideDirective, Severity: SeverityError, Path: override.Path.clone(),
Message: "configuration overrides cannot create configuration directives", Primary: location,
@@ -125,7 +125,7 @@ func prepareOverrideBatch(base overridePreparationInput, sources []SourceInfo, o
diagnostics = append(diagnostics, diagnostic)
continue
}
if relative, ok := overrideStructuralDirectivePath(value, Path{}); ok {
if relative, ok := overrideInheritancePath(value, Path{}); ok {
diagnostics = append(diagnostics, Diagnostic{
Code: CodeOverrideDirective, Severity: SeverityError, Path: appendOverridePath(override.Path, relative),
Message: "configuration overrides cannot create configuration directives", Primary: location,
@@ -201,15 +201,6 @@ func validateOverridePath(path Path, root *document.Node, lookup *documentLookup
return nil
}
func pathContainsDirective(path Path) bool {
for _, segment := range path.segments {
if segment.key == directiveKey {
return true
}
}
return false
}
func pathContainsInheritanceDirective(path Path) bool {
for _, segment := range path.segments {
if segment.key == inheritanceKey {
@@ -225,27 +216,23 @@ func appendOverridePath(base, relative Path) Path {
return result
}
func overrideStructuralDirectivePath(node *document.Node, path Path) (Path, bool) {
return overrideStructuralDirectivePathAt(node, path)
}
func overrideStructuralDirectivePathAt(node *document.Node, path Path) (Path, bool) {
func overrideInheritancePath(node *document.Node, path Path) (Path, bool) {
if node == nil {
return Path{}, false
}
if node.Kind == document.Mapping {
for _, entry := range node.Mapping {
child := path.Key(entry.Key)
if entry.Key == directiveKey || entry.Key == inheritanceKey {
if entry.Key == inheritanceKey {
return child, true
}
if found, ok := overrideStructuralDirectivePathAt(entry.Value, child); ok {
if found, ok := overrideInheritancePath(entry.Value, child); ok {
return found, true
}
}
} else if node.Kind == document.Sequence {
for index, child := range node.Sequence {
if found, ok := overrideStructuralDirectivePathAt(child, path.Index(index)); ok {
if found, ok := overrideInheritancePath(child, path.Index(index)); ok {
return found, true
}
}