wire: add info from the dependency graph when a type is not provided

This commit is contained in:
Robert van Gent
2018-10-17 14:14:08 -07:00
committed by Ross Light
parent b84ad6154f
commit a8825fef58
5 changed files with 72 additions and 24 deletions

View File

@@ -38,34 +38,42 @@ type providerSetSrc struct {
Import *ProviderSet
}
// trace returns a slice of strings describing the (possibly recursive) source
// of p, including line numbers.
func (p *providerSetSrc) trace(fset *token.FileSet, typ types.Type) []string {
// description returns a string describing the source of p, including line numbers.
func (p *providerSetSrc) description(fset *token.FileSet, typ types.Type) string {
quoted := func(s string) string {
if s == "" {
return ""
}
return fmt.Sprintf("%q ", s)
}
var retval []string
if p.Provider != nil {
switch {
case p.Provider != nil:
kind := "provider"
if p.Provider.IsStruct {
kind = "struct provider"
}
retval = append(retval, fmt.Sprintf("%s %s(%s)", kind, quoted(p.Provider.Name), fset.Position(p.Provider.Pos)))
} else if p.Binding != nil {
retval = append(retval, fmt.Sprintf("wire.Bind (%s)", fset.Position(p.Binding.Pos)))
} else if p.Value != nil {
retval = append(retval, fmt.Sprintf("wire.Value (%s)", fset.Position(p.Value.Pos)))
} else if p.Import != nil {
return fmt.Sprintf("%s %s(%s)", kind, quoted(p.Provider.Name), fset.Position(p.Provider.Pos))
case p.Binding != nil:
return fmt.Sprintf("wire.Bind (%s)", fset.Position(p.Binding.Pos))
case p.Value != nil:
return fmt.Sprintf("wire.Value (%s)", fset.Position(p.Value.Pos))
case p.Import != nil:
return fmt.Sprintf("provider set %s(%s)", quoted(p.Import.VarName), fset.Position(p.Import.Pos))
}
panic("providerSetSrc with no fields set")
}
// trace returns a slice of strings describing the (possibly recursive) source
// of p, including line numbers.
func (p *providerSetSrc) trace(fset *token.FileSet, typ types.Type) []string {
var retval []string
// Only Imports need recursion.
if p.Import != nil {
if parent := p.Import.srcMap.At(typ); parent != nil {
retval = append(retval, parent.(*providerSetSrc).trace(fset, typ)...)
}
retval = append(retval, fmt.Sprintf("provider set %s(%s)", quoted(p.Import.VarName), fset.Position(p.Import.Pos)))
} else {
panic("providerSetSrc with no fields set")
}
retval = append(retval, p.description(fset, typ))
return retval
}