@@ -62,6 +62,9 @@ class PluginServer {
6262
6363 String ? _sdkPath;
6464
65+ /// Paths of priority files.
66+ Set <String > _priorityPaths = {};
67+
6568 final List <Plugin > _plugins;
6669
6770 final _registry = PluginRegistryImpl ();
@@ -82,6 +85,16 @@ class PluginServer {
8285 }
8386 }
8487
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+
8598 /// Handles an 'edit.getFixes' request.
8699 ///
87100 /// Throws a [RequestFailure] if the request could not be handled.
@@ -185,23 +198,43 @@ class PluginServer {
185198 });
186199 }
187200
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+
188216 /// Analyzes the files at the given [paths] .
189217 Future <void > _analyzeFiles ({
190218 required AnalysisContext analysisContext,
191219 required List <String > paths,
192220 }) 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,
202237 );
203- _channel.sendNotification (
204- protocol.AnalysisErrorsParams (path, lints).toNotification ());
205238 }
206239 }
207240
@@ -294,12 +327,21 @@ class PluginServer {
294327 return errorsAndProtocolErrors.map ((e) => e.protocolError).toList ();
295328 }
296329
297- /// Invokes [fn] for all analysis contexts.
330+ /// Invokes [fn] first for priority analysis contexts, then for the rest .
298331 Future <void > _forAnalysisContexts (
299332 AnalysisContextCollection contextCollection,
300333 Future <void > Function (AnalysisContext analysisContext) fn,
301334 ) async {
335+ var nonPriorityAnalysisContexts = < AnalysisContext > [];
302336 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) {
303345 await fn (analysisContext);
304346 }
305347 }
@@ -495,6 +537,9 @@ class PluginServer {
495537 );
496538 }
497539
540+ bool _isPriorityAnalysisContext (AnalysisContext analysisContext) =>
541+ _priorityPaths.any (analysisContext.contextRoot.isAnalyzed);
542+
498543 static protocol.Location _locationFor (
499544 CompilationUnit unit, String path, AnalysisError error) {
500545 var lineInfo = unit.lineInfo;
0 commit comments