OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.status.get_handler; | 5 library analysis_server.src.status.get_handler; |
6 | 6 |
7 import 'dart:async'; | |
8 import 'dart:collection'; | 7 import 'dart:collection'; |
9 import 'dart:convert'; | 8 import 'dart:convert'; |
10 import 'dart:io'; | 9 import 'dart:io'; |
11 import 'dart:math'; | 10 import 'dart:math'; |
12 | 11 |
13 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; | 12 import 'package:analysis_server/plugin/protocol/protocol.dart' hide Element; |
14 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
15 import 'package:analysis_server/src/domain_completion.dart'; | 14 import 'package:analysis_server/src/domain_completion.dart'; |
16 import 'package:analysis_server/src/domain_diagnostic.dart'; | 15 import 'package:analysis_server/src/domain_diagnostic.dart'; |
17 import 'package:analysis_server/src/domain_execution.dart'; | 16 import 'package:analysis_server/src/domain_execution.dart'; |
18 import 'package:analysis_server/src/operation/operation.dart'; | 17 import 'package:analysis_server/src/operation/operation.dart'; |
19 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 18 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
20 import 'package:analysis_server/src/operation/operation_queue.dart'; | 19 import 'package:analysis_server/src/operation/operation_queue.dart'; |
21 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 20 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
22 import 'package:analysis_server/src/services/index/index.dart'; | |
23 import 'package:analysis_server/src/services/index/local_index.dart'; | |
24 import 'package:analysis_server/src/services/index/store/split_store.dart'; | |
25 import 'package:analysis_server/src/socket_server.dart'; | 21 import 'package:analysis_server/src/socket_server.dart'; |
26 import 'package:analysis_server/src/status/ast_writer.dart'; | 22 import 'package:analysis_server/src/status/ast_writer.dart'; |
27 import 'package:analysis_server/src/status/element_writer.dart'; | 23 import 'package:analysis_server/src/status/element_writer.dart'; |
28 import 'package:analysis_server/src/status/validator.dart'; | 24 import 'package:analysis_server/src/status/validator.dart'; |
29 import 'package:analysis_server/src/utilities/average.dart'; | 25 import 'package:analysis_server/src/utilities/average.dart'; |
30 import 'package:analyzer/dart/ast/ast.dart'; | 26 import 'package:analyzer/dart/ast/ast.dart'; |
31 import 'package:analyzer/dart/element/element.dart'; | 27 import 'package:analyzer/dart/element/element.dart'; |
32 import 'package:analyzer/dart/element/visitor.dart'; | 28 import 'package:analyzer/dart/element/visitor.dart'; |
33 import 'package:analyzer/file_system/file_system.dart'; | 29 import 'package:analyzer/file_system/file_system.dart'; |
34 import 'package:analyzer/source/error_processor.dart'; | 30 import 'package:analyzer/source/error_processor.dart'; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 * The path used to request diagnostic information. | 247 * The path used to request diagnostic information. |
252 */ | 248 */ |
253 static const String DIAGNOSTIC_PATH = '/diagnostic'; | 249 static const String DIAGNOSTIC_PATH = '/diagnostic'; |
254 | 250 |
255 /** | 251 /** |
256 * The path used to request information about a element model. | 252 * The path used to request information about a element model. |
257 */ | 253 */ |
258 static const String ELEMENT_PATH = '/element'; | 254 static const String ELEMENT_PATH = '/element'; |
259 | 255 |
260 /** | 256 /** |
261 * The path used to request information about elements with the given name. | |
262 */ | |
263 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name'; | |
264 | |
265 /** | |
266 * The path used to request an overlay contents. | 257 * The path used to request an overlay contents. |
267 */ | 258 */ |
268 static const String OVERLAY_PATH = '/overlay'; | 259 static const String OVERLAY_PATH = '/overlay'; |
269 | 260 |
270 /** | 261 /** |
271 * The path used to request overlays information. | 262 * The path used to request overlays information. |
272 */ | 263 */ |
273 static const String OVERLAYS_PATH = '/overlays'; | 264 static const String OVERLAYS_PATH = '/overlays'; |
274 | 265 |
275 /** | 266 /** |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } else if (path == CONTEXT_DIAGNOSTICS_PATH) { | 379 } else if (path == CONTEXT_DIAGNOSTICS_PATH) { |
389 _returnContextDiagnostics(request); | 380 _returnContextDiagnostics(request); |
390 } else if (path == CONTEXT_VALIDATION_DIAGNOSTICS_PATH) { | 381 } else if (path == CONTEXT_VALIDATION_DIAGNOSTICS_PATH) { |
391 _returnContextValidationDiagnostics(request); | 382 _returnContextValidationDiagnostics(request); |
392 } else if (path == CONTEXT_PATH) { | 383 } else if (path == CONTEXT_PATH) { |
393 _returnContextInfo(request); | 384 _returnContextInfo(request); |
394 } else if (path == DIAGNOSTIC_PATH) { | 385 } else if (path == DIAGNOSTIC_PATH) { |
395 _returnDiagnosticInfo(request); | 386 _returnDiagnosticInfo(request); |
396 } else if (path == ELEMENT_PATH) { | 387 } else if (path == ELEMENT_PATH) { |
397 _returnElement(request); | 388 _returnElement(request); |
398 } else if (path == INDEX_ELEMENT_BY_NAME) { | |
399 _returnIndexElementByName(request); | |
400 } else if (path == OVERLAY_PATH) { | 389 } else if (path == OVERLAY_PATH) { |
401 _returnOverlayContents(request); | 390 _returnOverlayContents(request); |
402 } else if (path == OVERLAYS_PATH) { | 391 } else if (path == OVERLAYS_PATH) { |
403 _returnOverlaysInfo(request); | 392 _returnOverlaysInfo(request); |
404 } else { | 393 } else { |
405 _returnUnknownRequest(request); | 394 _returnUnknownRequest(request); |
406 } | 395 } |
407 } | 396 } |
408 | 397 |
409 /** | 398 /** |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 | 1488 |
1500 void _returnFailure(HttpRequest request, String message) { | 1489 void _returnFailure(HttpRequest request, String message) { |
1501 _writeResponse(request, (StringBuffer buffer) { | 1490 _writeResponse(request, (StringBuffer buffer) { |
1502 _writePage(buffer, 'Analysis Server - Failure', [], | 1491 _writePage(buffer, 'Analysis Server - Failure', [], |
1503 (StringBuffer buffer) { | 1492 (StringBuffer buffer) { |
1504 buffer.write(HTML_ESCAPE.convert(message)); | 1493 buffer.write(HTML_ESCAPE.convert(message)); |
1505 }); | 1494 }); |
1506 }); | 1495 }); |
1507 } | 1496 } |
1508 | 1497 |
1509 /** | |
1510 * Return a response containing information about elements with the given | |
1511 * name. | |
1512 */ | |
1513 Future _returnIndexElementByName(HttpRequest request) async { | |
1514 AnalysisServer analysisServer = _server.analysisServer; | |
1515 if (analysisServer == null) { | |
1516 return _returnFailure(request, 'Analysis server not running'); | |
1517 } | |
1518 Index index = analysisServer.index; | |
1519 if (index == null) { | |
1520 return _returnFailure(request, 'Indexing is disabled'); | |
1521 } | |
1522 String name = request.uri.queryParameters[INDEX_ELEMENT_NAME]; | |
1523 if (name == null) { | |
1524 return _returnFailure( | |
1525 request, 'Query parameter $INDEX_ELEMENT_NAME required'); | |
1526 } | |
1527 if (index is LocalIndex) { | |
1528 Map<List<String>, List<InspectLocation>> relations = | |
1529 await index.findElementsByName(name); | |
1530 _writeResponse(request, (StringBuffer buffer) { | |
1531 _writePage(buffer, 'Analysis Server - Index Elements', ['Name: $name'], | |
1532 (StringBuffer buffer) { | |
1533 buffer.write('<table border="1">'); | |
1534 _writeRow(buffer, ['Element', 'Relationship', 'Location'], | |
1535 header: true); | |
1536 relations.forEach( | |
1537 (List<String> elementPath, List<InspectLocation> relations) { | |
1538 String elementLocation = elementPath.join(' '); | |
1539 relations.forEach((InspectLocation location) { | |
1540 var relString = location.relationship.identifier; | |
1541 var locString = '${location.path} offset=${location.offset} ' | |
1542 'length=${location.length} flags=${location.flags}'; | |
1543 _writeRow(buffer, [elementLocation, relString, locString]); | |
1544 }); | |
1545 }); | |
1546 buffer.write('</table>'); | |
1547 }); | |
1548 }); | |
1549 } else { | |
1550 return _returnFailure(request, 'LocalIndex expected, but $index found.'); | |
1551 } | |
1552 } | |
1553 | |
1554 void _returnOverlayContents(HttpRequest request) { | 1498 void _returnOverlayContents(HttpRequest request) { |
1555 String path = request.requestedUri.queryParameters[PATH_PARAM]; | 1499 String path = request.requestedUri.queryParameters[PATH_PARAM]; |
1556 if (path == null) { | 1500 if (path == null) { |
1557 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); | 1501 return _returnFailure(request, 'Query parameter $PATH_PARAM required'); |
1558 } | 1502 } |
1559 String contents = _overlayContents[path]; | 1503 String contents = _overlayContents[path]; |
1560 | 1504 |
1561 _writeResponse(request, (StringBuffer buffer) { | 1505 _writeResponse(request, (StringBuffer buffer) { |
1562 _writePage(buffer, 'Analysis Server - Overlay', [], | 1506 _writePage(buffer, 'Analysis Server - Overlay', [], |
1563 (StringBuffer buffer) { | 1507 (StringBuffer buffer) { |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 */ | 2427 */ |
2484 static String makeLink( | 2428 static String makeLink( |
2485 String path, Map<String, String> params, String innerHtml, | 2429 String path, Map<String, String> params, String innerHtml, |
2486 [bool hasError = false]) { | 2430 [bool hasError = false]) { |
2487 Uri uri = new Uri(path: path, queryParameters: params); | 2431 Uri uri = new Uri(path: path, queryParameters: params); |
2488 String href = HTML_ESCAPE.convert(uri.toString()); | 2432 String href = HTML_ESCAPE.convert(uri.toString()); |
2489 String classAttribute = hasError ? ' class="error"' : ''; | 2433 String classAttribute = hasError ? ' class="error"' : ''; |
2490 return '<a href="$href"$classAttribute>$innerHtml</a>'; | 2434 return '<a href="$href"$classAttribute>$innerHtml</a>'; |
2491 } | 2435 } |
2492 } | 2436 } |
OLD | NEW |