| 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/provisional/index/index_core.dart'; | 9 import 'package:analysis_server/src/provisional/index/index_core.dart'; |
| 10 import 'package:analysis_server/src/services/correction/source_range.dart'; | 10 import 'package:analysis_server/src/services/correction/source_range.dart'; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return requestor.merge(); | 112 return requestor.merge(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 @override | 115 @override |
| 116 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { | 116 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { |
| 117 RegExp regExp = new RegExp(pattern); | 117 RegExp regExp = new RegExp(pattern); |
| 118 List<Element> elements = | 118 List<Element> elements = |
| 119 _index.getTopLevelDeclarations((String name) => regExp.hasMatch(name)); | 119 _index.getTopLevelDeclarations((String name) => regExp.hasMatch(name)); |
| 120 List<SearchMatch> matches = <SearchMatch>[]; | 120 List<SearchMatch> matches = <SearchMatch>[]; |
| 121 for (Element element in elements) { | 121 for (Element element in elements) { |
| 122 matches.add(new SearchMatch(MatchKind.DECLARATION, element, | 122 matches.add(new SearchMatch( |
| 123 rangeElementName(element), true, false)); | 123 element.context, |
| 124 element.library.source.uri.toString(), |
| 125 element.source.uri.toString(), |
| 126 MatchKind.DECLARATION, |
| 127 rangeElementName(element), |
| 128 true, |
| 129 false)); |
| 124 } | 130 } |
| 125 return new Future.value(matches); | 131 return new Future.value(matches); |
| 126 } | 132 } |
| 127 | 133 |
| 128 Future<List<SearchMatch>> _searchReferences(Element element) { | 134 Future<List<SearchMatch>> _searchReferences(Element element) { |
| 129 _Requestor requestor = new _Requestor(_index); | 135 _Requestor requestor = new _Requestor(_index); |
| 130 requestor.addElement( | 136 requestor.addElement( |
| 131 element, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); | 137 element, IndexConstants.IS_REFERENCED_BY, MatchKind.REFERENCE); |
| 132 return requestor.merge(); | 138 return requestor.merge(); |
| 133 } | 139 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 _Requestor(this.index); | 229 _Requestor(this.index); |
| 224 | 230 |
| 225 void add(IndexableObject indexable, RelationshipImpl relationship, | 231 void add(IndexableObject indexable, RelationshipImpl relationship, |
| 226 MatchKind kind) { | 232 MatchKind kind) { |
| 227 Future relationsFuture = index.getRelationships(indexable, relationship); | 233 Future relationsFuture = index.getRelationships(indexable, relationship); |
| 228 Future matchesFuture = relationsFuture.then((List<LocationImpl> locations) { | 234 Future matchesFuture = relationsFuture.then((List<LocationImpl> locations) { |
| 229 List<SearchMatch> matches = <SearchMatch>[]; | 235 List<SearchMatch> matches = <SearchMatch>[]; |
| 230 for (LocationImpl location in locations) { | 236 for (LocationImpl location in locations) { |
| 231 IndexableObject indexable = location.indexable; | 237 IndexableObject indexable = location.indexable; |
| 232 if (indexable is IndexableElement) { | 238 if (indexable is IndexableElement) { |
| 239 Element element = indexable.element; |
| 233 matches.add(new SearchMatch( | 240 matches.add(new SearchMatch( |
| 241 element.context, |
| 242 element.library.source.uri.toString(), |
| 243 element.source.uri.toString(), |
| 234 kind, | 244 kind, |
| 235 indexable.element, | |
| 236 new SourceRange(location.offset, location.length), | 245 new SourceRange(location.offset, location.length), |
| 237 location.isResolved, | 246 location.isResolved, |
| 238 location.isQualified)); | 247 location.isQualified)); |
| 239 } | 248 } |
| 240 } | 249 } |
| 241 return matches; | 250 return matches; |
| 242 }); | 251 }); |
| 243 futures.add(matchesFuture); | 252 futures.add(matchesFuture); |
| 244 } | 253 } |
| 245 | 254 |
| 246 void addElement( | 255 void addElement( |
| 247 Element element, RelationshipImpl relationship, MatchKind kind) { | 256 Element element, RelationshipImpl relationship, MatchKind kind) { |
| 248 IndexableElement indexable = new IndexableElement(element); | 257 IndexableElement indexable = new IndexableElement(element); |
| 249 add(indexable, relationship, kind); | 258 add(indexable, relationship, kind); |
| 250 } | 259 } |
| 251 | 260 |
| 252 Future<List<SearchMatch>> merge() { | 261 Future<List<SearchMatch>> merge() { |
| 253 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { | 262 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { |
| 254 return matchesList.expand((matches) => matches).toList(); | 263 return matchesList.expand((matches) => matches).toList(); |
| 255 }); | 264 }); |
| 256 } | 265 } |
| 257 } | 266 } |
| OLD | NEW |