| 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/analysis/analyzed_files.dart'; | 12 import 'package:analysis_server/plugin/analysis/analyzed_files.dart'; |
| 13 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; | 13 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; |
| 14 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 14 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
| 15 import 'package:analysis_server/src/analysis_logger.dart'; | 15 import 'package:analysis_server/src/analysis_logger.dart'; |
| 16 import 'package:analysis_server/src/channel/channel.dart'; | 16 import 'package:analysis_server/src/channel/channel.dart'; |
| 17 import 'package:analysis_server/src/context_manager.dart'; | 17 import 'package:analysis_server/src/context_manager.dart'; |
| 18 import 'package:analysis_server/src/operation/operation.dart'; | 18 import 'package:analysis_server/src/operation/operation.dart'; |
| 19 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 19 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 20 import 'package:analysis_server/src/operation/operation_queue.dart'; | 20 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 21 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 21 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
| 22 import 'package:analysis_server/src/services/correction/namespace.dart'; | 22 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| 23 import 'package:analysis_server/src/services/index/index.dart'; | 23 import 'package:analysis_server/src/services/index/index.dart'; |
| 24 import 'package:analysis_server/src/services/search/search_engine.dart'; | 24 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 25 import 'package:analyzer/file_system/file_system.dart'; | 25 import 'package:analyzer/file_system/file_system.dart'; |
| 26 import 'package:analyzer/instrumentation/instrumentation.dart'; | 26 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 27 import 'package:analyzer/source/embedder.dart'; |
| 27 import 'package:analyzer/source/pub_package_map_provider.dart'; | 28 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 28 import 'package:analyzer/src/generated/ast.dart'; | 29 import 'package:analyzer/src/generated/ast.dart'; |
| 29 import 'package:analyzer/src/generated/element.dart'; | 30 import 'package:analyzer/src/generated/element.dart'; |
| 30 import 'package:analyzer/src/generated/engine.dart'; | 31 import 'package:analyzer/src/generated/engine.dart'; |
| 31 import 'package:analyzer/src/generated/java_engine.dart'; | 32 import 'package:analyzer/src/generated/java_engine.dart'; |
| 32 import 'package:analyzer/src/generated/java_io.dart'; | 33 import 'package:analyzer/src/generated/java_io.dart'; |
| 33 import 'package:analyzer/src/generated/sdk.dart'; | 34 import 'package:analyzer/src/generated/sdk.dart'; |
| 34 import 'package:analyzer/src/generated/source.dart'; | 35 import 'package:analyzer/src/generated/source.dart'; |
| 35 import 'package:analyzer/src/generated/source_io.dart'; | 36 import 'package:analyzer/src/generated/source_io.dart'; |
| 36 import 'package:analyzer/src/generated/utilities_general.dart'; | 37 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 } | 1435 } |
| 1435 return _analyzedFilesGlobs; | 1436 return _analyzedFilesGlobs; |
| 1436 } | 1437 } |
| 1437 | 1438 |
| 1438 @override | 1439 @override |
| 1439 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { | 1440 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { |
| 1440 InternalAnalysisContext context = | 1441 InternalAnalysisContext context = |
| 1441 AnalysisEngine.instance.createAnalysisContext(); | 1442 AnalysisEngine.instance.createAnalysisContext(); |
| 1442 context.contentCache = analysisServer.overlayState; | 1443 context.contentCache = analysisServer.overlayState; |
| 1443 analysisServer.folderMap[folder] = context; | 1444 analysisServer.folderMap[folder] = context; |
| 1444 context.sourceFactory = _createSourceFactory(disposition); | 1445 _locateEmbedderYamls(context, disposition); |
| 1446 context.sourceFactory = _createSourceFactory(context, disposition); |
| 1445 context.analysisOptions = | 1447 context.analysisOptions = |
| 1446 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); | 1448 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); |
| 1447 analysisServer._onContextsChangedController | 1449 analysisServer._onContextsChangedController |
| 1448 .add(new ContextsChangedEvent(added: [context])); | 1450 .add(new ContextsChangedEvent(added: [context])); |
| 1449 analysisServer.schedulePerformAnalysisOperation(context); | 1451 analysisServer.schedulePerformAnalysisOperation(context); |
| 1450 return context; | 1452 return context; |
| 1451 } | 1453 } |
| 1452 | 1454 |
| 1453 @override | 1455 @override |
| 1454 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1456 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 return file.exists; | 1505 return file.exists; |
| 1504 } | 1506 } |
| 1505 } | 1507 } |
| 1506 return false; | 1508 return false; |
| 1507 } | 1509 } |
| 1508 | 1510 |
| 1509 @override | 1511 @override |
| 1510 void updateContextPackageUriResolver( | 1512 void updateContextPackageUriResolver( |
| 1511 Folder contextFolder, FolderDisposition disposition) { | 1513 Folder contextFolder, FolderDisposition disposition) { |
| 1512 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1514 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
| 1513 context.sourceFactory = _createSourceFactory(disposition); | 1515 context.sourceFactory = _createSourceFactory(context, disposition); |
| 1514 analysisServer._onContextsChangedController | 1516 analysisServer._onContextsChangedController |
| 1515 .add(new ContextsChangedEvent(changed: [context])); | 1517 .add(new ContextsChangedEvent(changed: [context])); |
| 1516 analysisServer.schedulePerformAnalysisOperation(context); | 1518 analysisServer.schedulePerformAnalysisOperation(context); |
| 1517 } | 1519 } |
| 1518 | 1520 |
| 1519 void _computingPackageMap(bool computing) { | 1521 void _computingPackageMap(bool computing) { |
| 1520 if (analysisServer.serverServices.contains(ServerService.STATUS)) { | 1522 if (analysisServer.serverServices.contains(ServerService.STATUS)) { |
| 1521 PubStatus pubStatus = new PubStatus(computing); | 1523 PubStatus pubStatus = new PubStatus(computing); |
| 1522 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); | 1524 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); |
| 1523 analysisServer.sendNotification(params.toNotification()); | 1525 analysisServer.sendNotification(params.toNotification()); |
| 1524 } | 1526 } |
| 1525 } | 1527 } |
| 1526 | 1528 |
| 1529 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` |
| 1530 /// files. |
| 1531 void _locateEmbedderYamls(AnalysisContext context, |
| 1532 FolderDisposition disposition) { |
| 1533 Map<String, List<Folder>> packageMap; |
| 1534 if (disposition is PackageMapDisposition) { |
| 1535 packageMap = disposition.packageMap; |
| 1536 } else if (disposition is PackagesFileDisposition) { |
| 1537 packageMap = disposition.buildPackageMap(resourceProvider); |
| 1538 } |
| 1539 context.embedderYamlLocator.refresh(packageMap); |
| 1540 } |
| 1541 |
| 1527 /** | 1542 /** |
| 1528 * Set up a [SourceFactory] that resolves packages as appropriate for the | 1543 * Set up a [SourceFactory] that resolves packages as appropriate for the |
| 1529 * given [disposition]. | 1544 * given [disposition]. |
| 1530 */ | 1545 */ |
| 1531 SourceFactory _createSourceFactory(FolderDisposition disposition) { | 1546 SourceFactory _createSourceFactory(AnalysisContext context, |
| 1532 UriResolver dartResolver = new DartUriResolver(analysisServer.defaultSdk); | 1547 FolderDisposition disposition) { |
| 1533 UriResolver resourceResolver = new ResourceUriResolver(resourceProvider); | |
| 1534 List<UriResolver> resolvers = []; | 1548 List<UriResolver> resolvers = []; |
| 1535 resolvers.add(dartResolver); | 1549 List<UriResolver> packageUriResolvers = |
| 1536 resolvers.addAll(disposition.createPackageUriResolvers(resourceProvider)); | 1550 disposition.createPackageUriResolvers(resourceProvider); |
| 1537 resolvers.add(resourceResolver); | 1551 EmbedderUriResolver embedderUriResolver = |
| 1552 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls); |
| 1553 if (embedderUriResolver.length == 0) { |
| 1554 // The embedder uri resolver has no mappings. Use the default Dart SDK |
| 1555 // uri resolver. |
| 1556 resolvers.add(new DartUriResolver(analysisServer.defaultSdk)); |
| 1557 } else { |
| 1558 // The embedder uri resolver has mappings, use it instead of the default |
| 1559 // Dart SDK uri resolver. |
| 1560 resolvers.add(embedderUriResolver); |
| 1561 } |
| 1562 resolvers.addAll(packageUriResolvers); |
| 1563 resolvers.add(new ResourceUriResolver(resourceProvider)); |
| 1538 return new SourceFactory(resolvers, disposition.packages); | 1564 return new SourceFactory(resolvers, disposition.packages); |
| 1539 } | 1565 } |
| 1540 } | 1566 } |
| 1541 | 1567 |
| 1542 /** | 1568 /** |
| 1543 * A class used by [AnalysisServer] to record performance information | 1569 * A class used by [AnalysisServer] to record performance information |
| 1544 * such as request latency. | 1570 * such as request latency. |
| 1545 */ | 1571 */ |
| 1546 class ServerPerformance { | 1572 class ServerPerformance { |
| 1547 /** | 1573 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 /** | 1659 /** |
| 1634 * The [PerformanceTag] for time spent in server request handlers. | 1660 * The [PerformanceTag] for time spent in server request handlers. |
| 1635 */ | 1661 */ |
| 1636 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1662 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1637 | 1663 |
| 1638 /** | 1664 /** |
| 1639 * The [PerformanceTag] for time spent in split store microtasks. | 1665 * The [PerformanceTag] for time spent in split store microtasks. |
| 1640 */ | 1666 */ |
| 1641 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1667 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1642 } | 1668 } |
| OLD | NEW |