Add detached source lookup to results and errors
This commit is contained in:
@@ -50,6 +50,16 @@ func (e *LoadError) Sources() []SourceInfo {
|
||||
return cloneSourceInfos(e.sources)
|
||||
}
|
||||
|
||||
// Source returns a detached record from the source evidence retained before
|
||||
// loading failed. IDs are local to the failed load. Empty or unknown IDs return
|
||||
// false.
|
||||
func (e *LoadError) Source(id string) (SourceInfo, bool) {
|
||||
if e == nil {
|
||||
return SourceInfo{}, false
|
||||
}
|
||||
return lookupSourceInfo(e.sources, id)
|
||||
}
|
||||
|
||||
// WriteDiagnostics writes diagnostics in canonical order. It escapes terminal
|
||||
// control characters and propagates writer errors, including short writes.
|
||||
func WriteDiagnostics(output io.Writer, diagnostics []Diagnostic) error {
|
||||
|
||||
@@ -119,6 +119,16 @@ func (r *Inspection) Sources() []SourceInfo {
|
||||
return cloneSourceInfos(r.sources)
|
||||
}
|
||||
|
||||
// Source returns a detached record for an acquired source in this load. IDs are
|
||||
// local to the load; the lookup does not reacquire the source or access the
|
||||
// filesystem. Empty or unknown IDs return false.
|
||||
func (r *Inspection) Source(id string) (SourceInfo, bool) {
|
||||
if r == nil {
|
||||
return SourceInfo{}, false
|
||||
}
|
||||
return lookupSourceInfo(r.sources, id)
|
||||
}
|
||||
|
||||
// SourceContext returns a passive filesystem view for an acquired source.
|
||||
// Unknown IDs and sources without a filesystem context return false.
|
||||
func (r *Inspection) SourceContext(id string) (ResourceContext, bool) {
|
||||
|
||||
@@ -92,7 +92,7 @@ const (
|
||||
CodeDecodeUnknownField Code = "decode.unknown_field"
|
||||
CodeDecodeArrayLength Code = "decode.array_length"
|
||||
|
||||
CodeOptionsInvalid Code = "options.invalid"
|
||||
CodeOptionsInvalid Code = "options.invalid"
|
||||
|
||||
CodeImportDisabled Code = "import.disabled"
|
||||
CodeImportInvalid Code = "import.invalid"
|
||||
@@ -345,6 +345,18 @@ func cloneSourceInfo(source SourceInfo) SourceInfo {
|
||||
return source
|
||||
}
|
||||
|
||||
func lookupSourceInfo(sources []SourceInfo, id string) (SourceInfo, bool) {
|
||||
if id == "" {
|
||||
return SourceInfo{}, false
|
||||
}
|
||||
for _, source := range sources {
|
||||
if source.ID == id {
|
||||
return cloneSourceInfo(source), true
|
||||
}
|
||||
}
|
||||
return SourceInfo{}, false
|
||||
}
|
||||
|
||||
func cloneSourceVersionCheck(value *SourceVersionCheck) *SourceVersionCheck {
|
||||
if value == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user