| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library test.analysis_server; | 5 library test.analysis_server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 server.folderMap[dir] = context; | 276 server.folderMap[dir] = context; |
| 277 | 277 |
| 278 ContextSourcePair pair = server.getContextSourcePair(filePath); | 278 ContextSourcePair pair = server.getContextSourcePair(filePath); |
| 279 Source source = pair.source; | 279 Source source = pair.source; |
| 280 expect(pair.context, same(context)); | 280 expect(pair.context, same(context)); |
| 281 expect(source, isNotNull); | 281 expect(source, isNotNull); |
| 282 expect(source.uri.scheme, 'file'); | 282 expect(source.uri.scheme, 'file'); |
| 283 expect(source.fullName, filePath); | 283 expect(source.fullName, filePath); |
| 284 } | 284 } |
| 285 | 285 |
| 286 /** |
| 287 * Test that having multiple analysis contexts analyze the same file doesn't |
| 288 * cause that file to receive duplicate notifications when it's modified. |
| 289 */ |
| 290 Future test_no_duplicate_notifications() async { |
| 291 // Subscribe to STATUS so we'll know when analysis is done. |
| 292 server.serverServices = [ServerService.STATUS].toSet(); |
| 293 resourceProvider.newFolder('/foo'); |
| 294 resourceProvider.newFolder('/bar'); |
| 295 resourceProvider.newFile('/foo/foo.dart', 'import "../bar/bar.dart";'); |
| 296 File bar = resourceProvider.newFile('/bar/bar.dart', 'library bar;'); |
| 297 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 298 Map<AnalysisService, Set<String>> subscriptions = |
| 299 <AnalysisService, Set<String>>{}; |
| 300 for (AnalysisService service in AnalysisService.VALUES) { |
| 301 subscriptions[service] = <String>[bar.path].toSet(); |
| 302 } |
| 303 server.setAnalysisSubscriptions(subscriptions); |
| 304 await pumpEventQueue(100); |
| 305 expect(server.statusAnalyzing, isFalse); |
| 306 channel.notificationsReceived.clear(); |
| 307 server.updateContent( |
| 308 '0', {bar.path: new AddContentOverlay('library bar; void f() {}')}); |
| 309 await pumpEventQueue(100); |
| 310 expect(server.statusAnalyzing, isFalse); |
| 311 expect(channel.notificationsReceived, isNotEmpty); |
| 312 Set<String> notificationTypesReceived = new Set<String>(); |
| 313 for (Notification notification in channel.notificationsReceived) { |
| 314 String notificationType = notification.event; |
| 315 switch (notificationType) { |
| 316 case 'server.status': |
| 317 case 'analysis.errors': |
| 318 // It's normal for these notifications to be sent multiple times. |
| 319 break; |
| 320 case 'analysis.outline': |
| 321 // It's normal for this notification to be sent twice. |
| 322 // TODO(paulberry): why? |
| 323 break; |
| 324 default: |
| 325 if (!notificationTypesReceived.add(notificationType)) { |
| 326 fail('Notification type $notificationType received more than once'); |
| 327 } |
| 328 break; |
| 329 } |
| 330 } |
| 331 } |
| 332 |
| 286 test_operationsRemovedOnContextDisposal() async { | 333 test_operationsRemovedOnContextDisposal() async { |
| 287 resourceProvider.newFolder('/foo'); | 334 resourceProvider.newFolder('/foo'); |
| 288 resourceProvider.newFile('/foo/baz.dart', 'library lib;'); | 335 resourceProvider.newFile('/foo/baz.dart', 'library lib;'); |
| 289 resourceProvider.newFolder('/bar'); | 336 resourceProvider.newFolder('/bar'); |
| 290 resourceProvider.newFile('/bar/baz.dart', 'library lib;'); | 337 resourceProvider.newFile('/bar/baz.dart', 'library lib;'); |
| 291 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); | 338 server.setAnalysisRoots('0', ['/foo', '/bar'], [], {}); |
| 292 await pumpEventQueue(); | 339 await pumpEventQueue(); |
| 293 AnalysisContext contextFoo = server.getAnalysisContext('/foo/baz.dart'); | 340 AnalysisContext contextFoo = server.getAnalysisContext('/foo/baz.dart'); |
| 294 AnalysisContext contextBar = server.getAnalysisContext('/bar/baz.dart'); | 341 AnalysisContext contextBar = server.getAnalysisContext('/bar/baz.dart'); |
| 295 _MockServerOperation operationFoo = new _MockServerOperation(contextFoo); | 342 _MockServerOperation operationFoo = new _MockServerOperation(contextFoo); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 _MockServerOperation(this.context); | 481 _MockServerOperation(this.context); |
| 435 | 482 |
| 436 @override | 483 @override |
| 437 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; | 484 ServerOperationPriority get priority => ServerOperationPriority.ANALYSIS; |
| 438 | 485 |
| 439 @override | 486 @override |
| 440 void perform(AnalysisServer server) { | 487 void perform(AnalysisServer server) { |
| 441 isComplete = true; | 488 isComplete = true; |
| 442 } | 489 } |
| 443 } | 490 } |
| OLD | NEW |