Make AnalysisServer.getAnalysisResult() sync to avoid changing behavior between Dart1 and Dart2.

R=brianwilkerson@google.com

Change-Id: I35e01907a6e8286b5ffd48a3b5ac6fcaf23034b3
Reviewed-on: https://dart-review.googlesource.com/58000
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart
index 92eb394..ded8e70 100644
--- a/pkg/analysis_server/lib/src/analysis_server.dart
+++ b/pkg/analysis_server/lib/src/analysis_server.dart
@@ -601,20 +601,19 @@
    * otherwise in the first driver, otherwise `null` is returned.
    */
   Future<nd.AnalysisResult> getAnalysisResult(String path,
-      {bool sendCachedToStream: false}) async {
+      {bool sendCachedToStream: false}) {
     if (!AnalysisEngine.isDartFileName(path)) {
       return null;
     }
 
-    try {
-      nd.AnalysisDriver driver = getAnalysisDriver(path);
-      return await driver?.getResult(path,
-          sendCachedToStream: sendCachedToStream);
-    } catch (e) {
-      // Ignore the exception.
-      // We don't want to log the same exception again and again.
-      return null;
+    nd.AnalysisDriver driver = getAnalysisDriver(path);
+    if (driver == null) {
+      return new Future.value();
     }
+
+    return driver
+        .getResult(path, sendCachedToStream: sendCachedToStream)
+        .catchError((_) => null);
   }
 
   /**
diff --git a/pkg/analysis_server/test/analysis_server_test.dart b/pkg/analysis_server/test/analysis_server_test.dart
index f40ac66..f5fd828 100644
--- a/pkg/analysis_server/test/analysis_server_test.dart
+++ b/pkg/analysis_server/test/analysis_server_test.dart
@@ -154,11 +154,12 @@
     server.setAnalysisSubscriptions(<AnalysisService, Set<String>>{
       AnalysisService.NAVIGATION: new Set<String>.from([path])
     });
-    // the file is excluded, so no navigation notification
+
+    // We respect subscriptions, even for excluded files.
     await server.onAnalysisComplete;
     expect(channel.notificationsReceived.any((notification) {
       return notification.event == ANALYSIS_NOTIFICATION_NAVIGATION;
-    }), isFalse);
+    }), isTrue);
   }
 
   test_setAnalysisSubscriptions_fileInIgnoredFolder_oldOptions() async {
@@ -173,11 +174,12 @@
     server.setAnalysisSubscriptions(<AnalysisService, Set<String>>{
       AnalysisService.NAVIGATION: new Set<String>.from([path])
     });
-    // the file is excluded, so no navigation notification
+
+    // We respect subscriptions, even for excluded files.
     await server.onAnalysisComplete;
     expect(channel.notificationsReceived.any((notification) {
       return notification.event == ANALYSIS_NOTIFICATION_NAVIGATION;
-    }), isFalse);
+    }), isTrue);
   }
 
   Future test_shutdown() {
diff --git a/pkg/analysis_server/test/domain_analysis_test.dart b/pkg/analysis_server/test/domain_analysis_test.dart
index 5e9e26f..d75a3b9 100644
--- a/pkg/analysis_server/test/domain_analysis_test.dart
+++ b/pkg/analysis_server/test/domain_analysis_test.dart
@@ -584,9 +584,9 @@
     expect(filesHighlights[testFile], isNull);
     // subscribe
     addAnalysisSubscription(AnalysisService.HIGHLIGHTS, file);
-    await server.onAnalysisComplete;
+    await _resultsAvailable.future;
     // there are results
-    expect(filesHighlights[file], isNull);
+    expect(filesHighlights[file], isEmpty);
   }
 
   test_afterAnalysis_packageFile_external() async {