Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: pkg/analysis_server/lib/src/search/search_domain.dart

Issue 529123002: Make findElementReferences' "id" result optional. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
8
9 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart' as protocol; 9 import 'package:analysis_server/src/protocol.dart' as protocol;
12 import 'package:analysis_server/src/search/element_references.dart'; 10 import 'package:analysis_server/src/search/element_references.dart';
13 import 'package:analysis_server/src/search/type_hierarchy.dart'; 11 import 'package:analysis_server/src/search/type_hierarchy.dart';
14 import 'package:analysis_server/src/services/search/search_engine.dart'; 12 import 'package:analysis_server/src/services/search/search_engine.dart';
15 import 'package:analyzer/src/generated/element.dart'; 13 import 'package:analyzer/src/generated/element.dart';
16 14
17 /** 15 /**
18 * Instances of the class [SearchDomainHandler] implement a [RequestHandler] 16 * Instances of the class [SearchDomainHandler] implement a [RequestHandler]
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // schedule search 56 // schedule search
59 String searchId = (_nextSearchId++).toString(); 57 String searchId = (_nextSearchId++).toString();
60 elements.forEach((Element element) { 58 elements.forEach((Element element) {
61 var computer = new ElementReferencesComputer(searchEngine); 59 var computer = new ElementReferencesComputer(searchEngine);
62 var future = computer.compute(element, params.includePotential); 60 var future = computer.compute(element, params.includePotential);
63 future.then((List<protocol.SearchResult> results) { 61 future.then((List<protocol.SearchResult> results) {
64 bool isLast = identical(element, elements.last); 62 bool isLast = identical(element, elements.last);
65 _sendSearchNotification(searchId, isLast, results); 63 _sendSearchNotification(searchId, isLast, results);
66 }); 64 });
67 }); 65 });
66 // respond
68 if (elements.isEmpty) { 67 if (elements.isEmpty) {
69 new Future.microtask(() { 68 return new protocol.SearchFindElementReferencesResult().toResponse(
70 _sendSearchNotification(searchId, true, []); 69 request.id);
71 }); 70 } else {
71 protocol.Element element = new protocol.Element.fromEngine(elements[0]);
72 return new protocol.SearchFindElementReferencesResult(id: searchId,
73 element: element).toResponse(request.id);
72 } 74 }
73 // respond
74 protocol.Element element;
75 if (elements.isNotEmpty) {
76 element = new protocol.Element.fromEngine(elements[0]);
77 }
78 return new protocol.SearchFindElementReferencesResult(searchId,
79 element: element).toResponse(request.id);
80 } 75 }
81 76
82 protocol.Response findMemberDeclarations(protocol.Request request) { 77 protocol.Response findMemberDeclarations(protocol.Request request) {
83 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req uest); 78 var params = new protocol.SearchFindMemberDeclarationsParams.fromRequest(req uest);
84 // schedule search 79 // schedule search
85 String searchId = (_nextSearchId++).toString(); 80 String searchId = (_nextSearchId++).toString();
86 { 81 {
87 var matchesFuture = searchEngine.searchMemberDeclarations(params.name); 82 var matchesFuture = searchEngine.searchMemberDeclarations(params.name);
88 matchesFuture.then((List<SearchMatch> matches) { 83 matchesFuture.then((List<SearchMatch> matches) {
89 _sendSearchNotification(searchId, true, matches.map(toResult)); 84 _sendSearchNotification(searchId, true, matches.map(toResult));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 void _sendSearchNotification(String searchId, bool isLast, 169 void _sendSearchNotification(String searchId, bool isLast,
175 Iterable<protocol.SearchResult> results) { 170 Iterable<protocol.SearchResult> results) {
176 server.sendNotification(new protocol.SearchResultsParams(searchId, 171 server.sendNotification(new protocol.SearchResultsParams(searchId,
177 results.toList(), isLast).toNotification()); 172 results.toList(), isLast).toNotification());
178 } 173 }
179 174
180 static protocol.SearchResult toResult(SearchMatch match) { 175 static protocol.SearchResult toResult(SearchMatch match) {
181 return new protocol.SearchResult.fromMatch(match); 176 return new protocol.SearchResult.fromMatch(match);
182 } 177 }
183 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698