OLD | NEW |
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:async'; |
7 import 'dart:collection'; | 8 import 'dart:collection'; |
8 import 'dart:core'; | 9 import 'dart:core'; |
9 | 10 |
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 11 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
11 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
| 13 import 'package:analysis_server/src/constants.dart'; |
12 import 'package:analyzer/src/context/cache.dart'; | 14 import 'package:analyzer/src/context/cache.dart'; |
13 import 'package:analyzer/src/context/context.dart'; | 15 import 'package:analyzer/src/context/context.dart'; |
14 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; | 16 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; |
15 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
17 import 'package:analyzer/src/generated/utilities_collection.dart'; | 19 import 'package:analyzer/src/generated/utilities_collection.dart'; |
18 import 'package:analyzer/src/task/driver.dart'; | 20 import 'package:analyzer/src/task/driver.dart'; |
19 import 'package:analyzer/task/model.dart'; | 21 import 'package:analyzer/task/model.dart'; |
20 | 22 |
21 int _workItemCount(AnalysisContextImpl context) { | 23 int _workItemCount(AnalysisContextImpl context) { |
22 AnalysisDriver driver = context.driver; | 24 AnalysisDriver driver = context.driver; |
23 List<WorkItem> items = driver.currentWorkOrder?.workItems; | 25 List<WorkItem> items = driver.currentWorkOrder?.workItems; |
24 return items?.length ?? 0; | 26 return items?.length ?? 0; |
25 } | 27 } |
26 | 28 |
27 /// Instances of the class [DiagnosticDomainHandler] implement a | 29 /// Instances of the class [DiagnosticDomainHandler] implement a |
28 /// [RequestHandler] that handles requests in the `diagnostic` domain. | 30 /// [RequestHandler] that handles requests in the `diagnostic` domain. |
29 class DiagnosticDomainHandler implements RequestHandler { | 31 class DiagnosticDomainHandler implements RequestHandler { |
30 /// The name of the request used to get diagnostic information. | |
31 static const String DIAGNOSTICS = 'diagnostic.getDiagnostics'; | |
32 | |
33 /// The analysis server that is using this handler to process requests. | 32 /// The analysis server that is using this handler to process requests. |
34 final AnalysisServer server; | 33 final AnalysisServer server; |
35 | 34 |
36 /// Initialize a newly created handler to handle requests for the given | 35 /// Initialize a newly created handler to handle requests for the given |
37 /// [server]. | 36 /// [server]. |
38 DiagnosticDomainHandler(this.server); | 37 DiagnosticDomainHandler(this.server); |
39 | 38 |
40 /// Answer the `diagnostic.diagnostics` request. | 39 /// Answer the `diagnostic.getDiagnostics` request. |
41 Response computeDiagnostics(Request request) { | 40 Response computeDiagnostics(Request request) { |
42 List<ContextData> contexts = <ContextData>[]; | 41 List<ContextData> contexts = <ContextData>[]; |
43 if (server.options.enableNewAnalysisDriver) { | 42 if (server.options.enableNewAnalysisDriver) { |
44 contexts = server.driverMap.values.map(extractDataFromDriver).toList(); | 43 contexts = server.driverMap.values.map(extractDataFromDriver).toList(); |
45 } else { | 44 } else { |
46 for (AnalysisContext context in server.analysisContexts) { | 45 for (AnalysisContext context in server.analysisContexts) { |
47 contexts.add(extractDataFromContext(context)); | 46 contexts.add(extractDataFromContext(context)); |
48 } | 47 } |
49 } | 48 } |
50 return new DiagnosticGetDiagnosticsResult(contexts).toResponse(request.id); | 49 return new DiagnosticGetDiagnosticsResult(contexts).toResponse(request.id); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 int explicitFileCount = driver.addedFiles.length; | 93 int explicitFileCount = driver.addedFiles.length; |
95 int knownFileCount = driver.knownFiles.length; | 94 int knownFileCount = driver.knownFiles.length; |
96 return new ContextData(driver.name, explicitFileCount, | 95 return new ContextData(driver.name, explicitFileCount, |
97 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []); | 96 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []); |
98 } | 97 } |
99 | 98 |
100 @override | 99 @override |
101 Response handleRequest(Request request) { | 100 Response handleRequest(Request request) { |
102 try { | 101 try { |
103 String requestName = request.method; | 102 String requestName = request.method; |
104 if (requestName == DIAGNOSTICS) { | 103 if (requestName == DIAGNOSTIC_GET_DIAGNOSTICS) { |
105 return computeDiagnostics(request); | 104 return computeDiagnostics(request); |
| 105 } else if (requestName == DIAGNOSTIC_GET_SERVER_PORT) { |
| 106 handleGetServerPort(request); |
| 107 return Response.DELAYED_RESPONSE; |
106 } | 108 } |
107 } on RequestFailure catch (exception) { | 109 } on RequestFailure catch (exception) { |
108 return exception.response; | 110 return exception.response; |
109 } | 111 } |
110 return null; | 112 return null; |
111 } | 113 } |
| 114 |
| 115 /// Answer the `diagnostic.getServerPort` request. |
| 116 Future handleGetServerPort(Request request) async { |
| 117 try { |
| 118 // Open a port (or return the existing one). |
| 119 int port = await server.diagnosticServer.getServerPort(); |
| 120 server.sendResponse( |
| 121 new DiagnosticGetServerPortResult(port).toResponse(request.id)); |
| 122 } catch (error) { |
| 123 server |
| 124 .sendResponse(new Response.debugPortCouldNotBeOpened(request, error)); |
| 125 } |
| 126 } |
112 } | 127 } |
OLD | NEW |