| 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_computer.dart'; |
| 10 import 'package:analysis_services/completion/completion_suggestion.dart'; | 10 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Computes [CompletionSuggestion]s for the specified position in the source. | 26 * Computes [CompletionSuggestion]s for the specified position in the source. |
| 27 */ | 27 */ |
| 28 Future<List<CompletionSuggestion>> compute() { | 28 Future<List<CompletionSuggestion>> compute() { |
| 29 var future = searchEngine.searchTopLevelDeclarations(''); | 29 var future = searchEngine.searchTopLevelDeclarations(''); |
| 30 return future.then((List<SearchMatch> matches) { | 30 return future.then((List<SearchMatch> matches) { |
| 31 | 31 |
| 32 // Compute the set of visible libraries to determine relevance | 32 // Compute the set of visible libraries to determine relevance |
| 33 var visibleLibraries = new Set<LibraryElement>(); | 33 var visibleLibraries = new Set<LibraryElement>(); |
| 34 visibleLibraries.add(unit.element.library); | 34 var unitLibrary = unit.element.library; |
| 35 visibleLibraries.addAll(unit.element.library.importedLibraries); | 35 visibleLibraries.add(unitLibrary); |
| 36 visibleLibraries.addAll(unitLibrary.importedLibraries); |
| 36 | 37 |
| 37 // Compute the set of possible classes and top level variables | 38 // Compute the set of possible classes and top level variables |
| 38 var suggestions = new List<CompletionSuggestion>(); | 39 var suggestions = new List<CompletionSuggestion>(); |
| 39 matches.forEach((SearchMatch match) { | 40 matches.forEach((SearchMatch match) { |
| 40 if (match.kind == MatchKind.DECLARATION) { | 41 if (match.kind == MatchKind.DECLARATION) { |
| 41 Element element = match.element; | 42 Element element = match.element; |
| 42 String completion = element.displayName; | 43 if (element.isPublic || element.library == unitLibrary) { |
| 43 suggestions.add( | 44 String completion = element.displayName; |
| 44 new CompletionSuggestion( | 45 var relevance = visibleLibraries.contains(element.library) ? |
| 45 CompletionSuggestionKind.fromElementKind(element.kind), | 46 CompletionRelevance.DEFAULT : |
| 46 visibleLibraries.contains(element.library) ? | 47 CompletionRelevance.LOW; |
| 47 CompletionRelevance.DEFAULT : | 48 suggestions.add( |
| 48 CompletionRelevance.LOW, | 49 new CompletionSuggestion( |
| 49 completion, | 50 CompletionSuggestionKind.fromElementKind(element.kind), |
| 50 completion.length, | 51 relevance, |
| 51 0, | 52 completion, |
| 52 element.isDeprecated, | 53 completion.length, |
| 53 false // isPotential | 54 0, |
| 54 )); | 55 element.isDeprecated, |
| 56 false // isPotential |
| 57 )); |
| 58 } |
| 55 } | 59 } |
| 56 }); | 60 }); |
| 57 return suggestions; | 61 return suggestions; |
| 58 }); | 62 }); |
| 59 } | 63 } |
| 60 | 64 |
| 61 } | 65 } |
| OLD | NEW |