Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Unified Diff: pkg/analysis_server/lib/src/get_handler.dart

Issue 894853004: Support for inspecting index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/index/local_index.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/get_handler.dart
diff --git a/pkg/analysis_server/lib/src/get_handler.dart b/pkg/analysis_server/lib/src/get_handler.dart
index 4f9a1e2f153abc92266cb6dece72d845129f8143..09cd8992d0549de8e7b84618638475ca589254ac 100644
--- a/pkg/analysis_server/lib/src/get_handler.dart
+++ b/pkg/analysis_server/lib/src/get_handler.dart
@@ -4,6 +4,7 @@
library analysis_server.src.get_handler;
+import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:io';
@@ -16,6 +17,9 @@ import 'package:analysis_server/src/operation/operation.dart';
import 'package:analysis_server/src/operation/operation_analysis.dart';
import 'package:analysis_server/src/operation/operation_queue.dart';
import 'package:analysis_server/src/protocol.dart' hide Element;
+import 'package:analysis_server/src/services/index/index.dart';
+import 'package:analysis_server/src/services/index/local_index.dart';
+import 'package:analysis_server/src/services/index/store/split_store.dart';
import 'package:analysis_server/src/socket_server.dart';
import 'package:analysis_server/src/status/ast_writer.dart';
import 'package:analysis_server/src/status/element_writer.dart';
@@ -77,6 +81,11 @@ class GetHandler {
static const String ELEMENT_PATH = '/element';
/**
+ * The path used to request information about elements with the given name.
+ */
+ static const String INDEX_ELEMENT_BY_NAME = '/index/element-by-name';
+
+ /**
* The path used to request an overlay contents.
*/
static const String OVERLAY_PATH = '/overlay';
@@ -115,6 +124,12 @@ class GetHandler {
static const String ID_PARAM = 'id';
/**
+ * Query parameter used to represent the name of elements to search for, when
+ * accessing [INDEX_ELEMENT_BY_NAME].
+ */
+ static const String INDEX_ELEMENT_NAME = 'name';
+
+ /**
* Query parameter used to represent the source to search for, when accessing
* [CACHE_ENTRY_PATH].
*/
@@ -177,6 +192,8 @@ class GetHandler {
_returnContextInfo(request);
} else if (path == ELEMENT_PATH) {
_returnElement(request);
+ } else if (path == INDEX_ELEMENT_BY_NAME) {
+ _returnIndexElementByName(request);
} else if (path == OVERLAY_PATH) {
_returnOverlayContents(request);
} else if (path == OVERLAYS_PATH) {
@@ -695,6 +712,53 @@ class GetHandler {
});
}
+ /**
+ * Return a response containing information about elements with the given
+ * name.
+ */
+ Future _returnIndexElementByName(HttpRequest request) async {
+ AnalysisServer analysisServer = _server.analysisServer;
+ if (analysisServer == null) {
+ return _returnFailure(request, 'Analysis server not running');
+ }
+ Index index = analysisServer.index;
+ String name = request.uri.queryParameters[INDEX_ELEMENT_NAME];
+ if (name == null) {
+ return _returnFailure(
+ request,
+ 'Query parameter $INDEX_ELEMENT_NAME required');
+ }
+ 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.
+ Map<List<String>, List<InspectLocation>> relations =
+ await index.findElementsByName(name);
+ _writeResponse(request, (StringBuffer buffer) {
+ _writePage(
+ buffer,
+ 'Analysis Server - Index Elements',
+ ['Name: $name'],
+ (StringBuffer buffer) {
+ buffer.write('<table border="1">');
+ _writeRow(
+ buffer,
+ ['Element', 'Relationship', 'Location'],
+ header: true);
+ relations.forEach(
+ (List<String> elementPath, List<InspectLocation> relations) {
+ String elementLocation = elementPath.join(' ');
+ relations.forEach((InspectLocation location) {
+ var relString = location.relationship.identifier;
+ var locString =
+ '${location.path} offset=${location.offset} '
+ 'length=${location.length} flags=${location.flags}';
+ _writeRow(buffer, [elementLocation, relString, locString]);
+ });
+ });
+ buffer.write('</table>');
+ });
+ });
+ }
+ }
+
void _returnOverlayContents(HttpRequest request) {
String idString = request.requestedUri.queryParameters[ID_PARAM];
if (idString == null) {
@@ -1050,7 +1114,7 @@ class GetHandler {
HTML_ESCAPE.convert(performance.snippet)]);
++index;
}
- ;
+
buffer.write('</table>');
buffer.write('''
<p><strong>First (ms)</strong> - the number of milliseconds
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/index/local_index.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698