OLD | NEW |
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 services.src.search.search_engine; | 5 library services.src.search.search_engine; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
| 9 import 'package:analysis_server/src/services/correction/source_range.dart'; |
9 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
10 import 'package:analysis_server/src/services/search/search_engine.dart'; | 11 import 'package:analysis_server/src/services/search/search_engine.dart'; |
11 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
12 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
13 import 'package:analysis_server/src/services/correction/source_range.dart'; | |
14 | 14 |
15 /** | 15 /** |
16 * A [SearchEngine] implementation. | 16 * A [SearchEngine] implementation. |
17 */ | 17 */ |
18 class SearchEngineImpl implements SearchEngine { | 18 class SearchEngineImpl implements SearchEngine { |
19 final Index _index; | 19 final Index _index; |
20 | 20 |
21 SearchEngineImpl(this._index); | 21 SearchEngineImpl(this._index); |
22 | 22 |
23 @override | 23 @override |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return requestor.merge(); | 190 return requestor.merge(); |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 class _Requestor { | 194 class _Requestor { |
195 final List<Future<List<SearchMatch>>> futures = <Future<List<SearchMatch>>>[]; | 195 final List<Future<List<SearchMatch>>> futures = <Future<List<SearchMatch>>>[]; |
196 final Index index; | 196 final Index index; |
197 | 197 |
198 _Requestor(this.index); | 198 _Requestor(this.index); |
199 | 199 |
200 void add(Element element, Relationship relationship, MatchKind kind) { | 200 void add(Element element, RelationshipImpl relationship, MatchKind kind) { |
201 Future relationsFuture = index.getRelationships(element, relationship); | 201 Future relationsFuture = index.getRelationships(element, relationship); |
202 Future matchesFuture = relationsFuture.then((List<Location> locations) { | 202 Future matchesFuture = relationsFuture.then((List<LocationImpl> locations) { |
203 List<SearchMatch> matches = <SearchMatch>[]; | 203 List<SearchMatch> matches = <SearchMatch>[]; |
204 for (Location location in locations) { | 204 for (LocationImpl location in locations) { |
205 matches.add(new SearchMatch(kind, location.element, | 205 matches.add(new SearchMatch(kind, location.element, |
206 new SourceRange(location.offset, location.length), | 206 new SourceRange(location.offset, location.length), |
207 location.isResolved, location.isQualified)); | 207 location.isResolved, location.isQualified)); |
208 } | 208 } |
209 return matches; | 209 return matches; |
210 }); | 210 }); |
211 futures.add(matchesFuture); | 211 futures.add(matchesFuture); |
212 } | 212 } |
213 | 213 |
214 Future<List<SearchMatch>> merge() { | 214 Future<List<SearchMatch>> merge() { |
215 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { | 215 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { |
216 return matchesList.expand((matches) => matches).toList(); | 216 return matchesList.expand((matches) => matches).toList(); |
217 }); | 217 }); |
218 } | 218 } |
219 } | 219 } |
OLD | NEW |