@@ -467,7 +467,9 @@ class PluginServer {
467467 switch (request.method) {
468468 case protocol.ANALYSIS_REQUEST_GET_NAVIGATION :
469469 case protocol.ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS :
470- result = null ;
470+ var params =
471+ protocol.AnalysisHandleWatchEventsParams .fromRequest (request);
472+ result = await _handleAnalysisWatchEvents (params);
471473
472474 case protocol.ANALYSIS_REQUEST_SET_CONTEXT_ROOTS :
473475 var params =
@@ -608,21 +610,55 @@ class PluginServer {
608610
609611 changedPaths.add (path);
610612 });
611- await _handleContentChanged (changedPaths.toList ());
613+ await _handleContentChanged (modifiedPaths : changedPaths.toList ());
612614 return protocol.AnalysisUpdateContentResult ();
613615 }
614616
615- /// Handles the fact that files with [paths] were changed.
616- Future <void > _handleContentChanged (List <String > paths) async {
617+ /// Handles an 'analysis.handleWatchEvents' request.
618+ Future <protocol.AnalysisHandleWatchEventsResult > _handleAnalysisWatchEvents (
619+ protocol.AnalysisHandleWatchEventsParams parameters) async {
620+ final addedPaths = parameters.events
621+ .where ((e) => e.type == protocol.WatchEventType .ADD )
622+ .map ((e) => e.path)
623+ .toList ();
624+ final modifiedPaths = parameters.events
625+ .where ((e) => e.type == protocol.WatchEventType .MODIFY )
626+ .map ((e) => e.path)
627+ .toList ();
628+ final removedPaths = parameters.events
629+ .where ((e) => e.type == protocol.WatchEventType .REMOVE )
630+ .map ((e) => e.path)
631+ .toList ();
632+
633+ await _handleContentChanged (
634+ addedPaths: addedPaths,
635+ modifiedPaths: modifiedPaths,
636+ removedPaths: removedPaths,
637+ );
638+
639+ return protocol.AnalysisHandleWatchEventsResult ();
640+ }
641+
642+ /// Handles added files, modified files, and removed files.
643+ Future <void > _handleContentChanged (
644+ {List <String > addedPaths = const [],
645+ List <String > modifiedPaths = const [],
646+ List <String > removedPaths = const []}) async {
617647 if (_contextCollection case var contextCollection? ) {
618648 _channel.sendNotification (
619649 protocol.PluginStatusParams (analysis: protocol.AnalysisStatus (true ))
620650 .toNotification ());
621651 await _forAnalysisContexts (contextCollection, (analysisContext) async {
622- for (var path in paths) {
652+ for (var path in modifiedPaths) {
653+ analysisContext.changeFile (path);
654+ }
655+ for (var path in removedPaths) {
623656 analysisContext.changeFile (path);
624657 }
625- var affected = await analysisContext.applyPendingFileChanges ();
658+ var affected = [
659+ ...await analysisContext.applyPendingFileChanges (),
660+ ...addedPaths,
661+ ];
626662 await _handleAffectedFiles (
627663 analysisContext: analysisContext, paths: affected);
628664 });
0 commit comments