| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:convert'; | 5 import 'dart:convert'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
| 10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| 11 import 'package:analysis_server/src/domain_completion.dart'; | 11 import 'package:analysis_server/src/domain_completion.dart'; |
| 12 import 'package:analysis_server/src/domain_diagnostic.dart'; | 12 import 'package:analysis_server/src/domain_diagnostic.dart'; |
| 13 import 'package:analysis_server/src/domain_execution.dart'; | 13 import 'package:analysis_server/src/domain_execution.dart'; |
| 14 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 14 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
| 15 import 'package:analysis_server/src/socket_server.dart'; | 15 import 'package:analysis_server/src/socket_server.dart'; |
| 16 import 'package:analysis_server/src/status/get_handler.dart'; | 16 import 'package:analysis_server/src/status/get_handler.dart'; |
| 17 import 'package:analyzer/exception/exception.dart'; | 17 import 'package:analyzer/exception/exception.dart'; |
| 18 import 'package:analyzer/file_system/file_system.dart'; | 18 import 'package:analyzer/file_system/file_system.dart'; |
| 19 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 19 import 'package:analyzer/source/error_processor.dart'; | 20 import 'package:analyzer/source/error_processor.dart'; |
| 20 import 'package:analyzer/source/sdk_ext.dart'; | 21 import 'package:analyzer/source/sdk_ext.dart'; |
| 21 import 'package:analyzer/src/context/source.dart'; | 22 import 'package:analyzer/src/context/source.dart'; |
| 22 import 'package:analyzer/src/dart/analysis/driver.dart'; | 23 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 23 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 24 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 24 import 'package:analyzer/src/generated/engine.dart'; | 25 import 'package:analyzer/src/generated/engine.dart'; |
| 25 import 'package:analyzer/src/generated/sdk.dart'; | 26 import 'package:analyzer/src/generated/sdk.dart'; |
| 26 import 'package:analyzer/src/generated/source.dart'; | 27 import 'package:analyzer/src/generated/source.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_general.dart'; | 28 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 28 import 'package:analyzer/src/services/lint.dart'; | 29 import 'package:analyzer/src/services/lint.dart'; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 134 } |
| 134 return analysisServer.handlers | 135 return analysisServer.handlers |
| 135 .firstWhere((h) => h is CompletionDomainHandler, orElse: () => null); | 136 .firstWhere((h) => h is CompletionDomainHandler, orElse: () => null); |
| 136 } | 137 } |
| 137 | 138 |
| 138 /** | 139 /** |
| 139 * Handle a GET request received by the HTTP server. | 140 * Handle a GET request received by the HTTP server. |
| 140 */ | 141 */ |
| 141 void handleGetRequest(HttpRequest request) { | 142 void handleGetRequest(HttpRequest request) { |
| 142 String path = request.uri.path; | 143 String path = request.uri.path; |
| 143 if (path == '/' || path == STATUS_PATH) { | 144 if (path == '/') { |
| 145 _returnRedirect(request, STATUS_PATH); |
| 146 } else if (path == STATUS_PATH) { |
| 144 _returnServerStatus(request); | 147 _returnServerStatus(request); |
| 145 } else if (path == ANALYSIS_PERFORMANCE_PATH) { | 148 } else if (path == ANALYSIS_PERFORMANCE_PATH) { |
| 146 _returnAnalysisPerformance(request); | 149 _returnAnalysisPerformance(request); |
| 147 } else if (path == COMPLETION_PATH) { | 150 } else if (path == COMPLETION_PATH) { |
| 148 _returnCompletionInfo(request); | 151 _returnCompletionInfo(request); |
| 149 } else if (path == COMMUNICATION_PERFORMANCE_PATH) { | 152 } else if (path == COMMUNICATION_PERFORMANCE_PATH) { |
| 150 _returnCommunicationPerformance(request); | 153 _returnCommunicationPerformance(request); |
| 151 } else if (path == CONTEXT_PATH) { | 154 } else if (path == CONTEXT_PATH) { |
| 152 _returnContextInfo(request); | 155 _returnContextInfo(request); |
| 153 } else if (path == OVERLAY_PATH) { | 156 } else if (path == OVERLAY_PATH) { |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 _writeAnalysisStatus(buffer); | 600 _writeAnalysisStatus(buffer); |
| 598 _writeEditStatus(buffer); | 601 _writeEditStatus(buffer); |
| 599 _writeExecutionStatus(buffer); | 602 _writeExecutionStatus(buffer); |
| 600 _writePluginStatus(buffer); | 603 _writePluginStatus(buffer); |
| 601 _writeRecentOutput(buffer); | 604 _writeRecentOutput(buffer); |
| 602 } | 605 } |
| 603 }); | 606 }); |
| 604 }); | 607 }); |
| 605 } | 608 } |
| 606 | 609 |
| 610 void _returnRedirect(HttpRequest request, String pathFragment) { |
| 611 HttpResponse response = request.response; |
| 612 response.redirect(request.uri.resolve(pathFragment)); |
| 613 } |
| 614 |
| 607 /** | 615 /** |
| 608 * Return an error in response to an unrecognized request received by the HTTP | 616 * Return an error in response to an unrecognized request received by the HTTP |
| 609 * server. | 617 * server. |
| 610 */ | 618 */ |
| 611 void _returnUnknownRequest(HttpRequest request) { | 619 void _returnUnknownRequest(HttpRequest request) { |
| 612 _writeResponse(request, (StringBuffer buffer) { | 620 _writeResponse(request, (StringBuffer buffer) { |
| 613 _writePage(buffer, 'Analysis Server', [], (StringBuffer buffer) { | 621 _writePage(buffer, 'Analysis Server', [], (StringBuffer buffer) { |
| 614 buffer.write('<h3>Unknown page: '); | 622 buffer.write('<h3>Unknown page: '); |
| 615 buffer.write(request.uri.path); | 623 buffer.write(request.uri.path); |
| 616 buffer.write('</h3>'); | 624 buffer.write('</h3>'); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1083 if (analysisServer == null) { | 1091 if (analysisServer == null) { |
| 1084 buffer.write('Status: <span style="color:red">Not running</span>'); | 1092 buffer.write('Status: <span style="color:red">Not running</span>'); |
| 1085 return; | 1093 return; |
| 1086 } | 1094 } |
| 1087 buffer.write('Status: Running<br>'); | 1095 buffer.write('Status: Running<br>'); |
| 1088 buffer.write('New analysis driver: '); | 1096 buffer.write('New analysis driver: '); |
| 1089 buffer.write(analysisServer.options.enableNewAnalysisDriver); | 1097 buffer.write(analysisServer.options.enableNewAnalysisDriver); |
| 1090 buffer.write('<br>'); | 1098 buffer.write('<br>'); |
| 1091 buffer.write('Instrumentation: '); | 1099 buffer.write('Instrumentation: '); |
| 1092 if (AnalysisEngine.instance.instrumentationService.isActive) { | 1100 if (AnalysisEngine.instance.instrumentationService.isActive) { |
| 1093 buffer.write('<span style="color:red">Active</span>'); | 1101 buffer.write('<strong>active</strong>'); |
| 1094 } else { | 1102 } else { |
| 1095 buffer.write('Inactive'); | 1103 buffer.write('inactive'); |
| 1096 } | 1104 } |
| 1097 buffer.write('<br>'); | 1105 buffer.write('<br>'); |
| 1098 buffer.write('Process ID: '); | 1106 buffer.write('Process ID: '); |
| 1099 buffer.write(pid); | 1107 buffer.write(pid); |
| 1100 | 1108 |
| 1101 buffer.write('<p><b>Performance Data</b></p>'); | 1109 buffer.write('<p><b>Performance Data</b></p>'); |
| 1102 buffer.write(makeLink( | 1110 buffer.write(makeLink( |
| 1103 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance')); | 1111 COMMUNICATION_PERFORMANCE_PATH, {}, 'Communication performance')); |
| 1112 |
| 1113 if (AnalysisEngine.instance.instrumentationService.isActive) { |
| 1114 buffer.write('<p><b>Instrumentation</b></p>'); |
| 1115 InstrumentationServer instrumentationServer = AnalysisEngine |
| 1116 .instance.instrumentationService.instrumentationServer; |
| 1117 String description = instrumentationServer.describe; |
| 1118 HtmlEscape htmlEscape = new HtmlEscape(HtmlEscapeMode.ELEMENT); |
| 1119 description = htmlEscape.convert(description); |
| 1120 // Convert http(s): references to hyperlinks. |
| 1121 final RegExp urlRegExp = new RegExp(r'[http|https]+:\/*(\S+)'); |
| 1122 description = description.replaceAllMapped(urlRegExp, (Match match) { |
| 1123 return '<a href="${match.group(0)}">${match.group(1)}</a>'; |
| 1124 }); |
| 1125 buffer.write(description.replaceAll('\n', '<br>')); |
| 1126 } |
| 1104 }, (StringBuffer buffer) { | 1127 }, (StringBuffer buffer) { |
| 1105 _writeSubscriptionList(buffer, ServerService.VALUES, services); | 1128 _writeSubscriptionList(buffer, ServerService.VALUES, services); |
| 1106 buffer.write('<p><b>Versions</b></p>'); | 1129 buffer.write('<p><b>Versions</b></p>'); |
| 1107 buffer.write('Dart SDK: ${Platform.version}<br>'); | 1130 buffer.write('Dart SDK: ${Platform.version}<br>'); |
| 1108 buffer.write('Analysis server version: ${AnalysisServer.VERSION}<br>'); | 1131 buffer.write('Analysis server version: ${AnalysisServer.VERSION}<br>'); |
| 1109 }); | 1132 }); |
| 1110 return analysisServer != null; | 1133 return analysisServer != null; |
| 1111 } | 1134 } |
| 1112 | 1135 |
| 1113 /** | 1136 /** |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 // TODO(devoncarew): Replace with the implementation from package:intl. | 1249 // TODO(devoncarew): Replace with the implementation from package:intl. |
| 1227 String str = value.toString(); | 1250 String str = value.toString(); |
| 1228 int pos = 3; | 1251 int pos = 3; |
| 1229 while (str.length > pos) { | 1252 while (str.length > pos) { |
| 1230 int len = str.length; | 1253 int len = str.length; |
| 1231 str = '${str.substring(0, len - pos)},${str.substring(len - pos)}'; | 1254 str = '${str.substring(0, len - pos)},${str.substring(len - pos)}'; |
| 1232 pos += 4; | 1255 pos += 4; |
| 1233 } | 1256 } |
| 1234 return str; | 1257 return str; |
| 1235 } | 1258 } |
| OLD | NEW |