Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: pkg/analysis_server/lib/src/domain_diagnostic.dart

Issue 2625493002: Issue 28068. Implement diagnostics domain for the new analysis driver. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.src.domain_diagnostic; 5 library analysis_server.src.domain_diagnostic;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
11 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analyzer/src/context/cache.dart'; 12 import 'package:analyzer/src/context/cache.dart';
13 import 'package:analyzer/src/context/context.dart'; 13 import 'package:analyzer/src/context/context.dart';
14 import 'package:analyzer/src/dart/analysis/driver.dart' as nd;
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source.dart'; 16 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/generated/utilities_collection.dart'; 17 import 'package:analyzer/src/generated/utilities_collection.dart';
17 import 'package:analyzer/src/task/driver.dart'; 18 import 'package:analyzer/src/task/driver.dart';
18 import 'package:analyzer/task/model.dart'; 19 import 'package:analyzer/task/model.dart';
19 20
20 int _workItemCount(AnalysisContextImpl context) { 21 int _workItemCount(AnalysisContextImpl context) {
21 AnalysisDriver driver = context.driver; 22 AnalysisDriver driver = context.driver;
22 List<WorkItem> items = driver.currentWorkOrder?.workItems; 23 List<WorkItem> items = driver.currentWorkOrder?.workItems;
23 return items?.length ?? 0; 24 return items?.length ?? 0;
24 } 25 }
25 26
26 /// Instances of the class [DiagnosticDomainHandler] implement a 27 /// Instances of the class [DiagnosticDomainHandler] implement a
27 /// [RequestHandler] that handles requests in the `diagnostic` domain. 28 /// [RequestHandler] that handles requests in the `diagnostic` domain.
28 class DiagnosticDomainHandler implements RequestHandler { 29 class DiagnosticDomainHandler implements RequestHandler {
29 /// The name of the request used to get diagnostic information. 30 /// The name of the request used to get diagnostic information.
30 static const String DIAGNOSTICS = 'diagnostic.getDiagnostics'; 31 static const String DIAGNOSTICS = 'diagnostic.getDiagnostics';
31 32
32 /// The analysis server that is using this handler to process requests. 33 /// The analysis server that is using this handler to process requests.
33 final AnalysisServer server; 34 final AnalysisServer server;
34 35
35 /// Initialize a newly created handler to handle requests for the given 36 /// Initialize a newly created handler to handle requests for the given
36 /// [server]. 37 /// [server].
37 DiagnosticDomainHandler(this.server); 38 DiagnosticDomainHandler(this.server);
38 39
39 /// Answer the `diagnostic.diagnostics` request. 40 /// Answer the `diagnostic.diagnostics` request.
40 Response computeDiagnostics(Request request) { 41 Response computeDiagnostics(Request request) {
41 List<ContextData> infos = <ContextData>[]; 42 List<ContextData> contexts = <ContextData>[];
42 for (AnalysisContext context in server.analysisContexts) { 43 if (server.options.enableNewAnalysisDriver) {
43 infos.add(extractData(context)); 44 contexts = server.driverMap.values.map(extractDataFromDriver).toList();
45 } else {
46 for (AnalysisContext context in server.analysisContexts) {
47 contexts.add(extractDataFromContext(context));
48 }
44 } 49 }
45 return new DiagnosticGetDiagnosticsResult(infos).toResponse(request.id); 50 return new DiagnosticGetDiagnosticsResult(contexts).toResponse(request.id);
46 } 51 }
47 52
48 /// Extract context data from the given [context]. 53 /// Extract context data from the given [context].
49 ContextData extractData(AnalysisContext context) { 54 ContextData extractDataFromContext(AnalysisContext context) {
50 int explicitFiles = 0; 55 int explicitFiles = 0;
51 int implicitFiles = 0; 56 int implicitFiles = 0;
52 int workItems = 0; 57 int workItems = 0;
53 Set<String> exceptions = new HashSet<String>(); 58 Set<String> exceptions = new HashSet<String>();
54 if (context is AnalysisContextImpl) { 59 if (context is AnalysisContextImpl) {
55 workItems = _workItemCount(context); 60 workItems = _workItemCount(context);
56 var cache = context.analysisCache; 61 var cache = context.analysisCache;
57 if (cache is AnalysisCache) { 62 if (cache is AnalysisCache) {
58 Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>(); 63 Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>();
59 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator(); 64 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
(...skipping 17 matching lines...) Expand all
77 exceptions.add(cacheEntry.exception.toString()); 82 exceptions.add(cacheEntry.exception.toString());
78 } 83 }
79 } 84 }
80 } 85 }
81 } 86 }
82 } 87 }
83 return new ContextData(context.name, explicitFiles, implicitFiles, 88 return new ContextData(context.name, explicitFiles, implicitFiles,
84 workItems, exceptions.toList()); 89 workItems, exceptions.toList());
85 } 90 }
86 91
92 /// Extract context data from the given [driver].
93 ContextData extractDataFromDriver(nd.AnalysisDriver driver) {
94 int explicitFileCount = driver.addedFiles.length;
95 int knownFileCount = driver.knownFiles.length;
96 return new ContextData(driver.name, explicitFileCount,
97 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []);
98 }
99
87 @override 100 @override
88 Response handleRequest(Request request) { 101 Response handleRequest(Request request) {
89 try { 102 try {
90 String requestName = request.method; 103 String requestName = request.method;
91 if (requestName == DIAGNOSTICS) { 104 if (requestName == DIAGNOSTICS) {
92 return computeDiagnostics(request); 105 return computeDiagnostics(request);
93 } 106 }
94 } on RequestFailure catch (exception) { 107 } on RequestFailure catch (exception) {
95 return exception.response; 108 return exception.response;
96 } 109 }
97 return null; 110 return null;
98 } 111 }
99 } 112 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/test/domain_diagnostic_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698