| 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/analyzed_files.dart'; | 12 import 'package:analysis_server/plugin/analyzed_files.dart'; |
| 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/protocol.dart' hide Element; | 20 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 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:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | 24 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; |
| 25 import 'package:analysis_server/uri/resolver_provider.dart'; | 25 import 'package:analysis_server/uri/resolver_provider.dart'; |
| 26 import 'package:analyzer/file_system/file_system.dart'; | 26 import 'package:analyzer/file_system/file_system.dart'; |
| 27 import 'package:analyzer/instrumentation/instrumentation.dart'; | 27 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 28 import 'package:analyzer/source/package_map_resolver.dart'; | |
| 29 import 'package:analyzer/source/sdk_ext.dart'; | |
| 30 import 'package:analyzer/src/generated/ast.dart'; | 28 import 'package:analyzer/src/generated/ast.dart'; |
| 31 import 'package:analyzer/src/generated/element.dart'; | 29 import 'package:analyzer/src/generated/element.dart'; |
| 32 import 'package:analyzer/src/generated/engine.dart'; | 30 import 'package:analyzer/src/generated/engine.dart'; |
| 33 import 'package:analyzer/src/generated/java_engine.dart'; | 31 import 'package:analyzer/src/generated/java_engine.dart'; |
| 34 import 'package:analyzer/src/generated/sdk.dart'; | 32 import 'package:analyzer/src/generated/sdk.dart'; |
| 35 import 'package:analyzer/src/generated/source.dart'; | 33 import 'package:analyzer/src/generated/source.dart'; |
| 36 import 'package:analyzer/src/generated/source_io.dart'; | 34 import 'package:analyzer/src/generated/source_io.dart'; |
| 37 import 'package:analyzer/src/generated/utilities_general.dart'; | 35 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 38 import 'package:package_config/packages.dart'; | 36 import 'package:package_config/packages.dart'; |
| 39 import 'package:plugin/plugin.dart'; | 37 import 'package:plugin/plugin.dart'; |
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 final AnalysisServer analysisServer; | 1346 final AnalysisServer analysisServer; |
| 1349 | 1347 |
| 1350 /** | 1348 /** |
| 1351 * The [ResourceProvider] by which paths are converted into [Resource]s. | 1349 * The [ResourceProvider] by which paths are converted into [Resource]s. |
| 1352 */ | 1350 */ |
| 1353 final ResourceProvider resourceProvider; | 1351 final ResourceProvider resourceProvider; |
| 1354 | 1352 |
| 1355 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); | 1353 ServerContextManagerCallbacks(this.analysisServer, this.resourceProvider); |
| 1356 | 1354 |
| 1357 @override | 1355 @override |
| 1358 AnalysisContext addContext( | 1356 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { |
| 1359 Folder folder, UriResolver packageUriResolver, Packages packages) { | |
| 1360 InternalAnalysisContext context = | 1357 InternalAnalysisContext context = |
| 1361 AnalysisEngine.instance.createAnalysisContext(); | 1358 AnalysisEngine.instance.createAnalysisContext(); |
| 1362 context.contentCache = analysisServer.overlayState; | 1359 context.contentCache = analysisServer.overlayState; |
| 1363 analysisServer.folderMap[folder] = context; | 1360 analysisServer.folderMap[folder] = context; |
| 1364 context.sourceFactory = _createSourceFactory(packageUriResolver, packages); | 1361 context.sourceFactory = _createSourceFactory(disposition); |
| 1365 context.analysisOptions = | 1362 context.analysisOptions = |
| 1366 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); | 1363 new AnalysisOptionsImpl.from(analysisServer.defaultContextOptions); |
| 1367 analysisServer._onContextsChangedController | 1364 analysisServer._onContextsChangedController |
| 1368 .add(new ContextsChangedEvent(added: [context])); | 1365 .add(new ContextsChangedEvent(added: [context])); |
| 1369 analysisServer.schedulePerformAnalysisOperation(context); | 1366 analysisServer.schedulePerformAnalysisOperation(context); |
| 1370 return context; | 1367 return context; |
| 1371 } | 1368 } |
| 1372 | 1369 |
| 1373 @override | 1370 @override |
| 1374 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1371 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 // links causing the analyzer to thrash, just ignore links to | 1420 // links causing the analyzer to thrash, just ignore links to |
| 1424 // non-existent files. | 1421 // non-existent files. |
| 1425 return file.exists; | 1422 return file.exists; |
| 1426 } | 1423 } |
| 1427 } | 1424 } |
| 1428 return false; | 1425 return false; |
| 1429 } | 1426 } |
| 1430 | 1427 |
| 1431 @override | 1428 @override |
| 1432 void updateContextPackageUriResolver( | 1429 void updateContextPackageUriResolver( |
| 1433 Folder contextFolder, UriResolver packageUriResolver, Packages packages) { | 1430 Folder contextFolder, FolderDisposition disposition) { |
| 1434 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1431 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
| 1435 context.sourceFactory = _createSourceFactory(packageUriResolver, packages); | 1432 context.sourceFactory = _createSourceFactory(disposition); |
| 1436 analysisServer._onContextsChangedController | 1433 analysisServer._onContextsChangedController |
| 1437 .add(new ContextsChangedEvent(changed: [context])); | 1434 .add(new ContextsChangedEvent(changed: [context])); |
| 1438 analysisServer.schedulePerformAnalysisOperation(context); | 1435 analysisServer.schedulePerformAnalysisOperation(context); |
| 1439 } | 1436 } |
| 1440 | 1437 |
| 1441 void _computingPackageMap(bool computing) { | 1438 void _computingPackageMap(bool computing) { |
| 1442 if (analysisServer.serverServices.contains(ServerService.STATUS)) { | 1439 if (analysisServer.serverServices.contains(ServerService.STATUS)) { |
| 1443 PubStatus pubStatus = new PubStatus(computing); | 1440 PubStatus pubStatus = new PubStatus(computing); |
| 1444 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); | 1441 ServerStatusParams params = new ServerStatusParams(pub: pubStatus); |
| 1445 analysisServer.sendNotification(params.toNotification()); | 1442 analysisServer.sendNotification(params.toNotification()); |
| 1446 } | 1443 } |
| 1447 } | 1444 } |
| 1448 | 1445 |
| 1449 /** | 1446 /** |
| 1450 * Set up a [SourceFactory] that resolves packages using the given | 1447 * Set up a [SourceFactory] that resolves packages as appropriate for the |
| 1451 * [packageUriResolver] and [packages] resolution strategy. | 1448 * given [disposition]. |
| 1452 */ | 1449 */ |
| 1453 SourceFactory _createSourceFactory( | 1450 SourceFactory _createSourceFactory(FolderDisposition disposition) { |
| 1454 UriResolver packageUriResolver, Packages packages) { | |
| 1455 UriResolver dartResolver = new DartUriResolver(analysisServer.defaultSdk); | 1451 UriResolver dartResolver = new DartUriResolver(analysisServer.defaultSdk); |
| 1456 UriResolver resourceResolver = new ResourceUriResolver(resourceProvider); | 1452 UriResolver resourceResolver = new ResourceUriResolver(resourceProvider); |
| 1457 List<UriResolver> resolvers = []; | 1453 List<UriResolver> resolvers = []; |
| 1458 resolvers.add(dartResolver); | 1454 resolvers.add(dartResolver); |
| 1459 if (packageUriResolver is PackageMapUriResolver) { | 1455 resolvers.addAll(disposition.createPackageUriResolvers(resourceProvider)); |
| 1460 UriResolver sdkExtResolver = | |
| 1461 new SdkExtUriResolver(packageUriResolver.packageMap); | |
| 1462 resolvers.add(sdkExtResolver); | |
| 1463 } | |
| 1464 if (packageUriResolver != null) { | |
| 1465 resolvers.add(packageUriResolver); | |
| 1466 } | |
| 1467 resolvers.add(resourceResolver); | 1456 resolvers.add(resourceResolver); |
| 1468 return new SourceFactory(resolvers, packages); | 1457 return new SourceFactory(resolvers, disposition.packages); |
| 1469 } | 1458 } |
| 1470 } | 1459 } |
| 1471 | 1460 |
| 1472 /** | 1461 /** |
| 1473 * A class used by [AnalysisServer] to record performance information | 1462 * A class used by [AnalysisServer] to record performance information |
| 1474 * such as request latency. | 1463 * such as request latency. |
| 1475 */ | 1464 */ |
| 1476 class ServerPerformance { | 1465 class ServerPerformance { |
| 1477 | 1466 |
| 1478 /** | 1467 /** |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 /** | 1553 /** |
| 1565 * The [PerformanceTag] for time spent in server request handlers. | 1554 * The [PerformanceTag] for time spent in server request handlers. |
| 1566 */ | 1555 */ |
| 1567 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1556 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
| 1568 | 1557 |
| 1569 /** | 1558 /** |
| 1570 * The [PerformanceTag] for time spent in split store microtasks. | 1559 * The [PerformanceTag] for time spent in split store microtasks. |
| 1571 */ | 1560 */ |
| 1572 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1561 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 1573 } | 1562 } |
| OLD | NEW |