| 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 '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/computer/element.dart' as se; |
| 10 import 'package:analysis_server/src/search/element_references.dart'; | 11 import 'package:analysis_server/src/search/element_references.dart'; |
| 11 import 'package:analysis_server/src/search/search_result.dart'; | 12 import 'package:analysis_server/src/search/search_result.dart'; |
| 12 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 14 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analysis_services/search/search_engine.dart'; | 15 import 'package:analysis_services/search/search_engine.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] | 19 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] |
| 19 * that handles requests in the search domain. | 20 * that handles requests in the search domain. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 */ | 40 */ |
| 40 SearchDomainHandler(this.server) { | 41 SearchDomainHandler(this.server) { |
| 41 searchEngine = server.searchEngine; | 42 searchEngine = server.searchEngine; |
| 42 } | 43 } |
| 43 | 44 |
| 44 Response findElementReferences(Request request) { | 45 Response findElementReferences(Request request) { |
| 45 String file = request.getRequiredParameter(FILE).asString(); | 46 String file = request.getRequiredParameter(FILE).asString(); |
| 46 int offset = request.getRequiredParameter(OFFSET).asInt(); | 47 int offset = request.getRequiredParameter(OFFSET).asInt(); |
| 47 bool includePotential = | 48 bool includePotential = |
| 48 request.getRequiredParameter(INCLUDE_POTENTIAL).asBool(); | 49 request.getRequiredParameter(INCLUDE_POTENTIAL).asBool(); |
| 50 // prepare elements |
| 51 List<Element> elements = server.getElementsAtOffset(file, offset); |
| 52 elements = elements.map((Element element) { |
| 53 if (element is FieldFormalParameterElement) { |
| 54 return element.field; |
| 55 } |
| 56 if (element is PropertyAccessorElement) { |
| 57 return element.variable; |
| 58 } |
| 59 return element; |
| 60 }).toList(); |
| 49 // schedule search | 61 // schedule search |
| 50 String searchId = (_nextSearchId++).toString(); | 62 String searchId = (_nextSearchId++).toString(); |
| 51 List<Element> elements = server.getElementsAtOffset(file, offset); | |
| 52 elements.forEach((Element element) { | 63 elements.forEach((Element element) { |
| 53 var computer = new ElementReferencesComputer(searchEngine); | 64 var computer = new ElementReferencesComputer(searchEngine); |
| 54 var future = computer.compute(element, includePotential); | 65 var future = computer.compute(element, includePotential); |
| 55 return future.then((List<SearchResult> results) { | 66 return future.then((List<SearchResult> results) { |
| 56 bool isLast = identical(element, elements.last); | 67 bool isLast = identical(element, elements.last); |
| 57 _sendSearchNotification(searchId, isLast, results); | 68 _sendSearchNotification(searchId, isLast, results); |
| 58 }); | 69 }); |
| 59 }); | 70 }); |
| 60 if (elements.isEmpty) { | 71 if (elements.isEmpty) { |
| 61 new Future.microtask(() { | 72 new Future.microtask(() { |
| 62 _sendSearchNotification(searchId, true, []); | 73 _sendSearchNotification(searchId, true, []); |
| 63 }); | 74 }); |
| 64 } | 75 } |
| 65 // respond | 76 // respond |
| 66 return new Response(request.id)..setResult(ID, searchId); | 77 Response response = new Response(request.id); |
| 78 response.setResult(ID, searchId); |
| 79 if (elements.isNotEmpty) { |
| 80 var serverElement = new se.Element.fromEngine(elements[0]); |
| 81 response.setResult(ELEMENT, serverElement); |
| 82 } |
| 83 return response; |
| 67 } | 84 } |
| 68 | 85 |
| 69 Response findMemberDeclarations(Request request) { | 86 Response findMemberDeclarations(Request request) { |
| 70 // name | 87 // name |
| 71 RequestDatum nameDatum = request.getRequiredParameter(FILE); | 88 RequestDatum nameDatum = request.getRequiredParameter(FILE); |
| 72 String name = nameDatum.asString(); | 89 String name = nameDatum.asString(); |
| 73 // TODO(brianwilkerson) implement | 90 // TODO(brianwilkerson) implement |
| 74 return null; | 91 return null; |
| 75 } | 92 } |
| 76 | 93 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 128 |
| 112 void _sendSearchNotification(String searchId, bool isLast, | 129 void _sendSearchNotification(String searchId, bool isLast, |
| 113 List<SearchResult> results) { | 130 List<SearchResult> results) { |
| 114 Notification notification = new Notification(SEARCH_RESULTS); | 131 Notification notification = new Notification(SEARCH_RESULTS); |
| 115 notification.setParameter(ID, searchId); | 132 notification.setParameter(ID, searchId); |
| 116 notification.setParameter(LAST, isLast); | 133 notification.setParameter(LAST, isLast); |
| 117 notification.setParameter(RESULTS, results); | 134 notification.setParameter(RESULTS, results); |
| 118 server.sendNotification(notification); | 135 server.sendNotification(notification); |
| 119 } | 136 } |
| 120 } | 137 } |
| OLD | NEW |