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