| 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 services.completion.computer.toplevel; | 5 library services.completion.computer.toplevel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_services/completion/completion_computer.dart'; |
| 9 import 'package:analysis_services/completion/completion_suggestion.dart'; | 10 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| 10 import 'package:analysis_services/search/search_engine.dart'; | 11 import 'package:analysis_services/search/search_engine.dart'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * A computer for `completion.getSuggestions` request results. | 15 * A computer for `completion.getSuggestions` request results. |
| 15 */ | 16 */ |
| 16 class TopLevelComputer { | 17 class TopLevelComputer extends CompletionComputer { |
| 17 final SearchEngine searchEngine; | 18 final SearchEngine searchEngine; |
| 18 | 19 |
| 19 TopLevelComputer(this.searchEngine); | 20 TopLevelComputer(this.searchEngine); |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Computes [CompletionSuggestion]s for the specified position in the source. | 23 * Computes [CompletionSuggestion]s for the specified position in the source. |
| 23 */ | 24 */ |
| 24 Future<List<CompletionSuggestion>> compute() { | 25 Future<List<CompletionSuggestion>> compute() { |
| 25 var future = searchEngine.searchTopLevelDeclarations(''); | 26 var future = searchEngine.searchTopLevelDeclarations(''); |
| 26 return future.then((List<SearchMatch> matches) { | 27 return future.then((List<SearchMatch> matches) { |
| 27 return matches.map((SearchMatch match) { | 28 return matches.map((SearchMatch match) { |
| 28 Element element = match.element; | 29 Element element = match.element; |
| 29 String completion = element.displayName; | 30 String completion = element.displayName; |
| 30 return new CompletionSuggestion( | 31 return new CompletionSuggestion( |
| 31 CompletionSuggestionKind.fromElementKind(element.kind), | 32 CompletionSuggestionKind.fromElementKind(element.kind), |
| 32 CompletionRelevance.DEFAULT, | 33 CompletionRelevance.DEFAULT, |
| 33 completion, | 34 completion, |
| 34 completion.length, | 35 completion.length, |
| 35 0, | 36 0, |
| 36 element.isDeprecated, | 37 element.isDeprecated, |
| 37 false // isPotential | 38 false // isPotential |
| 38 ); | 39 ); |
| 39 }).toList(); | 40 }).toList(); |
| 40 }); | 41 }); |
| 41 } | 42 } |
| 42 } | 43 } |
| OLD | NEW |