@@ -42,6 +42,22 @@ const _defaultApiPageDirWeights = {
4242 'material/Icons' : 0.25 ,
4343};
4444
45+ /// The list of libraries that are to be exposed as part of the Flutter SDK index.
46+ const _flutterLibraryAllowlist = {
47+ 'animation' ,
48+ 'cupertino' ,
49+ 'foundation' ,
50+ 'gestures' ,
51+ 'material' ,
52+ 'painting' ,
53+ 'physics' ,
54+ 'rendering' ,
55+ 'scheduler' ,
56+ 'semantics' ,
57+ 'services' ,
58+ 'widgets' ,
59+ };
60+
4561final _logger = Logger ('search.dart_sdk_mem_index' );
4662final _dartUri = Uri .parse ('https://api.dart.dev/stable/latest/' );
4763final _flutterUri = Uri .parse ('https://api.flutter.dev/flutter/' );
@@ -88,7 +104,14 @@ class SdkMemIndex implements SdkIndex {
88104 Map <String , double >? apiPageDirWeights,
89105 }) : _apiPageDirWeights = apiPageDirWeights ?? _defaultApiPageDirWeights {
90106 _addDartdocIndex ('dart' , _dartUri, dartIndex);
91- _addDartdocIndex ('flutter' , _flutterUri, flutterIndex);
107+ _addDartdocIndex (
108+ 'flutter' ,
109+ _flutterUri,
110+ flutterIndex,
111+ includeLibraryFn: (library) =>
112+ library.startsWith ('flutter_' ) ||
113+ _flutterLibraryAllowlist.contains (library),
114+ );
92115 }
93116
94117 static final dartSdkIndexJsonUri =
@@ -99,8 +122,11 @@ class SdkMemIndex implements SdkIndex {
99122 void _addDartdocIndex (
100123 String sdk,
101124 Uri baseUri,
102- DartdocIndex index,
103- ) {
125+ DartdocIndex index, {
126+ /// If specified, the index building will call this function for
127+ /// each library, and will include only the ones that return `true` .
128+ bool Function (String library)? includeLibraryFn,
129+ }) {
104130 final textsPerLibrary = < String , Map <String , String >> {};
105131 final baseUris = < String , Uri > {};
106132 final descriptions = < String , String > {};
@@ -109,7 +135,16 @@ class SdkMemIndex implements SdkIndex {
109135 final library = f.qualifiedName? .split ('.' ).first;
110136 if (library == null ) continue ;
111137 if (f.href == null ) continue ;
112- if (_libraries.containsKey (library)) continue ;
138+ // Skips libraries that were added in a previous call of this method,
139+ // e.g. Dart SDK libraries are kept as-is and Flutter SDK libraries
140+ // are not overriding them here.
141+ if (_libraries.containsKey (library)) {
142+ continue ;
143+ }
144+ // Skips libraries that are not explicitly allowed.
145+ if (includeLibraryFn != null && ! includeLibraryFn (library)) {
146+ continue ;
147+ }
113148 if (f.isLibrary) {
114149 baseUris[library] = baseUri.resolve (f.href! );
115150
0 commit comments