@@ -62,6 +62,9 @@ class PluginServer {
62
62
63
63
String ? _sdkPath;
64
64
65
+ /// Paths of priority files.
66
+ Set <String > _priorityPaths = {};
67
+
65
68
final List <Plugin > _plugins;
66
69
67
70
final _registry = PluginRegistryImpl ();
@@ -82,6 +85,16 @@ class PluginServer {
82
85
}
83
86
}
84
87
88
+ /// Handles an 'analysis.setPriorityFiles' request.
89
+ ///
90
+ /// Throws a [RequestFailure] if the request could not be handled.
91
+ Future <protocol.AnalysisSetPriorityFilesResult >
92
+ handleAnalysisSetPriorityFiles (
93
+ protocol.AnalysisSetPriorityFilesParams parameters) async {
94
+ _priorityPaths = parameters.files.toSet ();
95
+ return protocol.AnalysisSetPriorityFilesResult ();
96
+ }
97
+
85
98
/// Handles an 'edit.getFixes' request.
86
99
///
87
100
/// Throws a [RequestFailure] if the request could not be handled.
@@ -185,23 +198,43 @@ class PluginServer {
185
198
});
186
199
}
187
200
201
+ Future <void > _analyzeFile ({
202
+ required AnalysisContext analysisContext,
203
+ required String path,
204
+ }) async {
205
+ var file = _resourceProvider.getFile (path);
206
+ var analysisOptions = analysisContext.getAnalysisOptionsForFile (file);
207
+ var lints = await _computeLints (
208
+ analysisContext,
209
+ path,
210
+ analysisOptions: analysisOptions as AnalysisOptionsImpl ,
211
+ );
212
+ _channel.sendNotification (
213
+ protocol.AnalysisErrorsParams (path, lints).toNotification ());
214
+ }
215
+
188
216
/// Analyzes the files at the given [paths] .
189
217
Future <void > _analyzeFiles ({
190
218
required AnalysisContext analysisContext,
191
219
required List <String > paths,
192
220
}) async {
193
- // TODO(srawlins): Implement "priority files" and analyze them first.
194
- // TODO(srawlins): Analyze libraries instead of files, for efficiency.
195
- for (var path in paths.toSet ()) {
196
- var file = _resourceProvider.getFile (path);
197
- var analysisOptions = analysisContext.getAnalysisOptionsForFile (file);
198
- var lints = await _computeLints (
199
- analysisContext,
200
- path,
201
- analysisOptions: analysisOptions as AnalysisOptionsImpl ,
221
+ var pathSet = paths.toSet ();
222
+
223
+ // First analyze priority files.
224
+ for (var path in _priorityPaths) {
225
+ pathSet.remove (path);
226
+ await _analyzeFile (
227
+ analysisContext: analysisContext,
228
+ path: path,
229
+ );
230
+ }
231
+
232
+ // Then analyze the remaining files.
233
+ for (var path in pathSet) {
234
+ await _analyzeFile (
235
+ analysisContext: analysisContext,
236
+ path: path,
202
237
);
203
- _channel.sendNotification (
204
- protocol.AnalysisErrorsParams (path, lints).toNotification ());
205
238
}
206
239
}
207
240
@@ -294,12 +327,21 @@ class PluginServer {
294
327
return errorsAndProtocolErrors.map ((e) => e.protocolError).toList ();
295
328
}
296
329
297
- /// Invokes [fn] for all analysis contexts.
330
+ /// Invokes [fn] first for priority analysis contexts, then for the rest .
298
331
Future <void > _forAnalysisContexts (
299
332
AnalysisContextCollection contextCollection,
300
333
Future <void > Function (AnalysisContext analysisContext) fn,
301
334
) async {
335
+ var nonPriorityAnalysisContexts = < AnalysisContext > [];
302
336
for (var analysisContext in contextCollection.contexts) {
337
+ if (_isPriorityAnalysisContext (analysisContext)) {
338
+ await fn (analysisContext);
339
+ } else {
340
+ nonPriorityAnalysisContexts.add (analysisContext);
341
+ }
342
+ }
343
+
344
+ for (var analysisContext in nonPriorityAnalysisContexts) {
303
345
await fn (analysisContext);
304
346
}
305
347
}
@@ -495,6 +537,9 @@ class PluginServer {
495
537
);
496
538
}
497
539
540
+ bool _isPriorityAnalysisContext (AnalysisContext analysisContext) =>
541
+ _priorityPaths.any (analysisContext.contextRoot.isAnalyzed);
542
+
498
543
static protocol.Location _locationFor (
499
544
CompilationUnit unit, String path, AnalysisError error) {
500
545
var lineInfo = unit.lineInfo;
0 commit comments