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' hide Element; | 12 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
13 import 'package:analysis_server/src/analysis_logger.dart'; | 13 import 'package:analysis_server/src/analysis_logger.dart'; |
14 import 'package:analysis_server/src/channel/channel.dart'; | 14 import 'package:analysis_server/src/channel/channel.dart'; |
15 import 'package:analysis_server/src/context_manager.dart'; | 15 import 'package:analysis_server/src/context_manager.dart'; |
16 import 'package:analysis_server/src/operation/operation.dart'; | 16 import 'package:analysis_server/src/operation/operation.dart'; |
17 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 17 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
18 import 'package:analysis_server/src/operation/operation_queue.dart'; | 18 import 'package:analysis_server/src/operation/operation_queue.dart'; |
19 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 19 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
20 import 'package:analysis_server/src/services/correction/namespace.dart'; | 20 import 'package:analysis_server/src/services/correction/namespace.dart'; |
21 import 'package:analysis_server/src/services/index/index.dart'; | 21 import 'package:analysis_server/src/services/index/index.dart'; |
22 import 'package:analysis_server/src/services/search/search_engine.dart'; | 22 import 'package:analysis_server/src/services/search/search_engine.dart'; |
23 import 'package:analyzer/dart/element/element.dart'; | 23 import 'package:analyzer/dart/element/element.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/plugin/embedded_resolver_provider.dart'; |
26 import 'package:analyzer/plugin/resolver_provider.dart'; | 27 import 'package:analyzer/plugin/resolver_provider.dart'; |
27 import 'package:analyzer/source/embedder.dart'; | 28 import 'package:analyzer/source/embedder.dart'; |
28 import 'package:analyzer/source/pub_package_map_provider.dart'; | 29 import 'package:analyzer/source/pub_package_map_provider.dart'; |
29 import 'package:analyzer/src/generated/ast.dart'; | 30 import 'package:analyzer/src/generated/ast.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'; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 AnalysisServer( | 296 AnalysisServer( |
296 this.channel, | 297 this.channel, |
297 this.resourceProvider, | 298 this.resourceProvider, |
298 PubPackageMapProvider packageMapProvider, | 299 PubPackageMapProvider packageMapProvider, |
299 Index _index, | 300 Index _index, |
300 this.serverPlugin, | 301 this.serverPlugin, |
301 this.options, | 302 this.options, |
302 this.defaultSdk, | 303 this.defaultSdk, |
303 this.instrumentationService, | 304 this.instrumentationService, |
304 {ResolverProvider packageResolverProvider: null, | 305 {ResolverProvider packageResolverProvider: null, |
| 306 EmbeddedResolverProvider embeddedResolverProvider: null, |
305 this.rethrowExceptions: true}) | 307 this.rethrowExceptions: true}) |
306 : index = _index, | 308 : index = _index, |
307 searchEngine = _index != null ? createSearchEngine(_index) : null { | 309 searchEngine = _index != null ? createSearchEngine(_index) : null { |
308 _performance = performanceDuringStartup; | 310 _performance = performanceDuringStartup; |
309 operationQueue = new ServerOperationQueue(); | 311 operationQueue = new ServerOperationQueue(); |
310 contextManager = new ContextManagerImpl(resourceProvider, | 312 contextManager = new ContextManagerImpl( |
311 packageResolverProvider, packageMapProvider, instrumentationService); | 313 resourceProvider, |
| 314 packageResolverProvider, |
| 315 embeddedResolverProvider, |
| 316 packageMapProvider, |
| 317 instrumentationService); |
312 ServerContextManagerCallbacks contextManagerCallbacks = | 318 ServerContextManagerCallbacks contextManagerCallbacks = |
313 new ServerContextManagerCallbacks(this, resourceProvider); | 319 new ServerContextManagerCallbacks(this, resourceProvider); |
314 contextManager.callbacks = contextManagerCallbacks; | 320 contextManager.callbacks = contextManagerCallbacks; |
315 defaultContextOptions.incremental = true; | 321 defaultContextOptions.incremental = true; |
316 defaultContextOptions.incrementalApi = | 322 defaultContextOptions.incrementalApi = |
317 options.enableIncrementalResolutionApi; | 323 options.enableIncrementalResolutionApi; |
318 defaultContextOptions.incrementalValidation = | 324 defaultContextOptions.incrementalValidation = |
319 options.enableIncrementalResolutionValidation; | 325 options.enableIncrementalResolutionValidation; |
320 defaultContextOptions.generateImplicitErrors = false; | 326 defaultContextOptions.generateImplicitErrors = false; |
321 _noErrorNotification = options.noErrorNotification; | 327 _noErrorNotification = options.noErrorNotification; |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 return _analyzedFilesGlobs; | 1458 return _analyzedFilesGlobs; |
1453 } | 1459 } |
1454 | 1460 |
1455 @override | 1461 @override |
1456 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { | 1462 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { |
1457 InternalAnalysisContext context = | 1463 InternalAnalysisContext context = |
1458 AnalysisEngine.instance.createAnalysisContext(); | 1464 AnalysisEngine.instance.createAnalysisContext(); |
1459 context.contentCache = analysisServer.overlayState; | 1465 context.contentCache = analysisServer.overlayState; |
1460 analysisServer.folderMap[folder] = context; | 1466 analysisServer.folderMap[folder] = context; |
1461 _locateEmbedderYamls(context, disposition); | 1467 _locateEmbedderYamls(context, disposition); |
1462 context.sourceFactory = _createSourceFactory(context, disposition); | 1468 context.sourceFactory = _createSourceFactory(context, disposition, folder); |
1463 context.analysisOptions = | 1469 context.analysisOptions = |
1464 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); | 1470 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); |
1465 analysisServer._onContextsChangedController | 1471 analysisServer._onContextsChangedController |
1466 .add(new ContextsChangedEvent(added: [context])); | 1472 .add(new ContextsChangedEvent(added: [context])); |
1467 analysisServer.schedulePerformAnalysisOperation(context); | 1473 analysisServer.schedulePerformAnalysisOperation(context); |
1468 return context; | 1474 return context; |
1469 } | 1475 } |
1470 | 1476 |
1471 @override | 1477 @override |
1472 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1478 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 return file.exists; | 1529 return file.exists; |
1524 } | 1530 } |
1525 } | 1531 } |
1526 return false; | 1532 return false; |
1527 } | 1533 } |
1528 | 1534 |
1529 @override | 1535 @override |
1530 void updateContextPackageUriResolver( | 1536 void updateContextPackageUriResolver( |
1531 Folder contextFolder, FolderDisposition disposition) { | 1537 Folder contextFolder, FolderDisposition disposition) { |
1532 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1538 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
1533 context.sourceFactory = _createSourceFactory(context, disposition); | 1539 context.sourceFactory = |
| 1540 _createSourceFactory(context, disposition, contextFolder); |
1534 analysisServer._onContextsChangedController | 1541 analysisServer._onContextsChangedController |
1535 .add(new ContextsChangedEvent(changed: [context])); | 1542 .add(new ContextsChangedEvent(changed: [context])); |
1536 analysisServer.schedulePerformAnalysisOperation(context); | 1543 analysisServer.schedulePerformAnalysisOperation(context); |
1537 } | 1544 } |
1538 | 1545 |
1539 void _computingPackageMap(bool computing) { | 1546 void _computingPackageMap(bool computing) { |
1540 if (analysisServer.serverServices.contains(ServerService.STATUS)) { | 1547 if (analysisServer.serverServices.contains(ServerService.STATUS)) { |
1541 PubStatus pubStatus = new PubStatus(computing); | 1548 PubStatus pubStatus = new PubStatus(computing); |
1542 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); | 1549 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); |
1543 analysisServer.sendNotification(params.toNotification()); | 1550 analysisServer.sendNotification(params.toNotification()); |
1544 } | 1551 } |
1545 } | 1552 } |
1546 | 1553 |
1547 /** | 1554 /** |
1548 * Set up a [SourceFactory] that resolves packages as appropriate for the | 1555 * Set up a [SourceFactory] that resolves packages as appropriate for the |
1549 * given [disposition]. | 1556 * given [disposition]. |
1550 */ | 1557 */ |
1551 SourceFactory _createSourceFactory( | 1558 SourceFactory _createSourceFactory(InternalAnalysisContext context, |
1552 InternalAnalysisContext context, FolderDisposition disposition) { | 1559 FolderDisposition disposition, Folder folder) { |
1553 List<UriResolver> resolvers = []; | 1560 List<UriResolver> resolvers = []; |
1554 List<UriResolver> packageUriResolvers = | 1561 List<UriResolver> packageUriResolvers = |
1555 disposition.createPackageUriResolvers(resourceProvider); | 1562 disposition.createPackageUriResolvers(resourceProvider); |
1556 EmbedderUriResolver embedderUriResolver = | 1563 |
| 1564 EmbedderUriResolver embedderUriResolver; |
| 1565 |
| 1566 // First check for a resolver provider. |
| 1567 ContextManager contextManager = analysisServer.contextManager; |
| 1568 if (contextManager is ContextManagerImpl) { |
| 1569 EmbeddedResolverProvider resolverProvider = |
| 1570 contextManager.embeddedUriResolverProvider; |
| 1571 if (resolverProvider != null) { |
| 1572 embedderUriResolver = resolverProvider(folder); |
| 1573 } |
| 1574 } |
| 1575 |
| 1576 // If no embedded URI resolver was provided, defer to a locator-backed one. |
| 1577 embedderUriResolver ??= |
1557 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls); | 1578 new EmbedderUriResolver(context.embedderYamlLocator.embedderYamls); |
1558 if (embedderUriResolver.length == 0) { | 1579 if (embedderUriResolver.length == 0) { |
1559 // The embedder uri resolver has no mappings. Use the default Dart SDK | 1580 // The embedder uri resolver has no mappings. Use the default Dart SDK |
1560 // uri resolver. | 1581 // uri resolver. |
1561 resolvers.add(new DartUriResolver(analysisServer.defaultSdk)); | 1582 resolvers.add(new DartUriResolver(analysisServer.defaultSdk)); |
1562 } else { | 1583 } else { |
1563 // The embedder uri resolver has mappings, use it instead of the default | 1584 // The embedder uri resolver has mappings, use it instead of the default |
1564 // Dart SDK uri resolver. | 1585 // Dart SDK uri resolver. |
1565 resolvers.add(embedderUriResolver); | 1586 resolvers.add(embedderUriResolver); |
1566 } | 1587 } |
| 1588 |
1567 resolvers.addAll(packageUriResolvers); | 1589 resolvers.addAll(packageUriResolvers); |
1568 resolvers.add(new ResourceUriResolver(resourceProvider)); | 1590 resolvers.add(new ResourceUriResolver(resourceProvider)); |
1569 return new SourceFactory(resolvers, disposition.packages); | 1591 return new SourceFactory(resolvers, disposition.packages); |
1570 } | 1592 } |
1571 | 1593 |
1572 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` | 1594 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` |
1573 /// files. | 1595 /// files. |
1574 void _locateEmbedderYamls( | 1596 void _locateEmbedderYamls( |
1575 InternalAnalysisContext context, FolderDisposition disposition) { | 1597 InternalAnalysisContext context, FolderDisposition disposition) { |
1576 Map<String, List<Folder>> packageMap; | 1598 Map<String, List<Folder>> packageMap; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 /** | 1699 /** |
1678 * The [PerformanceTag] for time spent in server request handlers. | 1700 * The [PerformanceTag] for time spent in server request handlers. |
1679 */ | 1701 */ |
1680 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1702 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
1681 | 1703 |
1682 /** | 1704 /** |
1683 * The [PerformanceTag] for time spent in split store microtasks. | 1705 * The [PerformanceTag] for time spent in split store microtasks. |
1684 */ | 1706 */ |
1685 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1707 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
1686 } | 1708 } |
OLD | NEW |