Chromium Code Reviews| Index: pkg/analysis_server/lib/src/domain_completion.dart |
| diff --git a/pkg/analysis_server/lib/src/domain_completion.dart b/pkg/analysis_server/lib/src/domain_completion.dart |
| index cfb68816f08d527981782108833269ba6b7f5f9d..1ea2a9c49730506355f9d20c098c7077aa6cc0b5 100644 |
| --- a/pkg/analysis_server/lib/src/domain_completion.dart |
| +++ b/pkg/analysis_server/lib/src/domain_completion.dart |
| @@ -4,9 +4,13 @@ |
| library domain.completion; |
| +import 'dart:async'; |
| + |
| import 'package:analysis_server/src/analysis_server.dart'; |
| import 'package:analysis_server/src/constants.dart'; |
| import 'package:analysis_server/src/protocol.dart'; |
| +import 'package:analysis_services/search/search_engine.dart'; |
| +import 'package:analysis_server/src/collections.dart'; |
| /** |
| * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] |
| @@ -19,6 +23,16 @@ class CompletionDomainHandler implements RequestHandler { |
| final AnalysisServer server; |
| /** |
| + * The [SearchEngine] for this server. |
| + */ |
| + SearchEngine searchEngine; |
| + |
| + /** |
| + * The next searc response id. |
|
scheglov
2014/07/17 20:40:00
The comment has couple nits: "searc" is an incompl
danrubel
2014/07/17 21:01:14
Done.
|
| + */ |
| + int _nextCompletionId = 0; |
| + |
| + /** |
| * Initialize a newly created handler to handle requests for the given [server]. |
| */ |
| CompletionDomainHandler(this.server); |
| @@ -43,7 +57,64 @@ class CompletionDomainHandler implements RequestHandler { |
| // offset |
| RequestDatum offsetDatum = request.getRequiredParameter(OFFSET); |
| int offset = offsetDatum.asInt(); |
| - // TODO(brianwilkerson) implement |
| - return null; |
| + // schedule completion analysis |
| + String completionId = (_nextCompletionId++).toString(); |
| + var computer = new TopLevelSuggestionsComputer(server.searchEngine); |
| + var future = computer.compute(); |
| + future.then((List<CompletionSuggestion> results) { |
| + _sendSearchNotification(completionId, true, results); |
| + }); |
| + // respond |
| + return new Response(request.id)..setResult(ID, completionId); |
| + } |
| + |
| + void _sendSearchNotification(String completionId, bool isLast, |
|
scheglov
2014/07/17 20:39:59
_secondCompletionNotification?
danrubel
2014/07/17 21:01:14
Done.
|
| + Iterable<CompletionSuggestion> results) { |
| + Notification notification = new Notification(COMPLETION_RESULTS); |
| + notification.setParameter(ID, completionId); |
| + notification.setParameter(LAST, isLast); |
| + notification.setParameter(RESULTS, results); |
| + server.sendNotification(notification); |
| + } |
| +} |
| + |
| +/** |
| + * A computer for `completion.getSuggestions` request results. |
| + */ |
| +class TopLevelSuggestionsComputer { |
|
scheglov
2014/07/17 20:40:00
Make it private?
danrubel
2014/07/17 21:01:14
I didn't bother because I envision more of these a
|
| + final SearchEngine searchEngine; |
| + |
| + TopLevelSuggestionsComputer(this.searchEngine); |
| + |
| + /** |
| + * Computes [CompletionSuggestion]s for the specified position in the source. |
| + */ |
| + Future<List<CompletionSuggestion>> compute() { |
| + var future = searchEngine.searchTopLevelDeclarations(''); |
|
scheglov
2014/07/17 20:40:00
Should we use an existing prefix here?
danrubel
2014/07/17 21:01:14
I want to return the complete list and let the cli
scheglov
2014/07/17 21:09:32
OK, good point.
|
| + return future.then((List<SearchMatch> matches) { |
| + return matches.map((SearchMatch match) { |
| + return new CompletionSuggestion(match.element.displayName); |
| + }).toList(); |
| + }); |
| + } |
| +} |
| + |
| +/** |
| + * A single completion suggestion. |
| + */ |
| +class CompletionSuggestion implements HasToJson { |
| + final String completion; |
| + |
| + CompletionSuggestion(this.completion); |
| + |
| + factory CompletionSuggestion.fromJson(Map<String, Object> json) { |
| + return new CompletionSuggestion(json[COMPLETION]); |
| + } |
| + |
| + @override |
| + Map<String, Object> toJson() { |
| + return { |
| + COMPLETION: completion |
| + }; |
| } |
| } |