Chromium Code Reviews| 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.get_handler; | 5 library analysis_server.src.get_handler; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 7 import 'dart:collection'; | 8 import 'dart:collection'; |
| 8 import 'dart:convert'; | 9 import 'dart:convert'; |
| 9 import 'dart:io'; | 10 import 'dart:io'; |
| 10 import 'dart:math'; | 11 import 'dart:math'; |
| 11 | 12 |
| 12 import 'package:analysis_server/src/analysis_server.dart'; | 13 import 'package:analysis_server/src/analysis_server.dart'; |
| 13 import 'package:analysis_server/src/domain_completion.dart'; | 14 import 'package:analysis_server/src/domain_completion.dart'; |
| 14 import 'package:analysis_server/src/domain_execution.dart'; | 15 import 'package:analysis_server/src/domain_execution.dart'; |
| 15 import 'package:analysis_server/src/operation/operation.dart'; | 16 import 'package:analysis_server/src/operation/operation.dart'; |
| 16 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 17 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
| 17 import 'package:analysis_server/src/operation/operation_queue.dart'; | 18 import 'package:analysis_server/src/operation/operation_queue.dart'; |
| 18 import 'package:analysis_server/src/protocol.dart' hide Element; | 19 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 20 import 'package:analysis_server/src/services/index/index.dart'; | |
| 21 import 'package:analysis_server/src/services/index/local_index.dart'; | |
| 22 import 'package:analysis_server/src/services/index/store/split_store.dart'; | |
| 19 import 'package:analysis_server/src/socket_server.dart'; | 23 import 'package:analysis_server/src/socket_server.dart'; |
| 20 import 'package:analysis_server/src/status/ast_writer.dart'; | 24 import 'package:analysis_server/src/status/ast_writer.dart'; |
| 21 import 'package:analysis_server/src/status/element_writer.dart'; | 25 import 'package:analysis_server/src/status/element_writer.dart'; |
| 22 import 'package:analyzer/file_system/file_system.dart'; | 26 import 'package:analyzer/file_system/file_system.dart'; |
| 23 import 'package:analyzer/src/generated/ast.dart'; | 27 import 'package:analyzer/src/generated/ast.dart'; |
| 24 import 'package:analyzer/src/generated/element.dart'; | 28 import 'package:analyzer/src/generated/element.dart'; |
| 25 import 'package:analyzer/src/generated/engine.dart'; | 29 import 'package:analyzer/src/generated/engine.dart'; |
| 26 import 'package:analyzer/src/generated/java_engine.dart'; | 30 import 'package:analyzer/src/generated/java_engine.dart'; |
| 27 import 'package:analyzer/src/generated/source.dart'; | 31 import 'package:analyzer/src/generated/source.dart'; |
| 28 | 32 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 * The path used to request information about a specific context. | 74 * The path used to request information about a specific context. |
| 71 */ | 75 */ |
| 72 static const String CONTEXT_PATH = '/context'; | 76 static const String CONTEXT_PATH = '/context'; |
| 73 | 77 |
| 74 /** | 78 /** |
| 75 * The path used to request information about a element model. | 79 * The path used to request information about a element model. |
| 76 */ | 80 */ |
| 77 static const String ELEMENT_PATH = '/element'; | 81 static const String ELEMENT_PATH = '/element'; |
| 78 | 82 |
| 79 /** | 83 /** |
| 84 * The path used to request information about elements with the given name. | |
| 85 */ | |
| 86 static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name'; | |
| 87 | |
| 88 /** | |
| 80 * The path used to request an overlay contents. | 89 * The path used to request an overlay contents. |
| 81 */ | 90 */ |
| 82 static const String OVERLAY_PATH = '/overlay'; | 91 static const String OVERLAY_PATH = '/overlay'; |
| 83 | 92 |
| 84 /** | 93 /** |
| 85 * The path used to request overlays information. | 94 * The path used to request overlays information. |
| 86 */ | 95 */ |
| 87 static const String OVERLAYS_PATH = '/overlays'; | 96 static const String OVERLAYS_PATH = '/overlays'; |
| 88 | 97 |
| 89 /** | 98 /** |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 108 * accessing [CACHE_STATE_PATH]. | 117 * accessing [CACHE_STATE_PATH]. |
| 109 */ | 118 */ |
| 110 static const String DESCRIPTOR_QUERY_PARAM = 'descriptor'; | 119 static const String DESCRIPTOR_QUERY_PARAM = 'descriptor'; |
| 111 | 120 |
| 112 /** | 121 /** |
| 113 * Query parameter used to represent the index in the [_overlayContents]. | 122 * Query parameter used to represent the index in the [_overlayContents]. |
| 114 */ | 123 */ |
| 115 static const String ID_PARAM = 'id'; | 124 static const String ID_PARAM = 'id'; |
| 116 | 125 |
| 117 /** | 126 /** |
| 127 * Query parameter used to represent the name of elements to search for, when | |
| 128 * accessing [INDEX_ELEMENT_BY_NAME]. | |
| 129 */ | |
| 130 static const String INDEX_ELEMENT_NAME = 'name'; | |
| 131 | |
| 132 /** | |
| 118 * Query parameter used to represent the source to search for, when accessing | 133 * Query parameter used to represent the source to search for, when accessing |
| 119 * [CACHE_ENTRY_PATH]. | 134 * [CACHE_ENTRY_PATH]. |
| 120 */ | 135 */ |
| 121 static const String SOURCE_QUERY_PARAM = 'entry'; | 136 static const String SOURCE_QUERY_PARAM = 'entry'; |
| 122 | 137 |
| 123 static final ContentType _htmlContent = | 138 static final ContentType _htmlContent = |
| 124 new ContentType("text", "html", charset: "utf-8"); | 139 new ContentType("text", "html", charset: "utf-8"); |
| 125 | 140 |
| 126 /** | 141 /** |
| 127 * The socket server whose status is to be reported on. | 142 * The socket server whose status is to be reported on. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } else if (path == CACHE_STATE_PATH) { | 185 } else if (path == CACHE_STATE_PATH) { |
| 171 _returnCacheState(request); | 186 _returnCacheState(request); |
| 172 } else if (path == CACHE_ENTRY_PATH) { | 187 } else if (path == CACHE_ENTRY_PATH) { |
| 173 _returnCacheEntry(request); | 188 _returnCacheEntry(request); |
| 174 } else if (path == COMPLETION_PATH) { | 189 } else if (path == COMPLETION_PATH) { |
| 175 _returnCompletionInfo(request); | 190 _returnCompletionInfo(request); |
| 176 } else if (path == CONTEXT_PATH) { | 191 } else if (path == CONTEXT_PATH) { |
| 177 _returnContextInfo(request); | 192 _returnContextInfo(request); |
| 178 } else if (path == ELEMENT_PATH) { | 193 } else if (path == ELEMENT_PATH) { |
| 179 _returnElement(request); | 194 _returnElement(request); |
| 195 } else if (path == INDEX_ELEMENT_BY_NAME) { | |
| 196 _returnIndexElementByName(request); | |
| 180 } else if (path == OVERLAY_PATH) { | 197 } else if (path == OVERLAY_PATH) { |
| 181 _returnOverlayContents(request); | 198 _returnOverlayContents(request); |
| 182 } else if (path == OVERLAYS_PATH) { | 199 } else if (path == OVERLAYS_PATH) { |
| 183 _returnOverlaysInfo(request); | 200 _returnOverlaysInfo(request); |
| 184 } else if (path == PERFORMANCE_PATH) { | 201 } else if (path == PERFORMANCE_PATH) { |
| 185 _returnPerformance(request); | 202 _returnPerformance(request); |
| 186 } else { | 203 } else { |
| 187 _returnUnknownRequest(request); | 204 _returnUnknownRequest(request); |
| 188 } | 205 } |
| 189 } | 206 } |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 _writePage( | 705 _writePage( |
| 689 buffer, | 706 buffer, |
| 690 'Analysis Server - Failure', | 707 'Analysis Server - Failure', |
| 691 [], | 708 [], |
| 692 (StringBuffer buffer) { | 709 (StringBuffer buffer) { |
| 693 buffer.write(HTML_ESCAPE.convert(message)); | 710 buffer.write(HTML_ESCAPE.convert(message)); |
| 694 }); | 711 }); |
| 695 }); | 712 }); |
| 696 } | 713 } |
| 697 | 714 |
| 715 /** | |
| 716 * Return a response containing information about elements with the given | |
| 717 * name. | |
| 718 */ | |
| 719 Future _returnIndexElementByName(HttpRequest request) async { | |
| 720 AnalysisServer analysisServer = _server.analysisServer; | |
| 721 if (analysisServer == null) { | |
| 722 return _returnFailure(request, 'Analysis server not running'); | |
| 723 } | |
| 724 Index index = analysisServer.index; | |
| 725 String name = request.uri.queryParameters[INDEX_ELEMENT_NAME]; | |
| 726 if (name == null) { | |
| 727 return _returnFailure( | |
| 728 request, | |
| 729 'Query parameter $INDEX_ELEMENT_NAME required'); | |
| 730 } | |
| 731 if (index is LocalIndex) { | |
|
Paul Berry
2015/02/02 23:45:47
It would be nice to have an "else" block that gene
scheglov
2015/02/03 03:04:49
Done.
| |
| 732 Map<List<String>, List<InspectLocation>> relations = | |
| 733 await index.findElementsByName(name); | |
| 734 _writeResponse(request, (StringBuffer buffer) { | |
| 735 _writePage( | |
| 736 buffer, | |
| 737 'Analysis Server - Index Elements', | |
| 738 ['Name: $name'], | |
| 739 (StringBuffer buffer) { | |
| 740 buffer.write('<table border="1">'); | |
| 741 _writeRow( | |
| 742 buffer, | |
| 743 ['Element', 'Relationship', 'Location'], | |
| 744 header: true); | |
| 745 relations.forEach( | |
| 746 (List<String> elementPath, List<InspectLocation> relations) { | |
| 747 String elementLocation = elementPath.join(' '); | |
| 748 relations.forEach((InspectLocation location) { | |
| 749 var relString = location.relationship.identifier; | |
| 750 var locString = | |
| 751 '${location.path} offset=${location.offset} ' | |
| 752 'length=${location.length} flags=${location.flags}'; | |
| 753 _writeRow(buffer, [elementLocation, relString, locString]); | |
| 754 }); | |
| 755 }); | |
| 756 buffer.write('</table>'); | |
| 757 }); | |
| 758 }); | |
| 759 } | |
| 760 } | |
| 761 | |
| 698 void _returnOverlayContents(HttpRequest request) { | 762 void _returnOverlayContents(HttpRequest request) { |
| 699 String idString = request.requestedUri.queryParameters[ID_PARAM]; | 763 String idString = request.requestedUri.queryParameters[ID_PARAM]; |
| 700 if (idString == null) { | 764 if (idString == null) { |
| 701 return _returnFailure(request, 'Query parameter $ID_PARAM required'); | 765 return _returnFailure(request, 'Query parameter $ID_PARAM required'); |
| 702 } | 766 } |
| 703 int id = int.parse(idString); | 767 int id = int.parse(idString); |
| 704 String contents = _overlayContents[id]; | 768 String contents = _overlayContents[id]; |
| 705 | 769 |
| 706 _writeResponse(request, (StringBuffer buffer) { | 770 _writeResponse(request, (StringBuffer buffer) { |
| 707 _writePage( | 771 _writePage( |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1043 ' ', | 1107 ' ', |
| 1044 performance.elapsedInMilliseconds, | 1108 performance.elapsedInMilliseconds, |
| 1045 ' ', | 1109 ' ', |
| 1046 performance.notificationCount, | 1110 performance.notificationCount, |
| 1047 ' ', | 1111 ' ', |
| 1048 performance.suggestionCount, | 1112 performance.suggestionCount, |
| 1049 ' ', | 1113 ' ', |
| 1050 HTML_ESCAPE.convert(performance.snippet)]); | 1114 HTML_ESCAPE.convert(performance.snippet)]); |
| 1051 ++index; | 1115 ++index; |
| 1052 } | 1116 } |
| 1053 ; | 1117 |
| 1054 buffer.write('</table>'); | 1118 buffer.write('</table>'); |
| 1055 buffer.write(''' | 1119 buffer.write(''' |
| 1056 <p><strong>First (ms)</strong> - the number of milliseconds | 1120 <p><strong>First (ms)</strong> - the number of milliseconds |
| 1057 from when completion received the request until the first notification | 1121 from when completion received the request until the first notification |
| 1058 with completion results was queued for sending back to the client. | 1122 with completion results was queued for sending back to the client. |
| 1059 <p><strong>Complete (ms)</strong> - the number of milliseconds | 1123 <p><strong>Complete (ms)</strong> - the number of milliseconds |
| 1060 from when completion received the request until the final notification | 1124 from when completion received the request until the final notification |
| 1061 with completion results was queued for sending back to the client. | 1125 with completion results was queued for sending back to the client. |
| 1062 <p><strong># Notifications</strong> - the total number of notifications | 1126 <p><strong># Notifications</strong> - the total number of notifications |
| 1063 sent to the client with completion results for this request. | 1127 sent to the client with completion results for this request. |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1473 } else if (value is Element) { | 1537 } else if (value is Element) { |
| 1474 String link = | 1538 String link = |
| 1475 _makeLink(ELEMENT_PATH, linkParameters, value.runtimeType.toString()); | 1539 _makeLink(ELEMENT_PATH, linkParameters, value.runtimeType.toString()); |
| 1476 buffer.write('<i>$link</i>'); | 1540 buffer.write('<i>$link</i>'); |
| 1477 } else { | 1541 } else { |
| 1478 buffer.write(HTML_ESCAPE.convert(value.toString())); | 1542 buffer.write(HTML_ESCAPE.convert(value.toString())); |
| 1479 buffer.write(' <i>(${value.runtimeType.toString()})</i>'); | 1543 buffer.write(' <i>(${value.runtimeType.toString()})</i>'); |
| 1480 } | 1544 } |
| 1481 } | 1545 } |
| 1482 } | 1546 } |
| OLD | NEW |