88 "os"
99 "path/filepath"
1010 "slices"
11- "sort"
1211 "strings"
1312)
1413
@@ -28,77 +27,11 @@ func CreateAPIView(pkgDir, outputDir string) error {
2827}
2928
3029func createReview (pkgDir string ) (PackageReview , error ) {
31- m , err := NewModule (pkgDir )
30+ r , err := NewReview (pkgDir )
3231 if err != nil {
3332 return PackageReview {}, err
3433 }
35- tokenList := & []Token {}
36- nav := []Navigation {}
37- diagnostics := []Diagnostic {}
38- packageNames := []string {}
39- for name , p := range m .packages {
40- // we use a prefixed path separator so that we can handle the "internal" module.
41- // internal/dig
42- // internal/errorinfo
43- // etc.
44- // for other modules, we skip /internal subdirectories
45- // azcore/internal/...
46- if strings .Contains (p .relName , "/internal" ) || p .c .isEmpty () {
47- continue
48- }
49- packageNames = append (packageNames , name )
50- }
51- sort .Strings (packageNames )
52- for _ , name := range packageNames {
53- p := m .packages [name ]
54- n := p .relName
55- makeToken (nil , nil , "package" , TokenTypeMemberName , tokenList )
56- makeToken (nil , nil , " " , TokenTypeWhitespace , tokenList )
57- makeToken (& n , nil , n , TokenTypeTypeName , tokenList )
58- makeToken (nil , nil , "" , TokenTypeNewline , tokenList )
59- makeToken (nil , nil , "" , TokenTypeNewline , tokenList )
60- // TODO: reordering these calls reorders APIView output and can omit content
61- p .c .parseInterface (tokenList )
62- p .c .parseStruct (tokenList )
63- p .c .parseSimpleType (tokenList )
64- p .c .parseVar (tokenList )
65- p .c .parseConst (tokenList )
66- p .c .parseFunc (tokenList )
67- navItems := p .c .generateNavChildItems ()
68- nav = append (nav , Navigation {
69- Text : n ,
70- NavigationId : n ,
71- ChildItems : navItems ,
72- Tags : & map [string ]string {
73- "TypeKind" : "namespace" ,
74- },
75- })
76- diagnostics = append (diagnostics , p .diagnostics ... )
77- }
78-
79- slices .SortFunc (diagnostics , func (a Diagnostic , b Diagnostic ) int {
80- targetCmp := strings .Compare (a .TargetID , b .TargetID )
81- if targetCmp != 0 {
82- return targetCmp
83- }
84- // if the target IDs are the same then fall back to the text.
85- // this accounts for cases where there are multiple diagnostics
86- // for the same target ID.
87- return strings .Compare (a .Text , b .Text )
88- })
89-
90- for _ , n := range nav {
91- recursiveSortNavigation (n )
92- }
93-
94- return PackageReview {
95- Diagnostics : diagnostics ,
96- Language : "Go" ,
97- Name : m .Name ,
98- Navigation : nav ,
99- Tokens : * tokenList ,
100- PackageName : m .PackageName ,
101- }, nil
34+ return r .Review ()
10235}
10336
10437func recursiveSortNavigation (n Navigation ) {
0 commit comments