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

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

Issue 2525693002: Use single unit/node/element. (Closed)
Patch Set: Created 4 years, 1 month 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
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';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 String searchId = (_nextSearchId++).toString(); 54 String searchId = (_nextSearchId++).toString();
55 var result = new protocol.SearchFindElementReferencesResult(); 55 var result = new protocol.SearchFindElementReferencesResult();
56 result.id = searchId; 56 result.id = searchId;
57 _sendSearchResult(request, result); 57 _sendSearchResult(request, result);
58 _sendSearchNotification(searchId, true, <protocol.SearchResult>[]); 58 _sendSearchNotification(searchId, true, <protocol.SearchResult>[]);
59 return; 59 return;
60 } 60 }
61 var params = 61 var params =
62 new protocol.SearchFindElementReferencesParams.fromRequest(request); 62 new protocol.SearchFindElementReferencesParams.fromRequest(request);
63 await server.onAnalysisComplete; 63 await server.onAnalysisComplete;
64 // prepare elements 64 // prepare element
65 List<Element> elements = 65 Element element = server.getElementAtOffset(params.file, params.offset);
66 server.getElementsAtOffset(params.file, params.offset); 66 if (element is ImportElement) {
67 elements = elements.map((Element element) { 67 element = (element as ImportElement).prefix;
68 if (element is ImportElement) { 68 }
69 return element.prefix; 69 if (element is FieldFormalParameterElement) {
70 } 70 element = (element as FieldFormalParameterElement).field;
71 if (element is FieldFormalParameterElement) { 71 }
72 return element.field; 72 if (element is PropertyAccessorElement) {
73 } 73 element = (element as PropertyAccessorElement).variable;
74 if (element is PropertyAccessorElement) { 74 }
75 return element.variable;
76 }
77 return element;
78 }).where((Element element) {
79 return element != null;
80 }).toList();
81 // respond 75 // respond
82 String searchId = (_nextSearchId++).toString(); 76 String searchId = (_nextSearchId++).toString();
83 var result = new protocol.SearchFindElementReferencesResult(); 77 var result = new protocol.SearchFindElementReferencesResult();
84 if (elements.isNotEmpty) { 78 if (element != null) {
85 result.id = searchId; 79 result.id = searchId;
86 result.element = protocol.convertElement(elements.first); 80 result.element = protocol.convertElement(element);
87 } 81 }
88 _sendSearchResult(request, result); 82 _sendSearchResult(request, result);
89 // search elements 83 // search elements
90 elements.forEach((Element element) async { 84 var computer = new ElementReferencesComputer(searchEngine);
91 var computer = new ElementReferencesComputer(searchEngine); 85 List<protocol.SearchResult> results =
92 List<protocol.SearchResult> results = 86 await computer.compute(element, params.includePotential);
93 await computer.compute(element, params.includePotential); 87 _sendSearchNotification(searchId, true, results);
94 bool isLast = identical(element, elements.last);
95 _sendSearchNotification(searchId, isLast, results);
96 });
97 } 88 }
98 89
99 Future findMemberDeclarations(protocol.Request request) async { 90 Future findMemberDeclarations(protocol.Request request) async {
100 var params = 91 var params =
101 new protocol.SearchFindMemberDeclarationsParams.fromRequest(request); 92 new protocol.SearchFindMemberDeclarationsParams.fromRequest(request);
102 await server.onAnalysisComplete; 93 await server.onAnalysisComplete;
103 // respond 94 // respond
104 String searchId = (_nextSearchId++).toString(); 95 String searchId = (_nextSearchId++).toString();
105 _sendSearchResult( 96 _sendSearchResult(
106 request, new protocol.SearchFindMemberDeclarationsResult(searchId)); 97 request, new protocol.SearchFindMemberDeclarationsResult(searchId));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 155 }
165 var params = new protocol.SearchGetTypeHierarchyParams.fromRequest(request); 156 var params = new protocol.SearchGetTypeHierarchyParams.fromRequest(request);
166 String file = params.file; 157 String file = params.file;
167 // wait for analysis 158 // wait for analysis
168 if (params.superOnly == true) { 159 if (params.superOnly == true) {
169 await server.onFileAnalysisComplete(file); 160 await server.onFileAnalysisComplete(file);
170 } else { 161 } else {
171 await server.onAnalysisComplete; 162 await server.onAnalysisComplete;
172 } 163 }
173 // prepare element 164 // prepare element
174 List<Element> elements = server.getElementsAtOffset(file, params.offset); 165 Element element = server.getElementAtOffset(file, params.offset);
175 if (elements.isEmpty) { 166 if (element == null) {
176 _sendTypeHierarchyNull(request); 167 _sendTypeHierarchyNull(request);
177 return; 168 return;
178 } 169 }
179 Element element = elements.first;
180 // maybe supertype hierarchy only 170 // maybe supertype hierarchy only
181 if (params.superOnly == true) { 171 if (params.superOnly == true) {
182 TypeHierarchyComputer computer = 172 TypeHierarchyComputer computer =
183 new TypeHierarchyComputer(searchEngine, element); 173 new TypeHierarchyComputer(searchEngine, element);
184 List<protocol.TypeHierarchyItem> items = computer.computeSuper(); 174 List<protocol.TypeHierarchyItem> items = computer.computeSuper();
185 protocol.Response response = 175 protocol.Response response =
186 new protocol.SearchGetTypeHierarchyResult(hierarchyItems: items) 176 new protocol.SearchGetTypeHierarchyResult(hierarchyItems: items)
187 .toResponse(request.id); 177 .toResponse(request.id);
188 server.sendResponse(response); 178 server.sendResponse(response);
189 return; 179 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void _sendTypeHierarchyNull(protocol.Request request) { 235 void _sendTypeHierarchyNull(protocol.Request request) {
246 protocol.Response response = 236 protocol.Response response =
247 new protocol.SearchGetTypeHierarchyResult().toResponse(request.id); 237 new protocol.SearchGetTypeHierarchyResult().toResponse(request.id);
248 server.sendResponse(response); 238 server.sendResponse(response);
249 } 239 }
250 240
251 static protocol.SearchResult toResult(SearchMatch match) { 241 static protocol.SearchResult toResult(SearchMatch match) {
252 return protocol.newSearchResult_fromMatch(match); 242 return protocol.newSearchResult_fromMatch(match);
253 } 243 }
254 } 244 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/operation/operation_analysis.dart ('k') | pkg/analysis_server/test/domain_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698