| 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 search.domain; | 5 library search.domain; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analysis_server/src/protocol.dart' as protocol; | 9 import 'package:analysis_server/src/protocol.dart' as protocol; |
| 10 import 'package:analysis_server/src/search/element_references.dart'; | 10 import 'package:analysis_server/src/search/element_references.dart'; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 String searchId = (_nextSearchId++).toString(); | 57 String searchId = (_nextSearchId++).toString(); |
| 58 elements.forEach((Element element) { | 58 elements.forEach((Element element) { |
| 59 var computer = new ElementReferencesComputer(searchEngine); | 59 var computer = new ElementReferencesComputer(searchEngine); |
| 60 var future = computer.compute(element, params.includePotential); | 60 var future = computer.compute(element, params.includePotential); |
| 61 future.then((List<protocol.SearchResult> results) { | 61 future.then((List<protocol.SearchResult> results) { |
| 62 bool isLast = identical(element, elements.last); | 62 bool isLast = identical(element, elements.last); |
| 63 _sendSearchNotification(searchId, isLast, results); | 63 _sendSearchNotification(searchId, isLast, results); |
| 64 }); | 64 }); |
| 65 }); | 65 }); |
| 66 // respond | 66 // respond |
| 67 if (elements.isEmpty) { | 67 var result = new protocol.SearchFindElementReferencesResult(); |
| 68 return new protocol.SearchFindElementReferencesResult().toResponse( | 68 if (elements.isNotEmpty) { |
| 69 request.id); | 69 result.id = searchId; |
| 70 } else { | 70 result.element = new protocol.Element.fromEngine(elements[0]); |
| 71 protocol.Element element = new protocol.Element.fromEngine(elements[0]); | |
| 72 return new protocol.SearchFindElementReferencesResult(id: searchId, | |
| 73 element: element).toResponse(request.id); | |
| 74 } | 71 } |
| 72 return result.toResponse(request.id); |
| 75 } | 73 } |
| 76 | 74 |
| 77 protocol.Response findMemberDeclarations(protocol.Request request) { | 75 protocol.Response findMemberDeclarations(protocol.Request request) { |
| 78 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req
uest); | 76 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req
uest); |
| 79 // schedule search | 77 // schedule search |
| 80 String searchId = (_nextSearchId++).toString(); | 78 String searchId = (_nextSearchId++).toString(); |
| 81 { | 79 { |
| 82 var matchesFuture = searchEngine.searchMemberDeclarations(params.name); | 80 var matchesFuture = searchEngine.searchMemberDeclarations(params.name); |
| 83 matchesFuture.then((List<SearchMatch> matches) { | 81 matchesFuture.then((List<SearchMatch> matches) { |
| 84 _sendSearchNotification(searchId, true, matches.map(toResult)); | 82 _sendSearchNotification(searchId, true, matches.map(toResult)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void _sendSearchNotification(String searchId, bool isLast, | 167 void _sendSearchNotification(String searchId, bool isLast, |
| 170 Iterable<protocol.SearchResult> results) { | 168 Iterable<protocol.SearchResult> results) { |
| 171 server.sendNotification(new protocol.SearchResultsParams(searchId, | 169 server.sendNotification(new protocol.SearchResultsParams(searchId, |
| 172 results.toList(), isLast).toNotification()); | 170 results.toList(), isLast).toNotification()); |
| 173 } | 171 } |
| 174 | 172 |
| 175 static protocol.SearchResult toResult(SearchMatch match) { | 173 static protocol.SearchResult toResult(SearchMatch match) { |
| 176 return new protocol.SearchResult.fromMatch(match); | 174 return new protocol.SearchResult.fromMatch(match); |
| 177 } | 175 } |
| 178 } | 176 } |
| OLD | NEW |