@@ -42,6 +42,22 @@ const _defaultApiPageDirWeights = {
42
42
'material/Icons' : 0.25 ,
43
43
};
44
44
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
+
45
61
final _logger = Logger ('search.dart_sdk_mem_index' );
46
62
final _dartUri = Uri .parse ('https://api.dart.dev/stable/latest/' );
47
63
final _flutterUri = Uri .parse ('https://api.flutter.dev/flutter/' );
@@ -88,7 +104,14 @@ class SdkMemIndex implements SdkIndex {
88
104
Map <String , double >? apiPageDirWeights,
89
105
}) : _apiPageDirWeights = apiPageDirWeights ?? _defaultApiPageDirWeights {
90
106
_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
+ );
92
115
}
93
116
94
117
static final dartSdkIndexJsonUri =
@@ -99,8 +122,11 @@ class SdkMemIndex implements SdkIndex {
99
122
void _addDartdocIndex (
100
123
String sdk,
101
124
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
+ }) {
104
130
final textsPerLibrary = < String , Map <String , String >> {};
105
131
final baseUris = < String , Uri > {};
106
132
final descriptions = < String , String > {};
@@ -109,7 +135,16 @@ class SdkMemIndex implements SdkIndex {
109
135
final library = f.qualifiedName? .split ('.' ).first;
110
136
if (library == null ) continue ;
111
137
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
+ }
113
148
if (f.isLibrary) {
114
149
baseUris[library] = baseUri.resolve (f.href! );
115
150
0 commit comments