@@ -43,11 +43,9 @@ base mixin PubDevSupport on ToolsSupport {
4343 try {
4444 result = jsonDecode (await _client.read (searchUrl));
4545
46- final packageNames =
47- dig <List >(result, ['packages' ])
48- .take (_resultsLimit)
49- .map ((p) => dig <String >(p, ['package' ]))
50- .toList ();
46+ final packageNames = dig <List >(result, [
47+ 'packages' ,
48+ ]).take (_resultsLimit).map ((p) => dig <String >(p, ['package' ])).toList ();
5149
5250 if (packageNames.isEmpty) {
5351 return CallToolResult (
@@ -71,15 +69,17 @@ base mixin PubDevSupport on ToolsSupport {
7169 }
7270
7371 // Retrieve information about all the packages in parallel.
74- final subQueryFutures =
75- packageNames
76- .map (
77- (packageName) => (
78- versionListing: retrieve ('api/packages/$packageName ' ),
79- score: retrieve ('api/packages/$packageName /score' ),
80- ),
81- )
82- .toList ();
72+ final subQueryFutures = packageNames
73+ .map (
74+ (packageName) => (
75+ versionListing: retrieve ('api/packages/$packageName ' ),
76+ score: retrieve ('api/packages/$packageName /score' ),
77+ docIndex: retrieve (
78+ 'documentation/$packageName /latest/index.json' ,
79+ ),
80+ ),
81+ )
82+ .toList ();
8383
8484 // Aggregate the retrieved information about each package into a
8585 // TextContent.
@@ -88,6 +88,17 @@ base mixin PubDevSupport on ToolsSupport {
8888 final packageName = packageNames[i];
8989 final versionListing = await subQueryFutures[i].versionListing;
9090 final scoreResult = await subQueryFutures[i].score;
91+ final libraryDocs = {
92+ for (var object
93+ in ((await subQueryFutures[i].docIndex) as List ? )
94+ ? .cast <Map <String , Object ?>>() ??
95+ < Map <String , Object ?>> [])
96+ if (! object.containsKey ('enclosedBy' ))
97+ object['name' ] as String : Uri .https (
98+ 'pub.dev' ,
99+ 'documentation/$packageName /latest/${object ['href' ]}' ,
100+ ).toString (),
101+ };
91102 results.add (
92103 TextContent (
93104 text: jsonEncode ({
@@ -97,12 +108,28 @@ base mixin PubDevSupport on ToolsSupport {
97108 'latest' ,
98109 'version' ,
99110 ]),
100- 'description' : dig <String >(versionListing, [
111+ 'description' : ? dig <String ? >(versionListing, [
101112 'latest' ,
102113 'pubspec' ,
103114 'description' ,
104115 ]),
116+ 'homepage' : ? dig <String ?>(versionListing, [
117+ 'latest' ,
118+ 'pubspec' ,
119+ 'homepage' ,
120+ ]),
121+ 'repository' : ? dig <String ?>(versionListing, [
122+ 'latest' ,
123+ 'pubspec' ,
124+ 'repository' ,
125+ ]),
126+ 'documentation' : ? dig <String ?>(versionListing, [
127+ 'latest' ,
128+ 'pubspec' ,
129+ 'documentation' ,
130+ ]),
105131 },
132+ if (libraryDocs.isNotEmpty) ...{'libraries' : libraryDocs},
106133 if (scoreResult != null ) ...{
107134 'scores' : {
108135 'pubPoints' : dig <int >(scoreResult, ['grantedPoints' ]),
@@ -112,19 +139,15 @@ base mixin PubDevSupport on ToolsSupport {
112139 'downloadCount30Days' ,
113140 ]),
114141 },
115- 'topics' :
116- dig <List >(
117- scoreResult,
118- ['tags' ],
119- ).where ((t) => (t as String ).startsWith ('topic:' )).toList (),
120- 'licenses' :
121- dig <List >(scoreResult, ['tags' ])
122- .where ((t) => (t as String ).startsWith ('license' ))
123- .toList (),
124- 'publisher' :
125- dig <List >(scoreResult, ['tags' ])
126- .where ((t) => (t as String ).startsWith ('publisher:' ))
127- .firstOrNull,
142+ 'topics' : dig <List >(scoreResult, [
143+ 'tags' ,
144+ ]).where ((t) => (t as String ).startsWith ('topic:' )).toList (),
145+ 'licenses' : dig <List >(scoreResult, [
146+ 'tags' ,
147+ ]).where ((t) => (t as String ).startsWith ('license' )).toList (),
148+ 'publisher' : dig <List >(scoreResult, ['tags' ])
149+ .where ((t) => (t as String ).startsWith ('publisher:' ))
150+ .firstOrNull,
128151 },
129152 }),
130153 ),
0 commit comments