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

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: Removed debug out. 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
13 * Instances of the class [ExperimentalDomainHandler] implement a 23 /// Extract context info from the given [context].
14 * [RequestHandler] that handles requests in the `experimental` domain. 24 ContextInfo extractInfo(AnalysisContext context) {
15 */ 25 int explicitFiles = 0;
26 int implicitFiles = 0;
27 int workItems = 0;
28 List<String> exceptions = <String>[];
29 if (context is AnalysisContextImpl) {
30 // Work Item count.
31 AnalysisDriver driver = context.driver;
32 List<WorkItem> items = driver.currentWorkOrder?.workItems;
33 workItems ??= items?.length;
34 var cache = context.analysisCache;
35 if (cache is AnalysisCache) {
36 Set<AnalysisTarget> countedTargets = new HashSet<AnalysisTarget>();
37 MapIterator<AnalysisTarget, CacheEntry> iterator = cache.iterator();
38 while (iterator.moveNext()) {
39 AnalysisTarget target = iterator.key;
40 if (countedTargets.add(target)) {
41 CacheEntry cacheEntry = iterator.value;
42 if (target is Source) {
43 if (cacheEntry.explicitlyAdded) {
44 explicitFiles++;
45 } else {
46 implicitFiles++;
47 }
48 }
49 // Caught exceptions.
50 if (cacheEntry.exception != null) {
51 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.
52 }
53 }
54 }
55 }
56 }
57 return new ContextInfo(
58 context.name, explicitFiles, implicitFiles, workItems, exceptions);
59 }
60
61 /// Instances of the class [ExperimentalDomainHandler] implement a
62 /// [RequestHandler] that handles requests in the `experimental` domain.
16 class ExperimentalDomainHandler implements RequestHandler { 63 class ExperimentalDomainHandler implements RequestHandler {
17 /** 64 /// The name of the request used to get diagnostic information.
18 * The analysis server that is using this handler to process requests. 65 static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.getDiagnostics';
19 */ 66
67 /// The analysis server that is using this handler to process requests.
20 final AnalysisServer server; 68 final AnalysisServer server;
21 69
22 /** 70 /// Initialize a newly created handler to handle requests for the given
23 * The name of the request used to get diagnostic information. 71 /// [server].
24 */ 72 ExperimentalDomainHandler(this.server);
25 static const String EXPERIMENTAL_DIAGNOSTICS = 'experimental.diagnostics';
26 73
27 /** 74 /// Answer the `experimental.diagnostics` request.
28 * Initialize a newly created handler to handle requests for the given [server ]. 75 Response computeDiagnostics(Request request) {
29 */ 76 List<ContextInfo> infos = <ContextInfo>[];
30 ExperimentalDomainHandler(this.server); 77 server.folderMap.forEach((Folder folder, AnalysisContext context) {
78 infos.add(extractInfo(context));
79 });
80
81 return new ExperimentalGetDiagnosticsResult(infos).toResponse(request.id);
82 }
31 83
32 @override 84 @override
33 Response handleRequest(Request request) { 85 Response handleRequest(Request request) {
34 try { 86 try {
35 String requestName = request.method; 87 String requestName = request.method;
36 if (requestName == EXPERIMENTAL_DIAGNOSTICS) { 88 if (requestName == EXPERIMENTAL_DIAGNOSTICS) {
37 return computeDiagnostics(request); 89 return computeDiagnostics(request);
38 } 90 }
39 } on RequestFailure catch (exception) { 91 } on RequestFailure catch (exception) {
40 return exception.response; 92 return exception.response;
41 } 93 }
42 return null; 94 return null;
43 } 95 }
44
45 /**
46 * Implement the `experimental.diagnostics` request.
47 */
48 Response computeDiagnostics(Request request) {
49 return new Response.unknownRequest(request);
50 }
51 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698