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..0e34409e42e9208008e9f7f75920a0b28fdc443c 100644 |
--- a/pkg/analysis_server/lib/src/domain_experimental.dart |
+++ b/pkg/analysis_server/lib/src/domain_experimental.dart |
@@ -4,31 +4,82 @@ |
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 data from the given [context]. |
+ContextData extractData(AnalysisContext context) { |
+ int explicitFiles = 0; |
+ int implicitFiles = 0; |
+ int workItems = 0; |
+ Set<String> exceptions = new HashSet<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()); |
+ } |
+ } |
+ } |
+ } |
+ } |
+ return new ContextData(context.name, explicitFiles, implicitFiles, workItems, |
+ exceptions.toList()); |
+} |
+ |
+/// 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<ContextData> infos = <ContextData>[]; |
+ server.folderMap.forEach((Folder folder, AnalysisContext context) { |
+ infos.add(extractData(context)); |
+ }); |
+ |
+ return new ExperimentalGetDiagnosticsResult(infos).toResponse(request.id); |
+ } |
+ |
@override |
Response handleRequest(Request request) { |
try { |
@@ -41,11 +92,4 @@ class ExperimentalDomainHandler implements RequestHandler { |
} |
return null; |
} |
- |
- /** |
- * Implement the `experimental.diagnostics` request. |
- */ |
- Response computeDiagnostics(Request request) { |
- return new Response.unknownRequest(request); |
- } |
} |