| 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/resolver_provider.dart'; | 12 import 'package:analysis_server/plugin/analysis/resolver_provider.dart'; |
| 13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide 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/search/search_engine.dart'; | 23 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 24 import 'package:analyzer/file_system/file_system.dart'; | 24 import 'package:analyzer/file_system/file_system.dart'; |
| 25 import 'package:analyzer/instrumentation/instrumentation.dart'; | 25 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 26 import 'package:analyzer/source/embedder.dart'; |
| 26 import 'package:analyzer/source/pub_package_map_provider.dart'; | 27 import 'package:analyzer/source/pub_package_map_provider.dart'; |
| 27 import 'package:analyzer/src/generated/ast.dart'; | 28 import 'package:analyzer/src/generated/ast.dart'; |
| 28 import 'package:analyzer/src/generated/element.dart'; | 29 import 'package:analyzer/src/generated/element.dart'; |
| 29 import 'package:analyzer/src/generated/engine.dart'; | 30 import 'package:analyzer/src/generated/engine.dart'; |
| 30 import 'package:analyzer/src/generated/java_engine.dart'; | 31 import 'package:analyzer/src/generated/java_engine.dart'; |
| 31 import 'package:analyzer/src/generated/java_io.dart'; | 32 import 'package:analyzer/src/generated/java_io.dart'; |
| 32 import 'package:analyzer/src/generated/sdk.dart'; | 33 import 'package:analyzer/src/generated/sdk.dart'; |
| 33 import 'package:analyzer/src/generated/source.dart'; | 34 import 'package:analyzer/src/generated/source.dart'; |
| 34 import 'package:analyzer/src/generated/source_io.dart'; | 35 import 'package:analyzer/src/generated/source_io.dart'; |
| 35 import 'package:analyzer/src/generated/utilities_general.dart'; | 36 import 'package:analyzer/src/generated/utilities_general.dart'; |
| (...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 } | 1442 } |
| 1442 return _analyzedFilesGlobs; | 1443 return _analyzedFilesGlobs; |
| 1443 } | 1444 } |
| 1444 | 1445 |
| 1445 @override | 1446 @override |
| 1446 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { | 1447 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { |
| 1447 InternalAnalysisContext context = | 1448 InternalAnalysisContext context = |
| 1448 AnalysisEngine.instance.createAnalysisContext(); | 1449 AnalysisEngine.instance.createAnalysisContext(); |
| 1449 context.contentCache = analysisServer.overlayState; | 1450 context.contentCache = analysisServer.overlayState; |
| 1450 analysisServer.folderMap[folder] = context; | 1451 analysisServer.folderMap[folder] = context; |
| 1451 context.sourceFactory = _createSourceFactory(disposition); | 1452 _locateEmbedderYamls(context, disposition); |
| 1453 context.sourceFactory = _createSourceFactory(context, disposition); |
| 1452 context.analysisOptions = | 1454 context.analysisOptions = |
| 1453 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); | 1455 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); |
| 1454 analysisServer._onContextsChangedController | 1456 analysisServer._onContextsChangedController |
| 1455 .add(new ContextsChangedEvent(added: [context])); | 1457 .add(new ContextsChangedEvent(added: [context])); |
| 1456 analysisServer.schedulePerformAnalysisOperation(context); | 1458 analysisServer.schedulePerformAnalysisOperation(context); |
| 1457 return context; | 1459 return context; |
| 1458 } | 1460 } |
| 1459 | 1461 |
| 1460 @override | 1462 @override |
| 1461 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1463 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 return file.exists; | 1512 return file.exists; |
| 1511 } | 1513 } |
| 1512 } | 1514 } |
| 1513 return false; | 1515 return false; |
| 1514 } | 1516 } |
| 1515 | 1517 |
| 1516 @override | 1518 @override |
| 1517 void updateContextPackageUriResolver( | 1519 void updateContextPackageUriResolver( |
| 1518 Folder contextFolder, FolderDisposition disposition) { | 1520 Folder contextFolder, FolderDisposition disposition) { |
| 1519 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1521 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
| 1520 context.sourceFactory = _createSourceFactory(disposition); | 1522 context.sourceFactory = _createSourceFactory(context, disposition); |
| 1521 analysisServer._onContextsChangedController | 1523 analysisServer._onContextsChangedController |
| 1522 .add(new ContextsChangedEvent(changed: [context])); | 1524 .add(new ContextsChangedEvent(changed: [context])); |
| 1523 analysisServer.schedulePerformAnalysisOperation(context); | 1525 analysisServer.schedulePerformAnalysisOperation(context); |
| 1524 } | 1526 } |
| 1525 | 1527 |
| 1526 void _computingPackageMap(bool computing) { | 1528 void _computingPackageMap(bool computing) { |
| 1527 if (analysisServer.serverServices.contains(ServerService.STATUS)) { | 1529 if (analysisServer.serverServices.contains(ServerService.STATUS)) { |
| 1528 PubStatus pubStatus = new PubStatus(computing); | 1530 PubStatus pubStatus = new PubStatus(computing); |
| 1529 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); | 1531 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); |
| 1530 analysisServer.sendNotification(params.toNotification()); | 1532 analysisServer.sendNotification(params.toNotification()); |
| 1531 } | 1533 } |
| 1532 } | 1534 } |
| 1533 | 1535 |
| 1536 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` |
| 1537 /// files. |
| 1538 void _locateEmbedderYamls(InternalAnalysisContext context, |
| 1539 FolderDisposition disposition) { |
| 1540 Map<String, List<Folder>> packageMap; |
| 1541 if (disposition is PackageMapDisposition) { |
| 1542 packageMap = disposition.packageMap; |
| 1543 } else if (disposition is PackagesFileDisposition) { |
| 1544 packageMap = disposition.buildPackageMap(resourceProvider); |
| 1545 } |
| 1546 context.embedderYamlLocator.refresh(packageMap); |
| 1547 } |
| 1548 |
| 1534 /** | 1549 /** |
| 1535 * Set up a [SourceFactory] that resolves packages as appropriate for the | 1550 * Set up a [SourceFactory] that resolves packages as appropriate for the |
| 1536 * given [disposition]. | 1551 * given [disposition]. |
| 1537 */ | 1552 */ |
| 1538 SourceFactory _createSourceFactory(FolderDisposition disposition) { | 1553 SourceFactory _createSourceFactory(InternalAnalysisContext context, |
| 1539 UriResolver dartResolver = new DartUriResolver(analysisServer.defaultSdk); | 1554 FolderDisposition disposition) { |
| 1540 UriResolver resourceResolver = new ResourceUriResolver(resourceProvider); | |
| 1541 List<UriResolver> resolvers = []; | 1555 List<UriResolver> resolvers = []; |
| 1542 resolvers.add(dartResolver); | 1556 List<UriResolver> packageUriResolvers = |
| 1543 resolvers.addAll(disposition.createPackageUriResolvers(resourceProvider)); | 1557 disposition.createPackageUriResolvers(resourceProvider); |
| 1544 resolvers.add(resourceResolver); | 1558 EmbedderUriResolver embedderUriResolver = |
| 1559 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls); |
| 1560 if (embedderUriResolver.length == 0) { |
| 1561 // The embedder uri resolver has no mappings. Use the default Dart SDK |
| 1562 // uri resolver. |
| 1563 resolvers.add(new DartUriResolver(analysisServer.defaultSdk)); |
| 1564 } else { |
| 1565 // The embedder uri resolver has mappings, use it instead of the default |
| 1566 // Dart SDK uri resolver. |
| 1567 resolvers.add(embedderUriResolver); |
| 1568 } |
| 1569 resolvers.addAll(packageUriResolvers); |
| 1570 resolvers.add(new ResourceUriResolver(resourceProvider)); |
| 1545 return new SourceFactory(resolvers, disposition.packages); | 1571 return new SourceFactory(resolvers, disposition.packages); |
| 1546 } | 1572 } |
| 1547 } | 1573 } |
| 1548 | 1574 |
| 1549 /** | 1575 /** |
| 1550 * A class used by [AnalysisServer] to record performance information | 1576 * A class used by [AnalysisServer] to record performance information |
| 1551 * such as request latency. | 1577 * such as request latency. |
| 1552 */ | 1578 */ |
| 1553 class ServerPerformance { | 1579 class ServerPerformance { |
| 1554 /** | 1580 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 /** | 1666 /** |
| 1641 * The [PerformanceTag] for time spent in server request handlers. | 1667 * The [PerformanceTag] for time spent in server request handlers. |
| 1642 */ | 1668 */ |
| 1643 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1669 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1644 | 1670 |
| 1645 /** | 1671 /** |
| 1646 * The [PerformanceTag] for time spent in split store microtasks. | 1672 * The [PerformanceTag] for time spent in split store microtasks. |
| 1647 */ | 1673 */ |
| 1648 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1674 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1649 } | 1675 } |
| OLD | NEW |