Centralize parser diagnostic translation
This commit is contained in:
16
imports.go
16
imports.go
@@ -345,7 +345,7 @@ func (s *importTraversal) visitPath(basePath string, declaration importDeclarati
|
||||
Depth: maxDocumentDepth, Nodes: maxDocumentNodes,
|
||||
})
|
||||
if len(issues) != 0 {
|
||||
return importParseDiagnostics(sourceID, issues)
|
||||
return parserDiagnostics(sourceID, issues)
|
||||
}
|
||||
nodeCount := countInputNodes(root)
|
||||
if s.usedNodes+nodeCount > s.limits.nodes {
|
||||
@@ -625,20 +625,6 @@ func sourceInfos(source *SourceInfo) []SourceInfo {
|
||||
return []SourceInfo{cloneSourceInfo(*source)}
|
||||
}
|
||||
|
||||
func importParseDiagnostics(sourceID string, issues []yamladapter.Issue) []Diagnostic {
|
||||
diagnostics := make([]Diagnostic, len(issues))
|
||||
for index, issue := range issues {
|
||||
diagnostics[index] = Diagnostic{
|
||||
Code: Code(issue.Code), Severity: SeverityError, Message: issue.Message,
|
||||
Primary: &Location{SourceID: sourceID, Line: issue.Line, Column: issue.Column},
|
||||
}
|
||||
for _, related := range issue.Related {
|
||||
diagnostics[index].Related = append(diagnostics[index].Related, publicLocation(related))
|
||||
}
|
||||
}
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
func importDiagnostic(code Code, message string, location *Location) Diagnostic {
|
||||
return Diagnostic{Code: code, Severity: SeverityError, Message: message, Primary: cloneLocation(location)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user