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

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

Issue 506433002: Finish modifying analysis server to make use of code generation. (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/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart' as protocol;
12 import 'package:analysis_server/src/protocol2.dart' as protocol;
13 import 'package:analysis_server/src/search/element_references.dart'; 12 import 'package:analysis_server/src/search/element_references.dart';
14 import 'package:analysis_server/src/search/type_hierarchy.dart'; 13 import 'package:analysis_server/src/search/type_hierarchy.dart';
15 import 'package:analysis_server/src/services/search/search_engine.dart'; 14 import 'package:analysis_server/src/services/search/search_engine.dart';
16 import 'package:analyzer/src/generated/element.dart'; 15 import 'package:analyzer/src/generated/element.dart';
17 16
18 /** 17 /**
19 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] 18 * Instances of the class [SearchDomainHandler] implement a [RequestHandler]
20 * that handles requests in the search domain. 19 * that handles requests in the search domain.
21 */ 20 */
22 class SearchDomainHandler implements RequestHandler { 21 class SearchDomainHandler implements protocol.RequestHandler {
23 /** 22 /**
24 * The analysis server that is using this handler to process requests. 23 * The analysis server that is using this handler to process requests.
25 */ 24 */
26 final AnalysisServer server; 25 final AnalysisServer server;
27 26
28 /** 27 /**
29 * The [SearchEngine] for this server. 28 * The [SearchEngine] for this server.
30 */ 29 */
31 SearchEngine searchEngine; 30 SearchEngine searchEngine;
32 31
33 /** 32 /**
34 * The next searc response id. 33 * The next searc response id.
35 */ 34 */
36 int _nextSearchId = 0; 35 int _nextSearchId = 0;
37 36
38 /** 37 /**
39 * Initialize a newly created handler to handle requests for the given [server ]. 38 * Initialize a newly created handler to handle requests for the given [server ].
40 */ 39 */
41 SearchDomainHandler(this.server) { 40 SearchDomainHandler(this.server) {
42 searchEngine = server.searchEngine; 41 searchEngine = server.searchEngine;
43 } 42 }
44 43
45 Response findElementReferences(Request request) { 44 protocol.Response findElementReferences(protocol.Request request) {
46 var params = new protocol.SearchFindElementReferencesParams.fromRequest(requ est); 45 var params = new protocol.SearchFindElementReferencesParams.fromRequest(requ est);
47 // prepare elements 46 // prepare elements
48 List<Element> elements = server.getElementsAtOffset(params.file, 47 List<Element> elements = server.getElementsAtOffset(params.file,
49 params.offset); 48 params.offset);
50 elements = elements.map((Element element) { 49 elements = elements.map((Element element) {
51 if (element is FieldFormalParameterElement) { 50 if (element is FieldFormalParameterElement) {
52 return element.field; 51 return element.field;
53 } 52 }
54 if (element is PropertyAccessorElement) { 53 if (element is PropertyAccessorElement) {
55 return element.variable; 54 return element.variable;
(...skipping 17 matching lines...) Expand all
73 } 72 }
74 // respond 73 // respond
75 protocol.Element element; 74 protocol.Element element;
76 if (elements.isNotEmpty) { 75 if (elements.isNotEmpty) {
77 element = new protocol.Element.fromEngine(elements[0]); 76 element = new protocol.Element.fromEngine(elements[0]);
78 } 77 }
79 return new protocol.SearchFindElementReferencesResult(searchId, 78 return new protocol.SearchFindElementReferencesResult(searchId,
80 element: element).toResponse(request.id); 79 element: element).toResponse(request.id);
81 } 80 }
82 81
83 Response findMemberDeclarations(Request request) { 82 protocol.Response findMemberDeclarations(protocol.Request request) {
84 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req uest); 83 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req uest);
85 // schedule search 84 // schedule search
86 String searchId = (_nextSearchId++).toString(); 85 String searchId = (_nextSearchId++).toString();
87 { 86 {
88 var matchesFuture = searchEngine.searchMemberDeclarations(params.name); 87 var matchesFuture = searchEngine.searchMemberDeclarations(params.name);
89 matchesFuture.then((List<SearchMatch> matches) { 88 matchesFuture.then((List<SearchMatch> matches) {
90 _sendSearchNotification(searchId, true, matches.map(toResult)); 89 _sendSearchNotification(searchId, true, matches.map(toResult));
91 }); 90 });
92 } 91 }
93 // respond 92 // respond
94 return new protocol.SearchFindMemberDeclarationsResult( 93 return new protocol.SearchFindMemberDeclarationsResult(
95 searchId).toResponse(request.id); 94 searchId).toResponse(request.id);
96 } 95 }
97 96
98 Response findMemberReferences(Request request) { 97 protocol.Response findMemberReferences(protocol.Request request) {
99 var params = new protocol.SearchFindMemberReferencesParams.fromRequest(reque st); 98 var params = new protocol.SearchFindMemberReferencesParams.fromRequest(reque st);
100 // schedule search 99 // schedule search
101 String searchId = (_nextSearchId++).toString(); 100 String searchId = (_nextSearchId++).toString();
102 { 101 {
103 var matchesFuture = searchEngine.searchMemberReferences(params.name); 102 var matchesFuture = searchEngine.searchMemberReferences(params.name);
104 matchesFuture.then((List<SearchMatch> matches) { 103 matchesFuture.then((List<SearchMatch> matches) {
105 _sendSearchNotification(searchId, true, matches.map(toResult)); 104 _sendSearchNotification(searchId, true, matches.map(toResult));
106 }); 105 });
107 } 106 }
108 // respond 107 // respond
109 return new protocol.SearchFindMemberReferencesResult(searchId).toResponse( 108 return new protocol.SearchFindMemberReferencesResult(searchId).toResponse(
110 request.id); 109 request.id);
111 } 110 }
112 111
113 Response findTopLevelDeclarations(Request request) { 112 protocol.Response findTopLevelDeclarations(protocol.Request request) {
114 var params = new protocol.SearchFindTopLevelDeclarationsParams.fromRequest(r equest); 113 var params = new protocol.SearchFindTopLevelDeclarationsParams.fromRequest(r equest);
115 // schedule search 114 // schedule search
116 String searchId = (_nextSearchId++).toString(); 115 String searchId = (_nextSearchId++).toString();
117 { 116 {
118 var matchesFuture = searchEngine.searchTopLevelDeclarations(params.pattern ); 117 var matchesFuture = searchEngine.searchTopLevelDeclarations(params.pattern );
119 matchesFuture.then((List<SearchMatch> matches) { 118 matchesFuture.then((List<SearchMatch> matches) {
120 _sendSearchNotification(searchId, true, matches.map(toResult)); 119 _sendSearchNotification(searchId, true, matches.map(toResult));
121 }); 120 });
122 } 121 }
123 // respond 122 // respond
124 return new protocol.SearchFindTopLevelDeclarationsResult( 123 return new protocol.SearchFindTopLevelDeclarationsResult(
125 searchId).toResponse(request.id); 124 searchId).toResponse(request.id);
126 } 125 }
127 126
128 /** 127 /**
129 * Implement the `search.getTypeHierarchy` request. 128 * Implement the `search.getTypeHierarchy` request.
130 */ 129 */
131 Response getTypeHierarchy(Request request) { 130 protocol.Response getTypeHierarchy(protocol.Request request) {
132 var params = new protocol.SearchGetTypeHierarchyParams.fromRequest(request); 131 var params = new protocol.SearchGetTypeHierarchyParams.fromRequest(request);
133 // prepare parameters 132 // prepare parameters
134 // prepare Element 133 // prepare Element
135 List<Element> elements = server.getElementsAtOffset(params.file, 134 List<Element> elements = server.getElementsAtOffset(params.file,
136 params.offset); 135 params.offset);
137 if (elements.isEmpty) { 136 if (elements.isEmpty) {
138 Response response = new protocol.SearchGetTypeHierarchyResult().toResponse (request.id); 137 protocol.Response response =
138 new protocol.SearchGetTypeHierarchyResult().toResponse(request.id);
139 return response; 139 return response;
140 } 140 }
141 Element element = elements.first; 141 Element element = elements.first;
142 // prepare type hierarchy 142 // prepare type hierarchy
143 TypeHierarchyComputer computer = new TypeHierarchyComputer(searchEngine); 143 TypeHierarchyComputer computer = new TypeHierarchyComputer(searchEngine);
144 computer.compute(element).then((List<protocol.TypeHierarchyItem> items) { 144 computer.compute(element).then((List<protocol.TypeHierarchyItem> items) {
145 Response response = new protocol.SearchGetTypeHierarchyResult( 145 protocol.Response response = new protocol.SearchGetTypeHierarchyResult(
146 hierarchyItems: items).toResponse(request.id); 146 hierarchyItems: items).toResponse(request.id);
147 server.sendResponse(response); 147 server.sendResponse(response);
148 }); 148 });
149 // delay response 149 // delay response
150 return Response.DELAYED_RESPONSE; 150 return protocol.Response.DELAYED_RESPONSE;
151 } 151 }
152 152
153 @override 153 @override
154 Response handleRequest(Request request) { 154 protocol.Response handleRequest(protocol.Request request) {
155 try { 155 try {
156 String requestName = request.method; 156 String requestName = request.method;
157 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) { 157 if (requestName == SEARCH_FIND_ELEMENT_REFERENCES) {
158 return findElementReferences(request); 158 return findElementReferences(request);
159 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) { 159 } else if (requestName == SEARCH_FIND_MEMBER_DECLARATIONS) {
160 return findMemberDeclarations(request); 160 return findMemberDeclarations(request);
161 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) { 161 } else if (requestName == SEARCH_FIND_MEMBER_REFERENCES) {
162 return findMemberReferences(request); 162 return findMemberReferences(request);
163 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) { 163 } else if (requestName == SEARCH_FIND_TOP_LEVEL_DECLARATIONS) {
164 return findTopLevelDeclarations(request); 164 return findTopLevelDeclarations(request);
165 } else if (requestName == SEARCH_GET_TYPE_HIERARCHY) { 165 } else if (requestName == SEARCH_GET_TYPE_HIERARCHY) {
166 return getTypeHierarchy(request); 166 return getTypeHierarchy(request);
167 } 167 }
168 } on RequestFailure catch (exception) { 168 } on protocol.RequestFailure catch (exception) {
169 return exception.response; 169 return exception.response;
170 } 170 }
171 return null; 171 return null;
172 } 172 }
173 173
174 void _sendSearchNotification(String searchId, bool isLast, 174 void _sendSearchNotification(String searchId, bool isLast,
175 Iterable<protocol.SearchResult> results) { 175 Iterable<protocol.SearchResult> results) {
176 server.sendNotification(new protocol.SearchResultsParams(searchId, 176 server.sendNotification(new protocol.SearchResultsParams(searchId,
177 results.toList(), isLast).toNotification()); 177 results.toList(), isLast).toNotification());
178 } 178 }
179 179
180 static protocol.SearchResult toResult(SearchMatch match) { 180 static protocol.SearchResult toResult(SearchMatch match) {
181 return new protocol.SearchResult.fromMatch(match); 181 return new protocol.SearchResult.fromMatch(match);
182 } 182 }
183 } 183 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/element_references.dart ('k') | pkg/analysis_server/lib/src/search/search_result.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698