| 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/index/index.dart'; | 9 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analysis_server/src/services/search/search_engine.dart'; | 10 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 Future<List<SearchMatch>> searchSubtypes(ClassElement type) { | 96 Future<List<SearchMatch>> searchSubtypes(ClassElement type) { |
| 97 _Requestor requestor = new _Requestor(_index); | 97 _Requestor requestor = new _Requestor(_index); |
| 98 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE); | 98 requestor.add(type, IndexConstants.IS_EXTENDED_BY, MatchKind.REFERENCE); |
| 99 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE); | 99 requestor.add(type, IndexConstants.IS_MIXED_IN_BY, MatchKind.REFERENCE); |
| 100 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); | 100 requestor.add(type, IndexConstants.IS_IMPLEMENTED_BY, MatchKind.REFERENCE); |
| 101 return requestor.merge(); | 101 return requestor.merge(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 @override | 104 @override |
| 105 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { | 105 Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) { |
| 106 UniverseElement universe = UniverseElement.INSTANCE; | |
| 107 _Requestor requestor = new _Requestor(_index); | |
| 108 requestor.add(universe, IndexConstants.DEFINES, MatchKind.DECLARATION); | |
| 109 RegExp regExp = new RegExp(pattern); | 106 RegExp regExp = new RegExp(pattern); |
| 110 return requestor.merge().then((List<SearchMatch> matches) { | 107 List<Element> elements = _index.getTopLevelDeclarations((String name) => reg
Exp.hasMatch(name)); |
| 111 return matches.where((SearchMatch match) { | 108 List<SearchMatch> matches = <SearchMatch>[]; |
| 112 String name = match.element.displayName; | 109 for (var element in elements) { |
| 113 return regExp.hasMatch(name); | 110 SourceRange range = new SourceRange(element.nameOffset, element.name.lengt
h); |
| 114 }).toList(); | 111 matches.add(new SearchMatch(MatchKind.DECLARATION, element, range, true, f
alse)); |
| 115 }); | 112 } |
| 113 // TODO(scheglov) it does not have to be a Future |
| 114 return new Future.value(matches); |
| 116 } | 115 } |
| 117 | 116 |
| 118 Future<List<SearchMatch>> _searchReferences(Element element) { | 117 Future<List<SearchMatch>> _searchReferences(Element element) { |
| 119 _Requestor requestor = new _Requestor(_index); | 118 _Requestor requestor = new _Requestor(_index); |
| 120 requestor.add( | 119 requestor.add( |
| 121 element, | 120 element, |
| 122 IndexConstants.IS_REFERENCED_BY, | 121 IndexConstants.IS_REFERENCED_BY, |
| 123 MatchKind.REFERENCE); | 122 MatchKind.REFERENCE); |
| 124 return requestor.merge(); | 123 return requestor.merge(); |
| 125 } | 124 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 }); | 233 }); |
| 235 futures.add(matchesFuture); | 234 futures.add(matchesFuture); |
| 236 } | 235 } |
| 237 | 236 |
| 238 Future<List<SearchMatch>> merge() { | 237 Future<List<SearchMatch>> merge() { |
| 239 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { | 238 return Future.wait(futures).then((List<List<SearchMatch>> matchesList) { |
| 240 return matchesList.expand((matches) => matches).toList(); | 239 return matchesList.expand((matches) => matches).toList(); |
| 241 }); | 240 }); |
| 242 } | 241 } |
| 243 } | 242 } |
| OLD | NEW |