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

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

Issue 396883002: Implementation for the 'search.findMemberReferences' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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/search/element_references.dart'; 11 import 'package:analysis_server/src/search/element_references.dart';
12 import 'package:analysis_server/src/search/search_result.dart'; 12 import 'package:analysis_server/src/search/search_result.dart';
13 import 'package:analysis_server/src/constants.dart'; 13 import 'package:analysis_server/src/constants.dart';
14 import 'package:analysis_server/src/protocol.dart'; 14 import 'package:analysis_server/src/protocol.dart';
15 import 'package:analysis_services/search/search_engine.dart'; 15 import 'package:analysis_services/search/search_engine.dart';
16 import 'package:analyzer/src/generated/element.dart'; 16 import 'package:analyzer/src/generated/element.dart';
17 import 'package:analysis_server/src/search/top_level_declarations.dart';
18 17
19 /** 18 /**
20 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] 19 * Instances of the class [SearchDomainHandler] implement a [RequestHandler]
21 * that handles requests in the search domain. 20 * that handles requests in the search domain.
22 */ 21 */
23 class SearchDomainHandler implements RequestHandler { 22 class SearchDomainHandler implements RequestHandler {
24 /** 23 /**
25 * The analysis server that is using this handler to process requests. 24 * The analysis server that is using this handler to process requests.
26 */ 25 */
27 final AnalysisServer server; 26 final AnalysisServer server;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 85
87 Response findMemberDeclarations(Request request) { 86 Response findMemberDeclarations(Request request) {
88 // name 87 // name
89 RequestDatum nameDatum = request.getRequiredParameter(FILE); 88 RequestDatum nameDatum = request.getRequiredParameter(FILE);
90 String name = nameDatum.asString(); 89 String name = nameDatum.asString();
91 // TODO(brianwilkerson) implement 90 // TODO(brianwilkerson) implement
92 return null; 91 return null;
93 } 92 }
94 93
95 Response findMemberReferences(Request request) { 94 Response findMemberReferences(Request request) {
96 // name 95 String name = request.getRequiredParameter(NAME).asString();
97 RequestDatum nameDatum = request.getRequiredParameter(FILE); 96 // schedule search
98 String name = nameDatum.asString(); 97 String searchId = (_nextSearchId++).toString();
99 // TODO(brianwilkerson) implement 98 {
100 return null; 99 var matchesFuture = searchEngine.searchMemberReferences(name);
100 matchesFuture.then((List<SearchMatch> matches) {
101 _sendSearchNotification(searchId, true, matches.map(toResult));
102 });
103 }
104 // respond
105 return new Response(request.id)..setResult(ID, searchId);
101 } 106 }
102 107
103 Response findTopLevelDeclarations(Request request) { 108 Response findTopLevelDeclarations(Request request) {
104 String pattern = request.getRequiredParameter(PATTERN).asString(); 109 String pattern = request.getRequiredParameter(PATTERN).asString();
105 // schedule search 110 // schedule search
106 String searchId = (_nextSearchId++).toString(); 111 String searchId = (_nextSearchId++).toString();
107 new Future.microtask(() { 112 {
108 var computer = new TopLevelDeclarationsComputer(searchEngine); 113 var matchesFuture = searchEngine.searchTopLevelDeclarations(pattern);
109 var future = computer.compute(pattern); 114 matchesFuture.then((List<SearchMatch> matches) {
110 future.then((List<SearchResult> results) { 115 _sendSearchNotification(searchId, true, matches.map(toResult));
111 _sendSearchNotification(searchId, true, results);
112 }); 116 });
113 }); 117 }
114 // respond 118 // respond
115 return new Response(request.id)..setResult(ID, searchId); 119 return new Response(request.id)..setResult(ID, searchId);
116 } 120 }
117 121
118 @override 122 @override
119 Response handleRequest(Request request) { 123 Response handleRequest(Request request) {
120 try { 124 try {
121 String requestName = request.method; 125 String requestName = request.method;
122 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) { 126 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) {
123 return findElementReferences(request); 127 return findElementReferences(request);
124 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) { 128 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) {
125 return findMemberDeclarations(request); 129 return findMemberDeclarations(request);
126 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) { 130 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) {
127 return findMemberReferences(request); 131 return findMemberReferences(request);
128 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) { 132 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) {
129 return findTopLevelDeclarations(request); 133 return findTopLevelDeclarations(request);
130 } 134 }
131 } on RequestFailure catch (exception) { 135 } on RequestFailure catch (exception) {
132 return exception.response; 136 return exception.response;
133 } 137 }
134 return null; 138 return null;
135 } 139 }
136 140
137 void _sendSearchNotification(String searchId, bool isLast, 141 void _sendSearchNotification(String searchId, bool isLast,
138 List<SearchResult> results) { 142 Iterable<SearchResult> results) {
139 Notification notification = new Notification(SEARCH_RESULTS); 143 Notification notification = new Notification(SEARCH_RESULTS);
140 notification.setParameter(ID, searchId); 144 notification.setParameter(ID, searchId);
141 notification.setParameter(LAST, isLast); 145 notification.setParameter(LAST, isLast);
142 notification.setParameter(RESULTS, results); 146 notification.setParameter(RESULTS, results);
143 server.sendNotification(notification); 147 server.sendNotification(notification);
144 } 148 }
149
150 static SearchResult toResult(SearchMatch match) {
151 return new SearchResult.fromMatch(match);
152 }
145 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698