@@ -14,6 +14,7 @@ import 'package:gcloud/storage.dart';
14
14
import 'package:gcloud/service_scope.dart' as ss;
15
15
import 'package:json_annotation/json_annotation.dart' ;
16
16
17
+ import '../dartdoc/pub_dartdoc_data.dart' ;
17
18
import '../frontend/model_properties.dart' ;
18
19
import '../frontend/models.dart' ;
19
20
import '../shared/analyzer_client.dart' ;
@@ -70,15 +71,15 @@ class SearchBackend {
70
71
versionList.where ((pv) => pv != null ),
71
72
key: (pv) => (pv as PackageVersion ).package);
72
73
73
- final indexJsonFutures = Future .wait (packages.map ((p) =>
74
- dartdocClient.getContentBytes (p.name, 'latest' , 'index .json' ,
74
+ final pubDataFutures = Future .wait (packages.map ((p) =>
75
+ dartdocClient.getContentBytes (p.name, 'latest' , 'pub-data .json' ,
75
76
timeout: const Duration (seconds: 10 ))));
76
77
77
78
final List <AnalysisView > analysisViews =
78
79
await analyzerClient.getAnalysisViews (packages.map ((p) =>
79
80
p == null ? null : new AnalysisKey (p.name, p.latestVersion)));
80
81
81
- final indexJsonContents = await indexJsonFutures ;
82
+ final pubDataContents = await pubDataFutures ;
82
83
83
84
final List <PackageDocument > results = new List (packages.length);
84
85
for (int i = 0 ; i < packages.length; i++ ) {
@@ -90,8 +91,15 @@ class SearchBackend {
90
91
final analysisView = analysisViews[i];
91
92
final double popularity = popularityStorage.lookup (pv.package) ?? 0.0 ;
92
93
93
- final List <int > indexJsonContent = indexJsonContents[i];
94
- final apiDocPages = _apiDocPagesFromIndexJson (indexJsonContent);
94
+ final List <int > pubDataContent = pubDataContents[i];
95
+ List <ApiDocPage > apiDocPages;
96
+ if (pubDataContent != null ) {
97
+ try {
98
+ apiDocPages = _apiDocPagesFromPubData (pubDataContent);
99
+ } catch (e, st) {
100
+ _logger.severe ('Parsing pub-data.json failed.' , e, st);
101
+ }
102
+ }
95
103
96
104
results[i] = new PackageDocument (
97
105
package: pv.package,
@@ -135,43 +143,56 @@ class SearchBackend {
135
143
return emails.toList ()..sort ();
136
144
}
137
145
138
- List <ApiDocPage > _apiDocPagesFromIndexJson (List <int > bytes) {
139
- if (bytes == null ) return null ;
140
- try {
141
- final list = json.decode (utf8.decode (bytes));
142
-
143
- final pathMap = < String , String > {};
144
- final symbolMap = < String , Set <String >> {};
145
- for (Map map in list) {
146
- final String name = map['name' ];
147
- final type = map['type' ];
148
- if (isCommonApiSymbol (name) && type != 'library' ) {
149
- continue ;
150
- }
146
+ List <ApiDocPage > _apiDocPagesFromPubData (List <int > bytes) {
147
+ final decodedMap = json.decode (utf8.decode (bytes)) as Map ;
148
+ final pubData = new PubDartdocData .fromJson (decodedMap.cast ());
149
+
150
+ final nameToKindMap = < String , String > {};
151
+ pubData.apiElements.forEach ((e) {
152
+ nameToKindMap[e.name] = e.kind;
153
+ });
151
154
152
- final String qualifiedName = map['qualifiedName' ];
153
- final enclosedBy = map['enclosedBy' ];
154
- final enclosedByType = enclosedBy is Map ? enclosedBy['type' ] : null ;
155
- final parentLevel = enclosedByType == 'class' ? 2 : 1 ;
156
- final String key = qualifiedName.split ('.' ).take (parentLevel).join ('.' );
155
+ final pathMap = < String , String > {};
156
+ final symbolMap = < String , Set <String >> {};
157
+ final docMap = < String , List <String >> {};
157
158
158
- if (key == qualifiedName) {
159
- pathMap[key] = map['href' ] as String ;
160
- }
161
- symbolMap.putIfAbsent (key, () => new Set ()).add (name);
162
- }
159
+ bool isTopLevel (String kind) => kind == 'library' || kind == 'class' ;
163
160
164
- final results = pathMap.keys. map ((key ) {
165
- final path = pathMap[ key] ;
166
- final symbols = symbolMap[key]. toList ().. sort ( );
167
- return new ApiDocPage (relativePath : path, symbols : symbols);
168
- }). toList ();
169
- results. sort ((a, b) => a.relativePath. compareTo (b.relativePath));
170
- return results ;
171
- } catch (e, st) {
172
- _logger. warning ( 'Parsing dartdoc index.json failed.' , e, st);
161
+ void update ( String key, String name, String documentation ) {
162
+ final set = symbolMap. putIfAbsent ( key, () => new Set < String >()) ;
163
+ set . addAll (name. split ( '.' ) );
164
+
165
+ documentation = documentation ? . trim ();
166
+ if (documentation != null && documentation.isNotEmpty) {
167
+ final list = docMap. putIfAbsent (key, () => []) ;
168
+ list. add ( compactReadme (documentation));
169
+ }
173
170
}
174
- return null ;
171
+
172
+ pubData.apiElements.forEach ((apiElement) {
173
+ if (isTopLevel (apiElement.kind)) {
174
+ pathMap[apiElement.name] = apiElement.href;
175
+ update (apiElement.name, apiElement.name, apiElement.documentation);
176
+ }
177
+
178
+ if (! isTopLevel (apiElement.kind) &&
179
+ apiElement.parent != null &&
180
+ isTopLevel (nameToKindMap[apiElement.parent])) {
181
+ update (apiElement.parent, apiElement.name, apiElement.documentation);
182
+ }
183
+ });
184
+
185
+ final results = pathMap.keys.map ((key) {
186
+ final path = pathMap[key];
187
+ final symbols = symbolMap[key].toList ()..sort ();
188
+ return new ApiDocPage (
189
+ relativePath: path,
190
+ symbols: symbols,
191
+ textBlocks: docMap[key],
192
+ );
193
+ }).toList ();
194
+ results.sort ((a, b) => a.relativePath.compareTo (b.relativePath));
195
+ return results;
175
196
}
176
197
}
177
198
0 commit comments