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

Side by Side Diff: pkg/analysis_server/lib/src/search/search_domain.dart

Issue 422573003: Implementation of the 'search.getTypeHierarchy' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 search.domain; 5 library search.domain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/element.dart' as se; 10 import 'package:analysis_server/src/computer/element.dart' as se;
11 import 'package:analysis_server/src/constants.dart'; 11 import 'package:analysis_server/src/constants.dart';
12 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
13 import 'package:analysis_server/src/search/element_references.dart'; 13 import 'package:analysis_server/src/search/element_references.dart';
14 import 'package:analysis_server/src/search/search_result.dart'; 14 import 'package:analysis_server/src/search/search_result.dart';
15 import 'package:analysis_server/src/search/type_hierarchy.dart';
15 import 'package:analysis_services/constants.dart'; 16 import 'package:analysis_services/constants.dart';
16 import 'package:analysis_services/search/search_engine.dart'; 17 import 'package:analysis_services/search/search_engine.dart';
17 import 'package:analyzer/src/generated/element.dart'; 18 import 'package:analyzer/src/generated/element.dart';
18 19
19 /** 20 /**
20 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] 21 * Instances of the class [SearchDomainHandler] implement a [RequestHandler]
21 * that handles requests in the search domain. 22 * that handles requests in the search domain.
22 */ 23 */
23 class SearchDomainHandler implements RequestHandler { 24 class SearchDomainHandler implements RequestHandler {
24 /** 25 /**
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 { 120 {
120 var matchesFuture = searchEngine.searchTopLevelDeclarations(pattern); 121 var matchesFuture = searchEngine.searchTopLevelDeclarations(pattern);
121 matchesFuture.then((List<SearchMatch> matches) { 122 matchesFuture.then((List<SearchMatch> matches) {
122 _sendSearchNotification(searchId, true, matches.map(toResult)); 123 _sendSearchNotification(searchId, true, matches.map(toResult));
123 }); 124 });
124 } 125 }
125 // respond 126 // respond
126 return new Response(request.id)..setResult(ID, searchId); 127 return new Response(request.id)..setResult(ID, searchId);
127 } 128 }
128 129
130 /**
131 * Implement the `search.getTypeHierarchy` request.
132 */
133 Response getTypeHierarchy(Request request) {
134 // prepare parameters
135 String file = request.getRequiredParameter(FILE).asString();
136 int offset = request.getRequiredParameter(OFFSET).asInt();
137 // prepare Element
138 List<Element> elements = server.getElementsAtOffset(file, offset);
139 if (elements.isEmpty) {
140 return new Response(request.id);
141 }
142 Element element = elements.first;
143 // prepare type hierarchy
144 TypeHierarchyComputer computer = new TypeHierarchyComputer(searchEngine);
145 computer.compute(element).then((TypeHierarchyItem item) {
146 Response response = new Response(request.id);
147 response.setResult(HIERARCHY, item);
148 server.sendResponse(response);
149 });
150 // delay response
151 return Response.DELAYED_RESPONSE;
152 }
153
129 @override 154 @override
130 Response handleRequest(Request request) { 155 Response handleRequest(Request request) {
131 try { 156 try {
132 String requestName = request.method; 157 String requestName = request.method;
133 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) { 158 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) {
134 return findElementReferences(request); 159 return findElementReferences(request);
135 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) { 160 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) {
136 return findMemberDeclarations(request); 161 return findMemberDeclarations(request);
137 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) { 162 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) {
138 return findMemberReferences(request); 163 return findMemberReferences(request);
139 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) { 164 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) {
140 return findTopLevelDeclarations(request); 165 return findTopLevelDeclarations(request);
166 } else if (requestName == SEARCH_GET_TYPE_HIERARCHY) {
167 return getTypeHierarchy(request);
141 } 168 }
142 } on RequestFailure catch (exception) { 169 } on RequestFailure catch (exception) {
143 return exception.response; 170 return exception.response;
144 } 171 }
145 return null; 172 return null;
146 } 173 }
147 174
148 void _sendSearchNotification(String searchId, bool isLast, 175 void _sendSearchNotification(String searchId, bool isLast,
149 Iterable<SearchResult> results) { 176 Iterable<SearchResult> results) {
150 Notification notification = new Notification(SEARCH_RESULTS); 177 Notification notification = new Notification(SEARCH_RESULTS);
151 notification.setParameter(ID, searchId); 178 notification.setParameter(ID, searchId);
152 notification.setParameter(LAST, isLast); 179 notification.setParameter(LAST, isLast);
153 notification.setParameter(RESULTS, results); 180 notification.setParameter(RESULTS, results);
154 server.sendNotification(notification); 181 server.sendNotification(notification);
155 } 182 }
156 183
157 static SearchResult toResult(SearchMatch match) { 184 static SearchResult toResult(SearchMatch match) {
158 return new SearchResult.fromMatch(match); 185 return new SearchResult.fromMatch(match);
159 } 186 }
160 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698