| 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 analysis.server; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
| 10 import 'dart:math' show max; | 10 import 'dart:math' show max; |
| 11 | 11 |
| 12 import 'package:analysis_server/plugin/protocol/protocol.dart' | 12 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 13 hide AnalysisOptions, Element; | 13 hide AnalysisOptions, Element; |
| 14 import 'package:analysis_server/src/analysis_logger.dart'; | 14 import 'package:analysis_server/src/analysis_logger.dart'; |
| 15 import 'package:analysis_server/src/channel/channel.dart'; | 15 import 'package:analysis_server/src/channel/channel.dart'; |
| 16 import 'package:analysis_server/src/context_manager.dart'; | 16 import 'package:analysis_server/src/context_manager.dart'; |
| 17 import 'package:analysis_server/src/operation/operation.dart'; | 17 import 'package:analysis_server/src/operation/operation.dart'; |
| 18 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 18 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 19 import 'package:analysis_server/src/operation/operation_queue.dart'; | 19 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 20 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 20 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 21 import 'package:analysis_server/src/services/correction/namespace.dart'; | 21 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| 22 import 'package:analysis_server/src/services/index/index.dart'; | 22 import 'package:analysis_server/src/services/index/index.dart'; |
| 23 import 'package:analysis_server/src/services/index2/index2.dart'; | |
| 24 import 'package:analysis_server/src/services/search/search_engine.dart'; | 23 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 25 import 'package:analysis_server/src/services/search/search_engine_internal2.dart
'; | 24 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 26 import 'package:analyzer/dart/ast/ast.dart'; | 25 import 'package:analyzer/dart/ast/ast.dart'; |
| 27 import 'package:analyzer/dart/element/element.dart'; | 26 import 'package:analyzer/dart/element/element.dart'; |
| 28 import 'package:analyzer/file_system/file_system.dart'; | 27 import 'package:analyzer/file_system/file_system.dart'; |
| 29 import 'package:analyzer/instrumentation/instrumentation.dart'; | 28 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 30 import 'package:analyzer/plugin/embedded_resolver_provider.dart'; | 29 import 'package:analyzer/plugin/embedded_resolver_provider.dart'; |
| 31 import 'package:analyzer/plugin/resolver_provider.dart'; | 30 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 32 import 'package:analyzer/source/embedder.dart'; | 31 import 'package:analyzer/source/embedder.dart'; |
| 33 import 'package:analyzer/source/pub_package_map_provider.dart'; | 32 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 34 import 'package:analyzer/src/dart/ast/utilities.dart'; | 33 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 35 import 'package:analyzer/src/generated/engine.dart'; | 34 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 * The [ResourceProvider] using which paths are converted into [Resource]s. | 102 * The [ResourceProvider] using which paths are converted into [Resource]s. |
| 104 */ | 103 */ |
| 105 final ResourceProvider resourceProvider; | 104 final ResourceProvider resourceProvider; |
| 106 | 105 |
| 107 /** | 106 /** |
| 108 * The [Index] for this server, may be `null` if indexing is disabled. | 107 * The [Index] for this server, may be `null` if indexing is disabled. |
| 109 */ | 108 */ |
| 110 final Index index; | 109 final Index index; |
| 111 | 110 |
| 112 /** | 111 /** |
| 113 * The [Index2] for this server, may be `null` if indexing is disabled. | |
| 114 */ | |
| 115 final Index2 index2; | |
| 116 | |
| 117 /** | |
| 118 * The [SearchEngine] for this server, may be `null` if indexing is disabled. | 112 * The [SearchEngine] for this server, may be `null` if indexing is disabled. |
| 119 */ | 113 */ |
| 120 final SearchEngine searchEngine; | 114 final SearchEngine searchEngine; |
| 121 | 115 |
| 122 /** | 116 /** |
| 123 * The plugin associated with this analysis server. | 117 * The plugin associated with this analysis server. |
| 124 */ | 118 */ |
| 125 final ServerPlugin serverPlugin; | 119 final ServerPlugin serverPlugin; |
| 126 | 120 |
| 127 /** | 121 /** |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 301 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| 308 * propagated up the call stack. The default is true to allow analysis | 302 * propagated up the call stack. The default is true to allow analysis |
| 309 * exceptions to show up in unit tests, but it should be set to false when | 303 * exceptions to show up in unit tests, but it should be set to false when |
| 310 * running a full analysis server. | 304 * running a full analysis server. |
| 311 */ | 305 */ |
| 312 AnalysisServer( | 306 AnalysisServer( |
| 313 this.channel, | 307 this.channel, |
| 314 this.resourceProvider, | 308 this.resourceProvider, |
| 315 PubPackageMapProvider packageMapProvider, | 309 PubPackageMapProvider packageMapProvider, |
| 316 Index _index, | 310 Index _index, |
| 317 Index2 _index2, | |
| 318 this.serverPlugin, | 311 this.serverPlugin, |
| 319 this.options, | 312 this.options, |
| 320 this.defaultSdkCreator, | 313 this.defaultSdkCreator, |
| 321 this.instrumentationService, | 314 this.instrumentationService, |
| 322 {ResolverProvider packageResolverProvider: null, | 315 {ResolverProvider packageResolverProvider: null, |
| 323 EmbeddedResolverProvider embeddedResolverProvider: null, | 316 EmbeddedResolverProvider embeddedResolverProvider: null, |
| 324 this.rethrowExceptions: true}) | 317 this.rethrowExceptions: true}) |
| 325 : index = _index, | 318 : index = _index, |
| 326 index2 = _index2, | 319 searchEngine = _index != null ? new SearchEngineImpl(_index) : null { |
| 327 searchEngine = _index != null ? new SearchEngineImpl2(_index2) : null { | |
| 328 _performance = performanceDuringStartup; | 320 _performance = performanceDuringStartup; |
| 329 defaultContextOptions.incremental = true; | 321 defaultContextOptions.incremental = true; |
| 330 defaultContextOptions.incrementalApi = | 322 defaultContextOptions.incrementalApi = |
| 331 options.enableIncrementalResolutionApi; | 323 options.enableIncrementalResolutionApi; |
| 332 defaultContextOptions.incrementalValidation = | 324 defaultContextOptions.incrementalValidation = |
| 333 options.enableIncrementalResolutionValidation; | 325 options.enableIncrementalResolutionValidation; |
| 334 defaultContextOptions.generateImplicitErrors = false; | 326 defaultContextOptions.generateImplicitErrors = false; |
| 335 operationQueue = new ServerOperationQueue(); | 327 operationQueue = new ServerOperationQueue(); |
| 336 sdkManager = new DartSdkManager(defaultSdkCreator); | 328 sdkManager = new DartSdkManager(defaultSdkCreator); |
| 337 contextManager = new ContextManagerImpl( | 329 contextManager = new ContextManagerImpl( |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 * Returns `true` if errors should be reported for [file] with the given | 1199 * Returns `true` if errors should be reported for [file] with the given |
| 1208 * absolute path. | 1200 * absolute path. |
| 1209 */ | 1201 */ |
| 1210 bool shouldSendErrorsNotificationFor(String file) { | 1202 bool shouldSendErrorsNotificationFor(String file) { |
| 1211 return !_noErrorNotification && contextManager.isInAnalysisRoot(file); | 1203 return !_noErrorNotification && contextManager.isInAnalysisRoot(file); |
| 1212 } | 1204 } |
| 1213 | 1205 |
| 1214 void shutdown() { | 1206 void shutdown() { |
| 1215 running = false; | 1207 running = false; |
| 1216 if (index != null) { | 1208 if (index != null) { |
| 1217 index.clear(); | |
| 1218 index.stop(); | 1209 index.stop(); |
| 1219 } | 1210 } |
| 1220 // Defer closing the channel and shutting down the instrumentation server so | 1211 // Defer closing the channel and shutting down the instrumentation server so |
| 1221 // that the shutdown response can be sent and logged. | 1212 // that the shutdown response can be sent and logged. |
| 1222 new Future(() { | 1213 new Future(() { |
| 1223 instrumentationService.shutdown(); | 1214 instrumentationService.shutdown(); |
| 1224 channel.close(); | 1215 channel.close(); |
| 1225 }); | 1216 }); |
| 1226 } | 1217 } |
| 1227 | 1218 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1432 } | 1423 } |
| 1433 | 1424 |
| 1434 _scheduleAnalysisImplementedNotification() async { | 1425 _scheduleAnalysisImplementedNotification() async { |
| 1435 Set<String> files = analysisServices[AnalysisService.IMPLEMENTED]; | 1426 Set<String> files = analysisServices[AnalysisService.IMPLEMENTED]; |
| 1436 if (files != null) { | 1427 if (files != null) { |
| 1437 scheduleImplementedNotification(this, files); | 1428 scheduleImplementedNotification(this, files); |
| 1438 } | 1429 } |
| 1439 } | 1430 } |
| 1440 | 1431 |
| 1441 /** | 1432 /** |
| 1442 * Schedules [performOperation] exection. | 1433 * Schedules [performOperation] execution. |
| 1443 */ | 1434 */ |
| 1444 void _schedulePerformOperation() { | 1435 void _schedulePerformOperation() { |
| 1445 if (performOperationPending) { | 1436 if (performOperationPending) { |
| 1446 return; | 1437 return; |
| 1447 } | 1438 } |
| 1448 /* | 1439 /* |
| 1449 * TODO (danrubel) Rip out this workaround once the underlying problem | 1440 * TODO (danrubel) Rip out this workaround once the underlying problem |
| 1450 * is fixed. Currently, the VM and dart:io do not deliver content | 1441 * is fixed. Currently, the VM and dart:io do not deliver content |
| 1451 * on stdin in a timely manner if the event loop is busy. | 1442 * on stdin in a timely manner if the event loop is busy. |
| 1452 * To work around this problem, we delay for 1 millisecond | 1443 * To work around this problem, we delay for 1 millisecond |
| 1453 * every 25 milliseconds. | 1444 * every 25 milliseconds. |
| 1454 * | 1445 * |
| 1455 * To disable this workaround and see the underlying problem, | 1446 * To disable this workaround and see the underlying problem, |
| 1456 * set performOperationDelayFreqency to zero | 1447 * set performOperationDelayFrequency to zero |
| 1457 */ | 1448 */ |
| 1458 int now = new DateTime.now().millisecondsSinceEpoch; | 1449 int now = new DateTime.now().millisecondsSinceEpoch; |
| 1459 if (now > _nextPerformOperationDelayTime && | 1450 if (now > _nextPerformOperationDelayTime && |
| 1460 performOperationDelayFrequency > 0) { | 1451 performOperationDelayFrequency > 0) { |
| 1461 _nextPerformOperationDelayTime = now + performOperationDelayFrequency; | 1452 _nextPerformOperationDelayTime = now + performOperationDelayFrequency; |
| 1462 new Future.delayed(new Duration(milliseconds: 1), performOperation); | 1453 new Future.delayed(new Duration(milliseconds: 1), performOperation); |
| 1463 } else { | 1454 } else { |
| 1464 new Future(performOperation); | 1455 new Future(performOperation); |
| 1465 } | 1456 } |
| 1466 performOperationPending = true; | 1457 performOperationPending = true; |
| 1467 } | 1458 } |
| 1468 | 1459 |
| 1469 /** | 1460 /** |
| 1470 * Listen for context events and invalidate index. | 1461 * Listen for context events and invalidate index. |
| 1471 * | 1462 * |
| 1472 * It is possible that this method will do more in the future, e.g. listening | 1463 * It is possible that this method will do more in the future, e.g. listening |
| 1473 * for summary information and linking pre-indexed packages into the index, | 1464 * for summary information and linking pre-indexed packages into the index, |
| 1474 * but for now we only invalidate project specific index information. | 1465 * but for now we only invalidate project specific index information. |
| 1475 */ | 1466 */ |
| 1476 void _setupIndexInvalidation() { | 1467 void _setupIndexInvalidation() { |
| 1477 if (index2 == null) { | 1468 if (index == null) { |
| 1478 return; | 1469 return; |
| 1479 } | 1470 } |
| 1480 onContextsChanged.listen((ContextsChangedEvent event) { | 1471 onContextsChanged.listen((ContextsChangedEvent event) { |
| 1481 for (AnalysisContext context in event.added) { | 1472 for (AnalysisContext context in event.added) { |
| 1482 context | 1473 context |
| 1483 .onResultChanged(RESOLVED_UNIT) | 1474 .onResultChanged(RESOLVED_UNIT) |
| 1484 .listen((ResultChangedEvent event) { | 1475 .listen((ResultChangedEvent event) { |
| 1485 if (event.wasInvalidated) { | 1476 if (event.wasInvalidated) { |
| 1486 LibrarySpecificUnit target = event.target; | 1477 LibrarySpecificUnit target = event.target; |
| 1487 index2.removeUnit(event.context, target.library, target.unit); | 1478 index.removeUnit(event.context, target.library, target.unit); |
| 1488 } | 1479 } |
| 1489 }); | 1480 }); |
| 1490 } | 1481 } |
| 1491 for (AnalysisContext context in event.removed) { | 1482 for (AnalysisContext context in event.removed) { |
| 1492 index2.removeContext(context); | 1483 index.removeContext(context); |
| 1493 } | 1484 } |
| 1494 }); | 1485 }); |
| 1495 } | 1486 } |
| 1496 } | 1487 } |
| 1497 | 1488 |
| 1498 class AnalysisServerOptions { | 1489 class AnalysisServerOptions { |
| 1499 bool enableIncrementalResolutionApi = false; | 1490 bool enableIncrementalResolutionApi = false; |
| 1500 bool enableIncrementalResolutionValidation = false; | 1491 bool enableIncrementalResolutionValidation = false; |
| 1501 bool noErrorNotification = false; | 1492 bool noErrorNotification = false; |
| 1502 bool noIndex = false; | 1493 bool noIndex = false; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 | 1570 |
| 1580 @override | 1571 @override |
| 1581 void computingPackageMap(bool computing) => | 1572 void computingPackageMap(bool computing) => |
| 1582 analysisServer._computingPackageMap(computing); | 1573 analysisServer._computingPackageMap(computing); |
| 1583 | 1574 |
| 1584 @override | 1575 @override |
| 1585 void removeContext(Folder folder, List<String> flushedFiles) { | 1576 void removeContext(Folder folder, List<String> flushedFiles) { |
| 1586 AnalysisContext context = analysisServer.folderMap.remove(folder); | 1577 AnalysisContext context = analysisServer.folderMap.remove(folder); |
| 1587 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); | 1578 sendAnalysisNotificationFlushResults(analysisServer, flushedFiles); |
| 1588 | 1579 |
| 1589 if (analysisServer.index != null) { | |
| 1590 analysisServer.index.removeContext(context); | |
| 1591 } | |
| 1592 analysisServer.operationQueue.contextRemoved(context); | 1580 analysisServer.operationQueue.contextRemoved(context); |
| 1593 analysisServer._onContextsChangedController | 1581 analysisServer._onContextsChangedController |
| 1594 .add(new ContextsChangedEvent(removed: [context])); | 1582 .add(new ContextsChangedEvent(removed: [context])); |
| 1595 analysisServer.sendContextAnalysisDoneNotifications( | 1583 analysisServer.sendContextAnalysisDoneNotifications( |
| 1596 context, AnalysisDoneReason.CONTEXT_REMOVED); | 1584 context, AnalysisDoneReason.CONTEXT_REMOVED); |
| 1597 context.dispose(); | 1585 context.dispose(); |
| 1598 } | 1586 } |
| 1599 | 1587 |
| 1600 @override | 1588 @override |
| 1601 void updateContextPackageUriResolver(AnalysisContext context) { | 1589 void updateContextPackageUriResolver(AnalysisContext context) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 * PerformAnalysisOperation._sendNotices. | 1727 * PerformAnalysisOperation._sendNotices. |
| 1740 */ | 1728 */ |
| 1741 static PerformanceTag notices = new PerformanceTag('notices'); | 1729 static PerformanceTag notices = new PerformanceTag('notices'); |
| 1742 | 1730 |
| 1743 /** | 1731 /** |
| 1744 * The [PerformanceTag] for time spent running pub. | 1732 * The [PerformanceTag] for time spent running pub. |
| 1745 */ | 1733 */ |
| 1746 static PerformanceTag pub = new PerformanceTag('pub'); | 1734 static PerformanceTag pub = new PerformanceTag('pub'); |
| 1747 | 1735 |
| 1748 /** | 1736 /** |
| 1749 * The [PerformanceTag] for time spent in server comminication channels. | 1737 * The [PerformanceTag] for time spent in server communication channels. |
| 1750 */ | 1738 */ |
| 1751 static PerformanceTag serverChannel = new PerformanceTag('serverChannel'); | 1739 static PerformanceTag serverChannel = new PerformanceTag('serverChannel'); |
| 1752 | 1740 |
| 1753 /** | 1741 /** |
| 1754 * The [PerformanceTag] for time spent in server request handlers. | 1742 * The [PerformanceTag] for time spent in server request handlers. |
| 1755 */ | 1743 */ |
| 1756 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1744 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1757 | 1745 |
| 1758 /** | 1746 /** |
| 1759 * The [PerformanceTag] for time spent in split store microtasks. | 1747 * The [PerformanceTag] for time spent in split store microtasks. |
| 1760 */ | 1748 */ |
| 1761 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1749 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1762 } | 1750 } |
| OLD | NEW |