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:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:core'; | 9 import 'dart:core'; |
10 | 10 |
11 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 11 import 'package:analysis_server/protocol/protocol.dart'; |
| 12 import 'package:analysis_server/protocol/protocol_generated.dart'; |
12 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
13 import 'package:analysis_server/src/constants.dart'; | 14 import 'package:analysis_server/src/constants.dart'; |
14 import 'package:analyzer/src/context/cache.dart'; | 15 import 'package:analyzer/src/context/cache.dart'; |
15 import 'package:analyzer/src/context/context.dart'; | 16 import 'package:analyzer/src/context/context.dart'; |
16 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; | 17 import 'package:analyzer/src/dart/analysis/driver.dart' as nd; |
17 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
18 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
19 import 'package:analyzer/src/generated/utilities_collection.dart'; | 20 import 'package:analyzer/src/generated/utilities_collection.dart'; |
20 import 'package:analyzer/src/task/driver.dart'; | 21 import 'package:analyzer/src/task/driver.dart'; |
21 import 'package:analyzer/task/model.dart'; | 22 import 'package:analyzer/task/model.dart'; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 90 } |
90 | 91 |
91 /// Extract context data from the given [driver]. | 92 /// Extract context data from the given [driver]. |
92 ContextData extractDataFromDriver(nd.AnalysisDriver driver) { | 93 ContextData extractDataFromDriver(nd.AnalysisDriver driver) { |
93 int explicitFileCount = driver.addedFiles.length; | 94 int explicitFileCount = driver.addedFiles.length; |
94 int knownFileCount = driver.knownFiles.length; | 95 int knownFileCount = driver.knownFiles.length; |
95 return new ContextData(driver.name, explicitFileCount, | 96 return new ContextData(driver.name, explicitFileCount, |
96 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []); | 97 knownFileCount - explicitFileCount, driver.numberOfFilesToAnalyze, []); |
97 } | 98 } |
98 | 99 |
| 100 /// Answer the `diagnostic.getServerPort` request. |
| 101 Future handleGetServerPort(Request request) async { |
| 102 try { |
| 103 // Open a port (or return the existing one). |
| 104 int port = await server.diagnosticServer.getServerPort(); |
| 105 server.sendResponse( |
| 106 new DiagnosticGetServerPortResult(port).toResponse(request.id)); |
| 107 } catch (error) { |
| 108 server |
| 109 .sendResponse(new Response.debugPortCouldNotBeOpened(request, error)); |
| 110 } |
| 111 } |
| 112 |
99 @override | 113 @override |
100 Response handleRequest(Request request) { | 114 Response handleRequest(Request request) { |
101 try { | 115 try { |
102 String requestName = request.method; | 116 String requestName = request.method; |
103 if (requestName == DIAGNOSTIC_GET_DIAGNOSTICS) { | 117 if (requestName == DIAGNOSTIC_GET_DIAGNOSTICS) { |
104 return computeDiagnostics(request); | 118 return computeDiagnostics(request); |
105 } else if (requestName == DIAGNOSTIC_GET_SERVER_PORT) { | 119 } else if (requestName == DIAGNOSTIC_GET_SERVER_PORT) { |
106 handleGetServerPort(request); | 120 handleGetServerPort(request); |
107 return Response.DELAYED_RESPONSE; | 121 return Response.DELAYED_RESPONSE; |
108 } | 122 } |
109 } on RequestFailure catch (exception) { | 123 } on RequestFailure catch (exception) { |
110 return exception.response; | 124 return exception.response; |
111 } | 125 } |
112 return null; | 126 return null; |
113 } | 127 } |
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 } | |
127 } | 128 } |
OLD | NEW |