| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:analysis_server/protocol/protocol.dart' as server; | 5 import 'package:analysis_server/protocol/protocol.dart' as server; |
| 6 import 'package:analysis_server/protocol/protocol_generated.dart' as server; | 6 import 'package:analysis_server/protocol/protocol_generated.dart' as server; |
| 7 import 'package:analysis_server/src/channel/channel.dart'; | 7 import 'package:analysis_server/src/channel/channel.dart'; |
| 8 import 'package:analysis_server/src/plugin/notification_manager.dart'; | 8 import 'package:analysis_server/src/plugin/notification_manager.dart'; |
| 9 import 'package:analyzer/file_system/memory_file_system.dart'; | 9 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; | 10 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; |
| 11 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; | 11 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 12 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; | 12 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; |
| 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 13 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| 14 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 16 | 16 |
| 17 import 'protocol_test_utilities.dart'; | 17 import 'protocol_test_utilities.dart'; |
| 18 | 18 |
| 19 main() { | 19 main() { |
| 20 defineReflectiveSuite(() { | 20 defineReflectiveSuite(() { |
| 21 defineReflectiveTests(NotificationManagerTest); | 21 defineReflectiveTests(NotificationManagerTest); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 MemoryResourceProvider provider = new MemoryResourceProvider(); | 36 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 37 testDir = provider.convertPath('/test'); | 37 testDir = provider.convertPath('/test'); |
| 38 fileA = provider.convertPath('/test/a.dart'); | 38 fileA = provider.convertPath('/test/a.dart'); |
| 39 fileB = provider.convertPath('/test/b.dart'); | 39 fileB = provider.convertPath('/test/b.dart'); |
| 40 channel = new TestChannel(); | 40 channel = new TestChannel(); |
| 41 manager = new NotificationManager(channel, provider); | 41 manager = new NotificationManager(channel, provider); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void test_handlePluginNotification_errors() { | 44 void test_handlePluginNotification_errors() { |
| 45 manager.setAnalysisRoots([testDir], []); | 45 manager.setAnalysisRoots([testDir], []); |
| 46 plugin.AnalysisError pluginError1 = pluginAnalysisError(0, 0, file: fileA); | 46 AnalysisError error1 = pluginAnalysisError(0, 0, file: fileA); |
| 47 plugin.AnalysisError pluginError2 = pluginAnalysisError(3, 4, file: fileA); | 47 AnalysisError error2 = pluginAnalysisError(3, 4, file: fileA); |
| 48 plugin.AnalysisErrorsParams params = | 48 plugin.AnalysisErrorsParams params = |
| 49 new plugin.AnalysisErrorsParams(fileA, [pluginError1, pluginError2]); | 49 new plugin.AnalysisErrorsParams(fileA, [error1, error2]); |
| 50 manager.handlePluginNotification('a', params.toNotification()); | 50 manager.handlePluginNotification('a', params.toNotification()); |
| 51 | 51 _verifyErrors(fileA, [error1, error2]); |
| 52 server.AnalysisError serverError1 = serverAnalysisError(0, 0, file: fileA); | |
| 53 server.AnalysisError serverError2 = serverAnalysisError(3, 4, file: fileA); | |
| 54 _verifyErrors(fileA, [serverError1, serverError2]); | |
| 55 } | 52 } |
| 56 | 53 |
| 57 void test_handlePluginNotification_folding() { | 54 void test_handlePluginNotification_folding() { |
| 58 manager.setSubscriptions({ | 55 manager.setSubscriptions({ |
| 59 server.AnalysisService.FOLDING: new Set.from([fileA, fileB]) | 56 server.AnalysisService.FOLDING: new Set.from([fileA, fileB]) |
| 60 }); | 57 }); |
| 61 plugin.FoldingRegion pluginRegion1 = pluginFoldingRegion(10, 3); | 58 FoldingRegion region1 = pluginFoldingRegion(10, 3); |
| 62 plugin.FoldingRegion pluginRegion2 = pluginFoldingRegion(20, 6); | 59 FoldingRegion region2 = pluginFoldingRegion(20, 6); |
| 63 plugin.AnalysisFoldingParams params = | 60 plugin.AnalysisFoldingParams params = |
| 64 new plugin.AnalysisFoldingParams(fileA, [pluginRegion1, pluginRegion2]); | 61 new plugin.AnalysisFoldingParams(fileA, [region1, region2]); |
| 65 manager.handlePluginNotification('a', params.toNotification()); | 62 manager.handlePluginNotification('a', params.toNotification()); |
| 66 | 63 _verifyFoldingRegions(fileA, [region1, region2]); |
| 67 server.FoldingRegion serverRegion1 = serverFoldingRegion(10, 3); | |
| 68 server.FoldingRegion serverRegion2 = serverFoldingRegion(20, 6); | |
| 69 _verifyFoldingRegions(fileA, [serverRegion1, serverRegion2]); | |
| 70 } | 64 } |
| 71 | 65 |
| 72 void test_handlePluginNotification_highlights() { | 66 void test_handlePluginNotification_highlights() { |
| 73 manager.setSubscriptions({ | 67 manager.setSubscriptions({ |
| 74 server.AnalysisService.HIGHLIGHTS: new Set.from([fileA, fileB]) | 68 server.AnalysisService.HIGHLIGHTS: new Set.from([fileA, fileB]) |
| 75 }); | 69 }); |
| 76 plugin.HighlightRegion pluginRegion1 = pluginHighlightRegion(10, 3); | 70 HighlightRegion region1 = pluginHighlightRegion(10, 3); |
| 77 plugin.HighlightRegion pluginRegion2 = pluginHighlightRegion(20, 6); | 71 HighlightRegion region2 = pluginHighlightRegion(20, 6); |
| 78 plugin.AnalysisHighlightsParams params = | 72 plugin.AnalysisHighlightsParams params = |
| 79 new plugin.AnalysisHighlightsParams( | 73 new plugin.AnalysisHighlightsParams(fileA, [region1, region2]); |
| 80 fileA, [pluginRegion1, pluginRegion2]); | |
| 81 | |
| 82 server.HighlightRegion serverRegion1 = serverHighlightRegion(10, 3); | |
| 83 server.HighlightRegion serverRegion2 = serverHighlightRegion(20, 6); | |
| 84 manager.handlePluginNotification('a', params.toNotification()); | 74 manager.handlePluginNotification('a', params.toNotification()); |
| 85 _verifyHighlightRegions(fileA, [serverRegion1, serverRegion2]); | 75 _verifyHighlightRegions(fileA, [region1, region2]); |
| 86 } | 76 } |
| 87 | 77 |
| 88 void test_handlePluginNotification_naviation() { | 78 void test_handlePluginNotification_naviation() { |
| 89 manager.setSubscriptions({ | 79 manager.setSubscriptions({ |
| 90 server.AnalysisService.NAVIGATION: new Set.from([fileA, fileB]) | 80 server.AnalysisService.NAVIGATION: new Set.from([fileA, fileB]) |
| 91 }); | 81 }); |
| 92 plugin.AnalysisNavigationParams pluginParams = | 82 plugin.AnalysisNavigationParams pluginParams = |
| 93 pluginNavigationParams(0, 0, file: fileA); | 83 pluginNavigationParams(0, 0, file: fileA); |
| 94 manager.handlePluginNotification('a', pluginParams.toNotification()); | 84 manager.handlePluginNotification('a', pluginParams.toNotification()); |
| 95 | 85 |
| 96 server.AnalysisNavigationParams serverParams = | 86 server.AnalysisNavigationParams serverParams = |
| 97 serverNavigationParams(0, 0, file: fileA); | 87 serverNavigationParams(0, 0, file: fileA); |
| 98 _verifyNavigationParams(serverParams); | 88 _verifyNavigationParams(serverParams); |
| 99 } | 89 } |
| 100 | 90 |
| 101 void test_handlePluginNotification_occurences() { | 91 void test_handlePluginNotification_occurences() { |
| 102 manager.setSubscriptions({ | 92 manager.setSubscriptions({ |
| 103 server.AnalysisService.OCCURRENCES: new Set.from([fileA, fileB]) | 93 server.AnalysisService.OCCURRENCES: new Set.from([fileA, fileB]) |
| 104 }); | 94 }); |
| 105 plugin.Occurrences pluginOccurrences1 = pluginOccurrences(0, 0); | 95 Occurrences occurrences1 = pluginOccurrences(0, 0); |
| 106 plugin.Occurrences pluginOccurrences2 = pluginOccurrences(5, 7); | 96 Occurrences occurrences2 = pluginOccurrences(5, 7); |
| 107 plugin.AnalysisOccurrencesParams params = | 97 plugin.AnalysisOccurrencesParams params = |
| 108 new plugin.AnalysisOccurrencesParams( | 98 new plugin.AnalysisOccurrencesParams( |
| 109 fileA, [pluginOccurrences1, pluginOccurrences2]); | 99 fileA, [occurrences1, occurrences2]); |
| 110 | 100 |
| 111 server.Occurrences serverOccurrences1 = serverOccurrences(0, 0); | |
| 112 server.Occurrences serverOccurrences2 = serverOccurrences(5, 7); | |
| 113 manager.handlePluginNotification('a', params.toNotification()); | 101 manager.handlePluginNotification('a', params.toNotification()); |
| 114 _verifyOccurrences(fileA, [serverOccurrences1, serverOccurrences2]); | 102 _verifyOccurrences(fileA, [occurrences1, occurrences2]); |
| 115 } | 103 } |
| 116 | 104 |
| 117 void test_handlePluginNotification_outline() { | 105 void test_handlePluginNotification_outline() { |
| 118 manager.setSubscriptions({ | 106 manager.setSubscriptions({ |
| 119 server.AnalysisService.OUTLINE: new Set.from([fileA, fileB]) | 107 server.AnalysisService.OUTLINE: new Set.from([fileA, fileB]) |
| 120 }); | 108 }); |
| 121 plugin.Outline pluginOutline1 = pluginOutline(0, 0); | 109 Outline outline1 = pluginOutline(0, 0); |
| 122 plugin.AnalysisOutlineParams params = | 110 plugin.AnalysisOutlineParams params = |
| 123 new plugin.AnalysisOutlineParams(fileA, [pluginOutline1]); | 111 new plugin.AnalysisOutlineParams(fileA, [outline1]); |
| 124 manager.handlePluginNotification('a', params.toNotification()); | 112 manager.handlePluginNotification('a', params.toNotification()); |
| 125 | 113 |
| 126 server.Outline serverOutline1 = serverOutline(0, 0); | 114 _verifyOutlines(fileA, outline1); |
| 127 _verifyOutlines(fileA, serverOutline1); | |
| 128 } | 115 } |
| 129 | 116 |
| 130 void test_handlePluginNotification_pluginError() { | 117 void test_handlePluginNotification_pluginError() { |
| 131 bool isFatal = false; | 118 bool isFatal = false; |
| 132 String message = 'message'; | 119 String message = 'message'; |
| 133 String stackTrace = 'stackTrace'; | 120 String stackTrace = 'stackTrace'; |
| 134 plugin.PluginErrorParams params = | 121 plugin.PluginErrorParams params = |
| 135 new plugin.PluginErrorParams(isFatal, message, stackTrace); | 122 new plugin.PluginErrorParams(isFatal, message, stackTrace); |
| 136 manager.handlePluginNotification('a', params.toNotification()); | 123 manager.handlePluginNotification('a', params.toNotification()); |
| 137 _verifyPluginError(isFatal, message, stackTrace); | 124 _verifyPluginError(isFatal, message, stackTrace); |
| 138 } | 125 } |
| 139 | 126 |
| 140 void test_recordAnalysisErrors_noSubscription() { | 127 void test_recordAnalysisErrors_noSubscription() { |
| 141 server.AnalysisError error = serverAnalysisError(0, 0, file: fileA); | 128 AnalysisError error = serverAnalysisError(0, 0, file: fileA); |
| 142 manager.recordAnalysisErrors('a', fileA, [error]); | 129 manager.recordAnalysisErrors('a', fileA, [error]); |
| 143 expect(channel.sentNotification, isNull); | 130 expect(channel.sentNotification, isNull); |
| 144 } | 131 } |
| 145 | 132 |
| 146 void test_recordAnalysisErrors_withSubscription() { | 133 void test_recordAnalysisErrors_withSubscription() { |
| 147 manager.setAnalysisRoots([testDir], []); | 134 manager.setAnalysisRoots([testDir], []); |
| 148 // | 135 // |
| 149 // Errors should be reported when they are recorded. | 136 // Errors should be reported when they are recorded. |
| 150 // | 137 // |
| 151 server.AnalysisError error1 = serverAnalysisError(0, 0, file: fileA); | 138 AnalysisError error1 = serverAnalysisError(0, 0, file: fileA); |
| 152 server.AnalysisError error2 = serverAnalysisError(3, 4, file: fileA); | 139 AnalysisError error2 = serverAnalysisError(3, 4, file: fileA); |
| 153 manager.recordAnalysisErrors('a', fileA, [error1, error2]); | 140 manager.recordAnalysisErrors('a', fileA, [error1, error2]); |
| 154 _verifyErrors(fileA, [error1, error2]); | 141 _verifyErrors(fileA, [error1, error2]); |
| 155 // | 142 // |
| 156 // Errors from different plugins should be cumulative. | 143 // Errors from different plugins should be cumulative. |
| 157 // | 144 // |
| 158 server.AnalysisError error3 = serverAnalysisError(6, 8, file: fileA); | 145 AnalysisError error3 = serverAnalysisError(6, 8, file: fileA); |
| 159 manager.recordAnalysisErrors('b', fileA, [error3]); | 146 manager.recordAnalysisErrors('b', fileA, [error3]); |
| 160 _verifyErrors(fileA, [error1, error2, error3]); | 147 _verifyErrors(fileA, [error1, error2, error3]); |
| 161 // | 148 // |
| 162 // Overwriting errors from one plugin should not affect errors from other | 149 // Overwriting errors from one plugin should not affect errors from other |
| 163 // plugins. | 150 // plugins. |
| 164 // | 151 // |
| 165 server.AnalysisError error4 = serverAnalysisError(9, 12, file: fileA); | 152 AnalysisError error4 = serverAnalysisError(9, 12, file: fileA); |
| 166 manager.recordAnalysisErrors('a', fileA, [error4]); | 153 manager.recordAnalysisErrors('a', fileA, [error4]); |
| 167 _verifyErrors(fileA, [error4, error3]); | 154 _verifyErrors(fileA, [error4, error3]); |
| 168 // | 155 // |
| 169 // Recording errors against a file should not affect the errors for other | 156 // Recording errors against a file should not affect the errors for other |
| 170 // files. | 157 // files. |
| 171 // | 158 // |
| 172 server.AnalysisError error5 = serverAnalysisError(12, 16, file: fileB); | 159 AnalysisError error5 = serverAnalysisError(12, 16, file: fileB); |
| 173 manager.recordAnalysisErrors('a', fileB, [error5]); | 160 manager.recordAnalysisErrors('a', fileB, [error5]); |
| 174 _verifyErrors(fileB, [error5]); | 161 _verifyErrors(fileB, [error5]); |
| 175 } | 162 } |
| 176 | 163 |
| 177 void test_recordFoldingRegions_noSubscription() { | 164 void test_recordFoldingRegions_noSubscription() { |
| 178 server.FoldingRegion region = serverFoldingRegion(10, 5); | 165 FoldingRegion region = serverFoldingRegion(10, 5); |
| 179 manager.recordFoldingRegions('a', fileA, [region]); | 166 manager.recordFoldingRegions('a', fileA, [region]); |
| 180 expect(channel.sentNotification, isNull); | 167 expect(channel.sentNotification, isNull); |
| 181 } | 168 } |
| 182 | 169 |
| 183 void test_recordFoldingRegions_withSubscription() { | 170 void test_recordFoldingRegions_withSubscription() { |
| 184 manager.setSubscriptions({ | 171 manager.setSubscriptions({ |
| 185 server.AnalysisService.FOLDING: new Set.from([fileA, fileB]) | 172 server.AnalysisService.FOLDING: new Set.from([fileA, fileB]) |
| 186 }); | 173 }); |
| 187 // | 174 // |
| 188 // Regions should be reported when they are recorded. | 175 // Regions should be reported when they are recorded. |
| 189 // | 176 // |
| 190 server.FoldingRegion region1 = serverFoldingRegion(10, 3); | 177 FoldingRegion region1 = serverFoldingRegion(10, 3); |
| 191 server.FoldingRegion region2 = serverFoldingRegion(20, 6); | 178 FoldingRegion region2 = serverFoldingRegion(20, 6); |
| 192 manager.recordFoldingRegions('a', fileA, [region1, region2]); | 179 manager.recordFoldingRegions('a', fileA, [region1, region2]); |
| 193 _verifyFoldingRegions(fileA, [region1, region2]); | 180 _verifyFoldingRegions(fileA, [region1, region2]); |
| 194 // | 181 // |
| 195 // Regions from different plugins should be cumulative. | 182 // Regions from different plugins should be cumulative. |
| 196 // | 183 // |
| 197 server.FoldingRegion region3 = serverFoldingRegion(30, 5); | 184 FoldingRegion region3 = serverFoldingRegion(30, 5); |
| 198 manager.recordFoldingRegions('b', fileA, [region3]); | 185 manager.recordFoldingRegions('b', fileA, [region3]); |
| 199 _verifyFoldingRegions(fileA, [region1, region2, region3]); | 186 _verifyFoldingRegions(fileA, [region1, region2, region3]); |
| 200 // | 187 // |
| 201 // Overwriting regions from one plugin should not affect regions from other | 188 // Overwriting regions from one plugin should not affect regions from other |
| 202 // plugins. | 189 // plugins. |
| 203 // | 190 // |
| 204 server.FoldingRegion region4 = serverFoldingRegion(40, 2); | 191 FoldingRegion region4 = serverFoldingRegion(40, 2); |
| 205 manager.recordFoldingRegions('a', fileA, [region4]); | 192 manager.recordFoldingRegions('a', fileA, [region4]); |
| 206 _verifyFoldingRegions(fileA, [region4, region3]); | 193 _verifyFoldingRegions(fileA, [region4, region3]); |
| 207 // | 194 // |
| 208 // Recording regions against a file should not affect the regions for other | 195 // Recording regions against a file should not affect the regions for other |
| 209 // files. | 196 // files. |
| 210 // | 197 // |
| 211 server.FoldingRegion region5 = serverFoldingRegion(50, 7); | 198 FoldingRegion region5 = serverFoldingRegion(50, 7); |
| 212 manager.recordFoldingRegions('a', fileB, [region5]); | 199 manager.recordFoldingRegions('a', fileB, [region5]); |
| 213 _verifyFoldingRegions(fileB, [region5]); | 200 _verifyFoldingRegions(fileB, [region5]); |
| 214 } | 201 } |
| 215 | 202 |
| 216 void test_recordHighlightRegions_noSubscription() { | 203 void test_recordHighlightRegions_noSubscription() { |
| 217 server.HighlightRegion region = serverHighlightRegion(10, 5); | 204 HighlightRegion region = serverHighlightRegion(10, 5); |
| 218 manager.recordHighlightRegions('a', fileA, [region]); | 205 manager.recordHighlightRegions('a', fileA, [region]); |
| 219 expect(channel.sentNotification, isNull); | 206 expect(channel.sentNotification, isNull); |
| 220 } | 207 } |
| 221 | 208 |
| 222 void test_recordHighlightRegions_withSubscription() { | 209 void test_recordHighlightRegions_withSubscription() { |
| 223 manager.setSubscriptions({ | 210 manager.setSubscriptions({ |
| 224 server.AnalysisService.HIGHLIGHTS: new Set.from([fileA, fileB]) | 211 server.AnalysisService.HIGHLIGHTS: new Set.from([fileA, fileB]) |
| 225 }); | 212 }); |
| 226 // | 213 // |
| 227 // Regions should be reported when they are recorded. | 214 // Regions should be reported when they are recorded. |
| 228 // | 215 // |
| 229 server.HighlightRegion region1 = serverHighlightRegion(10, 3); | 216 HighlightRegion region1 = serverHighlightRegion(10, 3); |
| 230 server.HighlightRegion region2 = serverHighlightRegion(20, 6); | 217 HighlightRegion region2 = serverHighlightRegion(20, 6); |
| 231 manager.recordHighlightRegions('a', fileA, [region1, region2]); | 218 manager.recordHighlightRegions('a', fileA, [region1, region2]); |
| 232 _verifyHighlightRegions(fileA, [region1, region2]); | 219 _verifyHighlightRegions(fileA, [region1, region2]); |
| 233 // | 220 // |
| 234 // Regions from different plugins should be cumulative. | 221 // Regions from different plugins should be cumulative. |
| 235 // | 222 // |
| 236 server.HighlightRegion region3 = serverHighlightRegion(30, 5); | 223 HighlightRegion region3 = serverHighlightRegion(30, 5); |
| 237 manager.recordHighlightRegions('b', fileA, [region3]); | 224 manager.recordHighlightRegions('b', fileA, [region3]); |
| 238 _verifyHighlightRegions(fileA, [region1, region2, region3]); | 225 _verifyHighlightRegions(fileA, [region1, region2, region3]); |
| 239 // | 226 // |
| 240 // Overwriting regions from one plugin should not affect regions from other | 227 // Overwriting regions from one plugin should not affect regions from other |
| 241 // plugins. | 228 // plugins. |
| 242 // | 229 // |
| 243 server.HighlightRegion region4 = serverHighlightRegion(40, 2); | 230 HighlightRegion region4 = serverHighlightRegion(40, 2); |
| 244 manager.recordHighlightRegions('a', fileA, [region4]); | 231 manager.recordHighlightRegions('a', fileA, [region4]); |
| 245 _verifyHighlightRegions(fileA, [region4, region3]); | 232 _verifyHighlightRegions(fileA, [region4, region3]); |
| 246 // | 233 // |
| 247 // Recording regions against a file should not affect the regions for other | 234 // Recording regions against a file should not affect the regions for other |
| 248 // files. | 235 // files. |
| 249 // | 236 // |
| 250 server.HighlightRegion region5 = serverHighlightRegion(50, 7); | 237 HighlightRegion region5 = serverHighlightRegion(50, 7); |
| 251 manager.recordHighlightRegions('a', fileB, [region5]); | 238 manager.recordHighlightRegions('a', fileB, [region5]); |
| 252 _verifyHighlightRegions(fileB, [region5]); | 239 _verifyHighlightRegions(fileB, [region5]); |
| 253 } | 240 } |
| 254 | 241 |
| 255 void test_recordNavigationParams_noSubscription() { | 242 void test_recordNavigationParams_noSubscription() { |
| 256 server.AnalysisNavigationParams params = | 243 server.AnalysisNavigationParams params = |
| 257 serverNavigationParams(0, 0, file: fileA); | 244 serverNavigationParams(0, 0, file: fileA); |
| 258 manager.recordNavigationParams('a', fileA, params); | 245 manager.recordNavigationParams('a', fileA, params); |
| 259 expect(channel.sentNotification, isNull); | 246 expect(channel.sentNotification, isNull); |
| 260 } | 247 } |
| 261 | 248 |
| 262 void test_recordNavigationParams_withSubscription() { | 249 void test_recordNavigationParams_withSubscription() { |
| 263 manager.setSubscriptions({ | 250 manager.setSubscriptions({ |
| 264 server.AnalysisService.NAVIGATION: new Set.from([fileA, fileB]) | 251 server.AnalysisService.NAVIGATION: new Set.from([fileA, fileB]) |
| 265 }); | 252 }); |
| 266 // | 253 // |
| 267 // Parameters should be reported when they are recorded. | 254 // Parameters should be reported when they are recorded. |
| 268 // | 255 // |
| 269 server.AnalysisNavigationParams params1 = | 256 server.AnalysisNavigationParams params1 = |
| 270 serverNavigationParams(0, 0, file: fileA); | 257 serverNavigationParams(0, 0, file: fileA); |
| 271 manager.recordNavigationParams('a', fileA, params1); | 258 manager.recordNavigationParams('a', fileA, params1); |
| 272 _verifyNavigationParams(params1); | 259 _verifyNavigationParams(params1); |
| 273 // | 260 // |
| 274 // Parameters from different plugins should be cumulative. | 261 // Parameters from different plugins should be cumulative. |
| 275 // | 262 // |
| 276 server.AnalysisNavigationParams params2 = | 263 server.AnalysisNavigationParams params2 = |
| 277 serverNavigationParams(2, 4, file: fileA); | 264 serverNavigationParams(2, 4, file: fileA); |
| 278 manager.recordNavigationParams('b', fileA, params2); | 265 manager.recordNavigationParams('b', fileA, params2); |
| 279 server.AnalysisNavigationParams params1and2 = | 266 server.AnalysisNavigationParams params1and2 = |
| 280 new server.AnalysisNavigationParams(fileA, <server.NavigationRegion>[ | 267 new server.AnalysisNavigationParams(fileA, <NavigationRegion>[ |
| 281 new server.NavigationRegion(0, 2, <int>[0]), | 268 new NavigationRegion(0, 2, <int>[0]), |
| 282 new server.NavigationRegion(4, 2, <int>[1]) | 269 new NavigationRegion(4, 2, <int>[1]) |
| 283 ], <server.NavigationTarget>[ | 270 ], <NavigationTarget>[ |
| 284 new server.NavigationTarget(server.ElementKind.FIELD, 0, 1, 2, 2, 3), | 271 new NavigationTarget(ElementKind.FIELD, 0, 1, 2, 2, 3), |
| 285 new server.NavigationTarget(server.ElementKind.FIELD, 2, 5, 2, 6, 7) | 272 new NavigationTarget(ElementKind.FIELD, 2, 5, 2, 6, 7) |
| 286 ], <String>[ | 273 ], <String>[ |
| 287 'aa', | 274 'aa', |
| 288 'ab', | 275 'ab', |
| 289 'ac', | 276 'ac', |
| 290 'ad' | 277 'ad' |
| 291 ]); | 278 ]); |
| 292 _verifyNavigationParams(params1and2); | 279 _verifyNavigationParams(params1and2); |
| 293 // | 280 // |
| 294 // Overwriting parameters from one plugin should not affect parameters from | 281 // Overwriting parameters from one plugin should not affect parameters from |
| 295 // other plugins. | 282 // other plugins. |
| 296 // | 283 // |
| 297 server.AnalysisNavigationParams params3 = | 284 server.AnalysisNavigationParams params3 = |
| 298 serverNavigationParams(4, 8, file: fileA); | 285 serverNavigationParams(4, 8, file: fileA); |
| 299 manager.recordNavigationParams('a', fileA, params3); | 286 manager.recordNavigationParams('a', fileA, params3); |
| 300 server.AnalysisNavigationParams params3and2 = | 287 server.AnalysisNavigationParams params3and2 = |
| 301 new server.AnalysisNavigationParams(fileA, <server.NavigationRegion>[ | 288 new server.AnalysisNavigationParams(fileA, <NavigationRegion>[ |
| 302 new server.NavigationRegion(8, 2, <int>[0]), | 289 new NavigationRegion(8, 2, <int>[0]), |
| 303 new server.NavigationRegion(4, 2, <int>[1]) | 290 new NavigationRegion(4, 2, <int>[1]) |
| 304 ], <server.NavigationTarget>[ | 291 ], <NavigationTarget>[ |
| 305 new server.NavigationTarget(server.ElementKind.FIELD, 0, 9, 2, 10, 11), | 292 new NavigationTarget(ElementKind.FIELD, 0, 9, 2, 10, 11), |
| 306 new server.NavigationTarget(server.ElementKind.FIELD, 2, 5, 2, 6, 7) | 293 new NavigationTarget(ElementKind.FIELD, 2, 5, 2, 6, 7) |
| 307 ], <String>[ | 294 ], <String>[ |
| 308 'ae', | 295 'ae', |
| 309 'af', | 296 'af', |
| 310 'ac', | 297 'ac', |
| 311 'ad' | 298 'ad' |
| 312 ]); | 299 ]); |
| 313 _verifyNavigationParams(params3and2); | 300 _verifyNavigationParams(params3and2); |
| 314 // | 301 // |
| 315 // Recording parameters against a file should not affect the parameters for | 302 // Recording parameters against a file should not affect the parameters for |
| 316 // other files. | 303 // other files. |
| 317 // | 304 // |
| 318 server.AnalysisNavigationParams params4 = | 305 server.AnalysisNavigationParams params4 = |
| 319 serverNavigationParams(6, 12, file: fileB); | 306 serverNavigationParams(6, 12, file: fileB); |
| 320 manager.recordNavigationParams('a', fileB, params4); | 307 manager.recordNavigationParams('a', fileB, params4); |
| 321 _verifyNavigationParams(params4); | 308 _verifyNavigationParams(params4); |
| 322 } | 309 } |
| 323 | 310 |
| 324 void test_recordOccurrences_noSubscription() { | 311 void test_recordOccurrences_noSubscription() { |
| 325 server.Occurrences occurrences = serverOccurrences(0, 0); | 312 Occurrences occurrences = serverOccurrences(0, 0); |
| 326 manager.recordOccurrences('a', fileA, [occurrences]); | 313 manager.recordOccurrences('a', fileA, [occurrences]); |
| 327 expect(channel.sentNotification, isNull); | 314 expect(channel.sentNotification, isNull); |
| 328 } | 315 } |
| 329 | 316 |
| 330 void test_recordOccurrences_withSubscription() { | 317 void test_recordOccurrences_withSubscription() { |
| 331 manager.setSubscriptions({ | 318 manager.setSubscriptions({ |
| 332 server.AnalysisService.OCCURRENCES: new Set.from([fileA, fileB]) | 319 server.AnalysisService.OCCURRENCES: new Set.from([fileA, fileB]) |
| 333 }); | 320 }); |
| 334 // | 321 // |
| 335 // Occurrences should be reported when they are recorded. | 322 // Occurrences should be reported when they are recorded. |
| 336 // | 323 // |
| 337 server.Occurrences occurrences1 = serverOccurrences(0, 0); | 324 Occurrences occurrences1 = serverOccurrences(0, 0); |
| 338 server.Occurrences occurrences2 = serverOccurrences(5, 7); | 325 Occurrences occurrences2 = serverOccurrences(5, 7); |
| 339 manager.recordOccurrences('a', fileA, [occurrences1, occurrences2]); | 326 manager.recordOccurrences('a', fileA, [occurrences1, occurrences2]); |
| 340 _verifyOccurrences(fileA, [occurrences1, occurrences2]); | 327 _verifyOccurrences(fileA, [occurrences1, occurrences2]); |
| 341 // | 328 // |
| 342 // Occurrences from different plugins should be cumulative. | 329 // Occurrences from different plugins should be cumulative. |
| 343 // | 330 // |
| 344 server.Occurrences occurrences3 = serverOccurrences(10, 14); | 331 Occurrences occurrences3 = serverOccurrences(10, 14); |
| 345 manager.recordOccurrences('b', fileA, [occurrences3]); | 332 manager.recordOccurrences('b', fileA, [occurrences3]); |
| 346 _verifyOccurrences(fileA, [occurrences1, occurrences2, occurrences3]); | 333 _verifyOccurrences(fileA, [occurrences1, occurrences2, occurrences3]); |
| 347 // | 334 // |
| 348 // Overwriting occurrences from one plugin should not affect occurrences | 335 // Overwriting occurrences from one plugin should not affect occurrences |
| 349 // from other plugins. | 336 // from other plugins. |
| 350 // | 337 // |
| 351 server.Occurrences occurrences4 = serverOccurrences(15, 21); | 338 Occurrences occurrences4 = serverOccurrences(15, 21); |
| 352 manager.recordOccurrences('a', fileA, [occurrences4]); | 339 manager.recordOccurrences('a', fileA, [occurrences4]); |
| 353 _verifyOccurrences(fileA, [occurrences4, occurrences3]); | 340 _verifyOccurrences(fileA, [occurrences4, occurrences3]); |
| 354 // | 341 // |
| 355 // Recording occurrences against a file should not affect the occurrences | 342 // Recording occurrences against a file should not affect the occurrences |
| 356 // for other files. | 343 // for other files. |
| 357 // | 344 // |
| 358 server.Occurrences occurrences5 = serverOccurrences(20, 28); | 345 Occurrences occurrences5 = serverOccurrences(20, 28); |
| 359 manager.recordOccurrences('a', fileB, [occurrences5]); | 346 manager.recordOccurrences('a', fileB, [occurrences5]); |
| 360 _verifyOccurrences(fileB, [occurrences5]); | 347 _verifyOccurrences(fileB, [occurrences5]); |
| 361 } | 348 } |
| 362 | 349 |
| 363 void test_recordOutlines_noSubscription() { | 350 void test_recordOutlines_noSubscription() { |
| 364 server.Outline outline = serverOutline(0, 0); | 351 Outline outline = serverOutline(0, 0); |
| 365 manager.recordOutlines('a', fileA, [outline]); | 352 manager.recordOutlines('a', fileA, [outline]); |
| 366 expect(channel.sentNotification, isNull); | 353 expect(channel.sentNotification, isNull); |
| 367 } | 354 } |
| 368 | 355 |
| 369 @failingTest | 356 @failingTest |
| 370 void test_recordOutlines_withSubscription() { | 357 void test_recordOutlines_withSubscription() { |
| 371 fail('The outline handling needs to be re-worked slightly'); | 358 fail('The outline handling needs to be re-worked slightly'); |
| 372 // TODO(brianwilkerson) Figure out outlines. What should we do when merge | 359 // TODO(brianwilkerson) Figure out outlines. What should we do when merge |
| 373 // cannot produce a single outline? | 360 // cannot produce a single outline? |
| 374 manager.setSubscriptions({ | 361 manager.setSubscriptions({ |
| 375 server.AnalysisService.OUTLINE: new Set.from([fileA, fileB]) | 362 server.AnalysisService.OUTLINE: new Set.from([fileA, fileB]) |
| 376 }); | 363 }); |
| 377 // | 364 // |
| 378 // Outlines should be reported when they are recorded. | 365 // Outlines should be reported when they are recorded. |
| 379 // | 366 // |
| 380 server.Outline outline1 = serverOutline(0, 0); | 367 Outline outline1 = serverOutline(0, 0); |
| 381 server.Outline outline2 = serverOutline(5, 7); | 368 Outline outline2 = serverOutline(5, 7); |
| 382 manager.recordOutlines('a', fileA, [outline1, outline2]); | 369 manager.recordOutlines('a', fileA, [outline1, outline2]); |
| 383 // TODO(brianwilkerson) Figure out how to test this. | 370 // TODO(brianwilkerson) Figure out how to test this. |
| 384 // _verifyOutlines(fileA, [outline1, outline2]); | 371 // _verifyOutlines(fileA, [outline1, outline2]); |
| 385 // | 372 // |
| 386 // Outlines from different plugins should be cumulative. | 373 // Outlines from different plugins should be cumulative. |
| 387 // | 374 // |
| 388 server.Outline outline3 = serverOutline(10, 14); | 375 Outline outline3 = serverOutline(10, 14); |
| 389 manager.recordOutlines('b', fileA, [outline3]); | 376 manager.recordOutlines('b', fileA, [outline3]); |
| 390 // TODO(brianwilkerson) Figure out how to test this. | 377 // TODO(brianwilkerson) Figure out how to test this. |
| 391 // _verifyOutlines(fileA, [outline1, outline2, outline3]); | 378 // _verifyOutlines(fileA, [outline1, outline2, outline3]); |
| 392 // | 379 // |
| 393 // Overwriting outlines from one plugin should not affect outlines from | 380 // Overwriting outlines from one plugin should not affect outlines from |
| 394 // other plugins. | 381 // other plugins. |
| 395 // | 382 // |
| 396 server.Outline outline4 = serverOutline(15, 21); | 383 Outline outline4 = serverOutline(15, 21); |
| 397 manager.recordOutlines('a', fileA, [outline4]); | 384 manager.recordOutlines('a', fileA, [outline4]); |
| 398 // TODO(brianwilkerson) Figure out how to test this. | 385 // TODO(brianwilkerson) Figure out how to test this. |
| 399 // _verifyOutlines(fileA, [outline4, outline3]); | 386 // _verifyOutlines(fileA, [outline4, outline3]); |
| 400 // | 387 // |
| 401 // Recording outlines against a file should not affect the outlines for | 388 // Recording outlines against a file should not affect the outlines for |
| 402 // other files. | 389 // other files. |
| 403 // | 390 // |
| 404 server.Outline outline5 = serverOutline(20, 28); | 391 Outline outline5 = serverOutline(20, 28); |
| 405 manager.recordOutlines('a', fileB, [outline5]); | 392 manager.recordOutlines('a', fileB, [outline5]); |
| 406 // TODO(brianwilkerson) Figure out how to test this. | 393 // TODO(brianwilkerson) Figure out how to test this. |
| 407 // _verifyOutlines(fileB, [outline5]); | 394 // _verifyOutlines(fileB, [outline5]); |
| 408 } | 395 } |
| 409 | 396 |
| 410 void _verifyErrors( | 397 void _verifyErrors(String fileName, List<AnalysisError> expectedErrors) { |
| 411 String fileName, List<server.AnalysisError> expectedErrors) { | |
| 412 server.Notification notification = channel.sentNotification; | 398 server.Notification notification = channel.sentNotification; |
| 413 expect(notification, isNotNull); | 399 expect(notification, isNotNull); |
| 414 expect(notification.event, 'analysis.errors'); | 400 expect(notification.event, 'analysis.errors'); |
| 415 server.AnalysisErrorsParams params = | 401 server.AnalysisErrorsParams params = |
| 416 new server.AnalysisErrorsParams.fromNotification(notification); | 402 new server.AnalysisErrorsParams.fromNotification(notification); |
| 417 expect(params, isNotNull); | 403 expect(params, isNotNull); |
| 418 expect(params.file, fileName); | 404 expect(params.file, fileName); |
| 419 expect(params.errors, equals(expectedErrors)); | 405 expect(params.errors, equals(expectedErrors)); |
| 420 channel.sentNotification = null; | 406 channel.sentNotification = null; |
| 421 } | 407 } |
| 422 | 408 |
| 423 void _verifyFoldingRegions( | 409 void _verifyFoldingRegions( |
| 424 String fileName, List<server.FoldingRegion> expectedRegions) { | 410 String fileName, List<FoldingRegion> expectedRegions) { |
| 425 server.Notification notification = channel.sentNotification; | 411 server.Notification notification = channel.sentNotification; |
| 426 expect(notification, isNotNull); | 412 expect(notification, isNotNull); |
| 427 expect(notification.event, 'analysis.folding'); | 413 expect(notification.event, 'analysis.folding'); |
| 428 server.AnalysisFoldingParams params = | 414 server.AnalysisFoldingParams params = |
| 429 new server.AnalysisFoldingParams.fromNotification(notification); | 415 new server.AnalysisFoldingParams.fromNotification(notification); |
| 430 expect(params, isNotNull); | 416 expect(params, isNotNull); |
| 431 expect(params.file, fileName); | 417 expect(params.file, fileName); |
| 432 expect(params.regions, equals(expectedRegions)); | 418 expect(params.regions, equals(expectedRegions)); |
| 433 channel.sentNotification = null; | 419 channel.sentNotification = null; |
| 434 } | 420 } |
| 435 | 421 |
| 436 void _verifyHighlightRegions( | 422 void _verifyHighlightRegions( |
| 437 String fileName, List<server.HighlightRegion> expectedRegions) { | 423 String fileName, List<HighlightRegion> expectedRegions) { |
| 438 server.Notification notification = channel.sentNotification; | 424 server.Notification notification = channel.sentNotification; |
| 439 expect(notification, isNotNull); | 425 expect(notification, isNotNull); |
| 440 expect(notification.event, 'analysis.highlights'); | 426 expect(notification.event, 'analysis.highlights'); |
| 441 server.AnalysisHighlightsParams params = | 427 server.AnalysisHighlightsParams params = |
| 442 new server.AnalysisHighlightsParams.fromNotification(notification); | 428 new server.AnalysisHighlightsParams.fromNotification(notification); |
| 443 expect(params, isNotNull); | 429 expect(params, isNotNull); |
| 444 expect(params.file, fileName); | 430 expect(params.file, fileName); |
| 445 expect(params.regions, equals(expectedRegions)); | 431 expect(params.regions, equals(expectedRegions)); |
| 446 channel.sentNotification = null; | 432 channel.sentNotification = null; |
| 447 } | 433 } |
| 448 | 434 |
| 449 void _verifyNavigationParams(server.AnalysisNavigationParams expectedParams) { | 435 void _verifyNavigationParams(server.AnalysisNavigationParams expectedParams) { |
| 450 server.Notification notification = channel.sentNotification; | 436 server.Notification notification = channel.sentNotification; |
| 451 expect(notification, isNotNull); | 437 expect(notification, isNotNull); |
| 452 expect(notification.event, 'analysis.navigation'); | 438 expect(notification.event, 'analysis.navigation'); |
| 453 server.AnalysisNavigationParams params = | 439 server.AnalysisNavigationParams params = |
| 454 new server.AnalysisNavigationParams.fromNotification(notification); | 440 new server.AnalysisNavigationParams.fromNotification(notification); |
| 455 expect(params, isNotNull); | 441 expect(params, isNotNull); |
| 456 expect(params.file, expectedParams.file); | 442 expect(params.file, expectedParams.file); |
| 457 expect(params.files, equals(expectedParams.files)); | 443 expect(params.files, equals(expectedParams.files)); |
| 458 expect(params.regions, equals(expectedParams.regions)); | 444 expect(params.regions, equals(expectedParams.regions)); |
| 459 expect(params.targets, equals(expectedParams.targets)); | 445 expect(params.targets, equals(expectedParams.targets)); |
| 460 channel.sentNotification = null; | 446 channel.sentNotification = null; |
| 461 } | 447 } |
| 462 | 448 |
| 463 void _verifyOccurrences( | 449 void _verifyOccurrences( |
| 464 String fileName, List<server.Occurrences> expectedOccurrences) { | 450 String fileName, List<Occurrences> expectedOccurrences) { |
| 465 server.Notification notification = channel.sentNotification; | 451 server.Notification notification = channel.sentNotification; |
| 466 expect(notification, isNotNull); | 452 expect(notification, isNotNull); |
| 467 expect(notification.event, 'analysis.occurrences'); | 453 expect(notification.event, 'analysis.occurrences'); |
| 468 server.AnalysisOccurrencesParams params = | 454 server.AnalysisOccurrencesParams params = |
| 469 new server.AnalysisOccurrencesParams.fromNotification(notification); | 455 new server.AnalysisOccurrencesParams.fromNotification(notification); |
| 470 expect(params, isNotNull); | 456 expect(params, isNotNull); |
| 471 expect(params.file, fileName); | 457 expect(params.file, fileName); |
| 472 expect(params.occurrences, equals(expectedOccurrences)); | 458 expect(params.occurrences, equals(expectedOccurrences)); |
| 473 channel.sentNotification = null; | 459 channel.sentNotification = null; |
| 474 } | 460 } |
| 475 | 461 |
| 476 void _verifyOutlines(String fileName, server.Outline expectedOutline) { | 462 void _verifyOutlines(String fileName, Outline expectedOutline) { |
| 477 server.Notification notification = channel.sentNotification; | 463 server.Notification notification = channel.sentNotification; |
| 478 expect(notification, isNotNull); | 464 expect(notification, isNotNull); |
| 479 expect(notification.event, 'analysis.outline'); | 465 expect(notification.event, 'analysis.outline'); |
| 480 server.AnalysisOutlineParams params = | 466 server.AnalysisOutlineParams params = |
| 481 new server.AnalysisOutlineParams.fromNotification(notification); | 467 new server.AnalysisOutlineParams.fromNotification(notification); |
| 482 expect(params, isNotNull); | 468 expect(params, isNotNull); |
| 483 expect(params.file, fileName); | 469 expect(params.file, fileName); |
| 484 expect(params.outline, equals(expectedOutline)); | 470 expect(params.outline, equals(expectedOutline)); |
| 485 channel.sentNotification = null; | 471 channel.sentNotification = null; |
| 486 } | 472 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 516 @override | 502 @override |
| 517 void sendNotification(server.Notification notification) { | 503 void sendNotification(server.Notification notification) { |
| 518 sentNotification = notification; | 504 sentNotification = notification; |
| 519 } | 505 } |
| 520 | 506 |
| 521 @override | 507 @override |
| 522 void sendResponse(server.Response response) { | 508 void sendResponse(server.Response response) { |
| 523 fail('Unexpected invocation of sendResponse'); | 509 fail('Unexpected invocation of sendResponse'); |
| 524 } | 510 } |
| 525 } | 511 } |
| OLD | NEW |