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

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

Issue 1416093007: Experimental `getDiagnostics` request (#24480). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Review fixes. Created 5 years, 1 month 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 src.domain_experimental; 5 library src.domain_experimental;
6 6
7 import 'dart:collection';
7 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
8 9
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analyzer/file_system/file_system.dart';
13 import 'package:analyzer/src/context/cache.dart';
14 import 'package:analyzer/src/context/context.dart';
15 import 'package:analyzer/src/generated/engine.dart'
16 hide AnalysisCache, AnalysisContextImpl;
17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:analyzer/src/generated/utilities_collection.dart';
19 import 'package:analyzer/src/task/driver.dart';
20 import 'package:analyzer/task/model.dart';
11 21
12 /** 22 /// Extract context data from the given [context].
13 * Instances of the class [ExperimentalDomainHandler] implement a 23 ContextData extractData(AnalysisContext context) {
14 * [RequestHandler] that handles requests in the `experimental` domain. 24 int explicitFiles = 0;
15 */ 25 int implicitFiles = 0;
26 int workItems = 0;
27 Set<String> exceptions = new HashSet<String>();
28 if (context is AnalysisContextImpl) {
29 // Work Item count.
30 AnalysisDriver driver = context.driver;
31 List<WorkItem> items = driver.currentWorkOrder?.workItems;
32 workItems ??= items?.length;
33 var cache = context.analysisCache;
34 if (cache is AnalysisCache) {
35 Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>();
36 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
37 while (iterator.moveNext()) {
38 AnalysisTarget target = iterator.key;
39 if (countedTargets.add(target)) {
40 CacheEntry cacheEntry = iterator.value;
41 if (target is Source) {
42 if (cacheEntry.explicitlyAdded) {
43 explicitFiles++;
44 } else {
45 implicitFiles++;
46 }
47 }
48 // Caught exceptions.
49 if (cacheEntry.exception != null) {
50 exceptions.add(cacheEntry.exception.toString());
51 }
52 }
53 }
54 }
55 }
56 return new ContextData(context.name, explicitFiles, implicitFiles, workItems,
57 exceptions.toList());
58 }
59
60 /// Instances of the class [ExperimentalDomainHandler] implement a
61 /// [RequestHandler] that handles requests in the `experimental` domain.
16 class ExperimentalDomainHandler implements RequestHandler { 62 class ExperimentalDomainHandler implements RequestHandler {
17 /** 63 /// The name of the request used to get diagnostic information.
18 * The analysis server that is using this handler to process requests. 64 static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.getDiagnostics';
19 */ 65
66 /// The analysis server that is using this handler to process requests.
20 final AnalysisServer server; 67 final AnalysisServer server;
21 68
22 /** 69 /// Initialize a newly created handler to handle requests for the given
23 * The name of the request used to get diagnostic information. 70 /// [server].
24 */ 71 ExperimentalDomainHandler(this.server);
25 static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.diagnostics';
26 72
27 /** 73 /// Answer the `experimental.diagnostics` request.
28 * Initialize a newly created handler to handle requests for the given [server ]. 74 Response computeDiagnostics(Request request) {
29 */ 75 List<ContextData> infos = <ContextData>[];
30 ExperimentalDomainHandler(this.server); 76 server.folderMap.forEach((Folder folder, AnalysisContext context) {
77 infos.add(extractData(context));
78 });
79
80 return new ExperimentalGetDiagnosticsResult(infos).toResponse(request.id);
81 }
31 82
32 @override 83 @override
33 Response handleRequest(Request request) { 84 Response handleRequest(Request request) {
34 try { 85 try {
35 String requestName = request.method; 86 String requestName = request.method;
36 if (requestName == EXPERIMENTAL_DIAGNOSTICS) { 87 if (requestName == EXPERIMENTAL_DIAGNOSTICS) {
37 return computeDiagnostics(request); 88 return computeDiagnostics(request);
38 } 89 }
39 } on RequestFailure catch (exception) { 90 } on RequestFailure catch (exception) {
40 return exception.response; 91 return exception.response;
41 } 92 }
42 return null; 93 return null;
43 } 94 }
44
45 /**
46 * Implement the `experimental.diagnostics` request.
47 */
48 Response computeDiagnostics(Request request) {
49 return new Response.unknownRequest(request);
50 }
51 } 95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698