fixed an issue with resolving scalar types in structs and sorting service methods in order to avoid unnessary file changes

This commit is contained in:
Jan Halfar 2016-10-18 17:19:58 +02:00
parent e2612d8352
commit 76a667423a
2 changed files with 15 additions and 5 deletions

View File

@ -49,9 +49,15 @@ type Field struct {
type Service struct {
Name string
Methods []*Method
Methods ServiceMethods
}
type ServiceMethods []*Method
func (sm ServiceMethods) Len() int { return len(sm) }
func (sm ServiceMethods) Swap(i, j int) { sm[i], sm[j] = sm[j], sm[i] }
func (sm ServiceMethods) Less(i, j int) bool { return sm[i].Name < sm[j].Name }
type Method struct {
Name string
Args []*Field

View File

@ -7,6 +7,7 @@ import (
"go/token"
"reflect"
"runtime"
"sort"
"strings"
)
@ -57,7 +58,9 @@ func readServiceFile(file *ast.File, packageName string, services []*Service) er
}
}
}
for _, s := range services {
sort.Sort(s.Methods)
}
return nil
}
@ -366,14 +369,15 @@ func typesPending(structs map[string]*Struct, scalars map[string]*Scalar, missin
func (s *Struct) DepsSatisfied(missingTypes map[string]bool, structs map[string]*Struct, scalarTypes map[string]*Scalar) bool {
needsWork := func(fullName string) bool {
strct, ok := structs[fullName]
if !ok {
strct, strctOK := structs[fullName]
scalar, scalarOK := scalarTypes[fullName]
if !strctOK && !scalarOK {
// hey there is more todo
missingTypes[fullName] = true
trace("need work ----------------------" + fullName)
return true
}
if strct == nil {
if strct == nil && scalar == nil {
trace("need work ----------------------" + fullName)
return true
}