| 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.dart.toplevel; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_services/completion/completion_computer.dart'; | |
| 10 import 'package:analysis_services/completion/completion_suggestion.dart'; | |
| 11 import 'package:analysis_services/search/search_engine.dart'; | |
| 12 import 'package:analyzer/src/generated/ast.dart'; | |
| 13 import 'package:analyzer/src/generated/element.dart'; | |
| 14 | |
| 15 /** | |
| 16 * A computer for calculating class and top level variable | |
| 17 * `completion.getSuggestions` request results | |
| 18 */ | |
| 19 class TopLevelComputer extends CompletionComputer { | |
| 20 | |
| 21 @override | |
| 22 bool computeFast(CompilationUnit unit, | |
| 23 List<CompletionSuggestion> suggestions) { | |
| 24 // TODO: implement computeFast | |
| 25 return false; | |
| 26 } | |
| 27 | |
| 28 @override | |
| 29 Future<bool> computeFull(CompilationUnit unit, | |
| 30 List<CompletionSuggestion> suggestions) { | |
| 31 var future = searchEngine.searchTopLevelDeclarations(''); | |
| 32 return future.then((List<SearchMatch> matches) { | |
| 33 | |
| 34 // Compute the set of visible libraries to determine relevance | |
| 35 var visibleLibraries = new Set<LibraryElement>(); | |
| 36 var unitLibrary = unit.element.library; | |
| 37 visibleLibraries.add(unitLibrary); | |
| 38 visibleLibraries.addAll(unitLibrary.importedLibraries); | |
| 39 | |
| 40 // Compute the set of possible classes and top level variables | |
| 41 matches.forEach((SearchMatch match) { | |
| 42 if (match.kind == MatchKind.DECLARATION) { | |
| 43 Element element = match.element; | |
| 44 if (element.isPublic || element.library == unitLibrary) { | |
| 45 String completion = element.displayName; | |
| 46 var relevance = visibleLibraries.contains(element.library) ? | |
| 47 CompletionRelevance.DEFAULT : | |
| 48 CompletionRelevance.LOW; | |
| 49 suggestions.add( | |
| 50 new CompletionSuggestion( | |
| 51 CompletionSuggestionKind.fromElementKind(element.kind), | |
| 52 relevance, | |
| 53 completion, | |
| 54 completion.length, | |
| 55 0, | |
| 56 element.isDeprecated, | |
| 57 false // isPotential | |
| 58 )); | |
| 59 } | |
| 60 } | |
| 61 }); | |
| 62 return true; | |
| 63 }); | |
| 64 } | |
| 65 } | |
| OLD | NEW |