Chromium Code Reviews| Index: pkg/analysis_server/lib/src/domain_experimental.dart |
| diff --git a/pkg/analysis_server/lib/src/domain_experimental.dart b/pkg/analysis_server/lib/src/domain_experimental.dart |
| index 43631f2481795ce2a1a53c8dc33925c139f8e83b..b30495e02102e059509913bcc59fbd8662b43bff 100644 |
| --- a/pkg/analysis_server/lib/src/domain_experimental.dart |
| +++ b/pkg/analysis_server/lib/src/domain_experimental.dart |
| @@ -4,31 +4,83 @@ |
| library src.domain_experimental; |
| +import 'dart:collection'; |
| import 'dart:core' hide Resource; |
| import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| import 'package:analysis_server/src/analysis_server.dart'; |
| +import 'package:analyzer/file_system/file_system.dart'; |
| +import 'package:analyzer/src/context/cache.dart'; |
| +import 'package:analyzer/src/context/context.dart'; |
| +import 'package:analyzer/src/generated/engine.dart' |
| + hide AnalysisCache, AnalysisContextImpl; |
| +import 'package:analyzer/src/generated/source.dart'; |
| +import 'package:analyzer/src/generated/utilities_collection.dart'; |
| +import 'package:analyzer/src/task/driver.dart'; |
| +import 'package:analyzer/task/model.dart'; |
| -/** |
| - * Instances of the class [ExperimentalDomainHandler] implement a |
| - * [RequestHandler] that handles requests in the `experimental` domain. |
| - */ |
| + |
| +/// Extract context info from the given [context]. |
| +ContextInfo extractInfo(AnalysisContext context) { |
| + int explicitFiles = 0; |
| + int implicitFiles = 0; |
| + int workItems = 0; |
| + List<String> exceptions = <String>[]; |
| + if (context is AnalysisContextImpl) { |
| + // Work Item count. |
| + AnalysisDriver driver = context.driver; |
| + List<WorkItem> items = driver.currentWorkOrder?.workItems; |
| + workItems ??= items?.length; |
| + var cache = context.analysisCache; |
| + if (cache is AnalysisCache) { |
| + Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>(); |
| + MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); |
| + while (iterator.moveNext()) { |
| + AnalysisTarget target = iterator.key; |
| + if (countedTargets.add(target)) { |
| + CacheEntry cacheEntry = iterator.value; |
| + if (target is Source) { |
| + if (cacheEntry.explicitlyAdded) { |
| + explicitFiles++; |
| + } else { |
| + implicitFiles++; |
| + } |
| + } |
| + // Caught exceptions. |
| + if (cacheEntry.exception != null) { |
| + exceptions.add(cacheEntry.exception.toString()); |
|
Brian Wilkerson
2015/11/05 22:43:43
Each exception will typically be recorded in multi
pquitslund
2015/11/05 22:58:11
Good catch. Done.
|
| + } |
| + } |
| + } |
| + } |
| + } |
| + return new ContextInfo( |
| + context.name, explicitFiles, implicitFiles, workItems, exceptions); |
| +} |
| + |
| +/// Instances of the class [ExperimentalDomainHandler] implement a |
| +/// [RequestHandler] that handles requests in the `experimental` domain. |
| class ExperimentalDomainHandler implements RequestHandler { |
| - /** |
| - * The analysis server that is using this handler to process requests. |
| - */ |
| - final AnalysisServer server; |
| + /// The name of the request used to get diagnostic information. |
| + static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.getDiagnostics'; |
| - /** |
| - * The name of the request used to get diagnostic information. |
| - */ |
| - static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.diagnostics'; |
| + /// The analysis server that is using this handler to process requests. |
| + final AnalysisServer server; |
| - /** |
| - * Initialize a newly created handler to handle requests for the given [server]. |
| - */ |
| + /// Initialize a newly created handler to handle requests for the given |
| + /// [server]. |
| ExperimentalDomainHandler(this.server); |
| + /// Answer the `experimental.diagnostics` request. |
| + Response computeDiagnostics(Request request) { |
| + List<ContextInfo> infos = <ContextInfo>[]; |
| + server.folderMap.forEach((Folder folder, AnalysisContext context) { |
| + infos.add(extractInfo(context)); |
| + }); |
| + |
| + return new ExperimentalGetDiagnosticsResult(infos).toResponse(request.id); |
| + } |
| + |
| @override |
| Response handleRequest(Request request) { |
| try { |
| @@ -41,11 +93,4 @@ class ExperimentalDomainHandler implements RequestHandler { |
| } |
| return null; |
| } |
| - |
| - /** |
| - * Implement the `experimental.diagnostics` request. |
| - */ |
| - Response computeDiagnostics(Request request) { |
| - return new Response.unknownRequest(request); |
| - } |
| } |