Activate ordinary source collection declarations
This commit is contained in:
@@ -264,3 +264,72 @@ func disabledDirectiveDiagnostics(node *document.Node, path Path) []Diagnostic {
|
||||
}
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
func disabledRootImportDiagnostics(node *document.Node) []Diagnostic {
|
||||
if node == nil || node.Kind != document.Mapping {
|
||||
return nil
|
||||
}
|
||||
var rootDirective *document.Node
|
||||
var rootLocation document.Location
|
||||
var foundRootDirective bool
|
||||
for index := range node.Mapping {
|
||||
if node.Mapping[index].Key == directiveKey {
|
||||
rootDirective = node.Mapping[index].Value
|
||||
rootLocation = node.Mapping[index].KeyLocation
|
||||
foundRootDirective = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundRootDirective {
|
||||
if rootDirective == nil || rootDirective.Kind != document.Mapping {
|
||||
return disabledDirectiveDiagnostic(rootLocation)
|
||||
}
|
||||
for _, directive := range rootDirective.Mapping {
|
||||
if directive.Key == "imports" {
|
||||
return disabledDirectiveDiagnostic(rootLocation)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, entry := range node.Mapping {
|
||||
if entry.Key == directiveKey {
|
||||
continue
|
||||
}
|
||||
if diagnostic := disabledNestedDirectiveDiagnostics(entry.Value, Path{}.Key(entry.Key)); len(diagnostic) != 0 {
|
||||
return diagnostic
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func disabledNestedDirectiveDiagnostics(node *document.Node, path Path) []Diagnostic {
|
||||
if node.Kind == document.Mapping {
|
||||
for _, entry := range node.Mapping {
|
||||
childPath := path.Key(entry.Key)
|
||||
if entry.Key == directiveKey {
|
||||
location := Location{SourceID: entry.KeyLocation.SourceID, Line: entry.KeyLocation.Line, Column: entry.KeyLocation.Column}
|
||||
return []Diagnostic{{
|
||||
Code: CodeImportDisabled, Severity: SeverityError, Path: childPath,
|
||||
Message: "configuration directives require imports to be enabled", Primary: &location,
|
||||
}}
|
||||
}
|
||||
if diagnostics := disabledNestedDirectiveDiagnostics(entry.Value, childPath); len(diagnostics) != 0 {
|
||||
return diagnostics
|
||||
}
|
||||
}
|
||||
} else if node.Kind == document.Sequence {
|
||||
for index, child := range node.Sequence {
|
||||
if diagnostics := disabledNestedDirectiveDiagnostics(child, path.Index(index)); len(diagnostics) != 0 {
|
||||
return diagnostics
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func disabledDirectiveDiagnostic(location document.Location) []Diagnostic {
|
||||
public := Location{SourceID: location.SourceID, Line: location.Line, Column: location.Column}
|
||||
return []Diagnostic{{
|
||||
Code: CodeImportDisabled, Severity: SeverityError, Path: Keys(directiveKey),
|
||||
Message: "configuration directives require imports to be enabled", Primary: &public,
|
||||
}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user