| 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 domain.completion; | 5 library domain.completion; |
| 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/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| 11 import 'package:analysis_server/src/protocol.dart'; | 11 import 'package:analysis_server/src/protocol.dart'; |
| 12 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| 13 import 'package:analysis_services/constants.dart'; |
| 12 import 'package:analysis_services/search/search_engine.dart'; | 14 import 'package:analysis_services/search/search_engine.dart'; |
| 13 import 'package:analysis_server/src/collections.dart'; | 15 import 'package:analyzer/src/generated/element.dart'; |
| 14 | 16 |
| 15 /** | 17 /** |
| 16 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] | 18 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] |
| 17 * that handles requests in the search domain. | 19 * that handles requests in the search domain. |
| 18 */ | 20 */ |
| 19 class CompletionDomainHandler implements RequestHandler { | 21 class CompletionDomainHandler implements RequestHandler { |
| 20 /** | 22 /** |
| 21 * The analysis server that is using this handler to process requests. | 23 * The analysis server that is using this handler to process requests. |
| 22 */ | 24 */ |
| 23 final AnalysisServer server; | 25 final AnalysisServer server; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 85 |
| 84 TopLevelSuggestionsComputer(this.searchEngine); | 86 TopLevelSuggestionsComputer(this.searchEngine); |
| 85 | 87 |
| 86 /** | 88 /** |
| 87 * Computes [CompletionSuggestion]s for the specified position in the source. | 89 * Computes [CompletionSuggestion]s for the specified position in the source. |
| 88 */ | 90 */ |
| 89 Future<List<CompletionSuggestion>> compute() { | 91 Future<List<CompletionSuggestion>> compute() { |
| 90 var future = searchEngine.searchTopLevelDeclarations(''); | 92 var future = searchEngine.searchTopLevelDeclarations(''); |
| 91 return future.then((List<SearchMatch> matches) { | 93 return future.then((List<SearchMatch> matches) { |
| 92 return matches.map((SearchMatch match) { | 94 return matches.map((SearchMatch match) { |
| 93 return new CompletionSuggestion(match.element.displayName); | 95 Element element = match.element; |
| 96 String completion = element.displayName; |
| 97 return new CompletionSuggestion( |
| 98 CompletionSuggestionKind.fromElementKind(element.kind), |
| 99 CompletionRelevance.DEFAULT, |
| 100 completion, |
| 101 completion.length, |
| 102 0, |
| 103 element.isDeprecated, |
| 104 false // isPotential |
| 105 ); |
| 94 }).toList(); | 106 }).toList(); |
| 95 }); | 107 }); |
| 96 } | 108 } |
| 97 } | 109 } |
| 98 | |
| 99 /** | |
| 100 * A single completion suggestion. | |
| 101 */ | |
| 102 class CompletionSuggestion implements HasToJson { | |
| 103 final String completion; | |
| 104 | |
| 105 CompletionSuggestion(this.completion); | |
| 106 | |
| 107 factory CompletionSuggestion.fromJson(Map<String, Object> json) { | |
| 108 return new CompletionSuggestion(json[COMPLETION]); | |
| 109 } | |
| 110 | |
| 111 @override | |
| 112 Map<String, Object> toJson() { | |
| 113 return { | |
| 114 COMPLETION: completion | |
| 115 }; | |
| 116 } | |
| 117 } | |
| OLD | NEW |