Chromium Code Reviews| Index: pkg/analysis_services/lib/src/completion/top_level_computer.dart |
| diff --git a/pkg/analysis_services/lib/src/completion/top_level_computer.dart b/pkg/analysis_services/lib/src/completion/top_level_computer.dart |
| index 9688a8272ad3eeff3e78058ab9be37cf6262507d..d725b8e96cab4140e0ab235a0f00110ab4e26fe5 100644 |
| --- a/pkg/analysis_services/lib/src/completion/top_level_computer.dart |
| +++ b/pkg/analysis_services/lib/src/completion/top_level_computer.dart |
| @@ -9,15 +9,18 @@ import 'dart:async'; |
| import 'package:analysis_services/completion/completion_computer.dart'; |
| import 'package:analysis_services/completion/completion_suggestion.dart'; |
| import 'package:analysis_services/search/search_engine.dart'; |
| +import 'package:analyzer/src/generated/ast.dart'; |
| import 'package:analyzer/src/generated/element.dart'; |
| /** |
| - * A computer for `completion.getSuggestions` request results. |
| + * A computer for calculating class and top level variable |
| + * `completion.getSuggestions` request results |
| */ |
| class TopLevelComputer extends CompletionComputer { |
| final SearchEngine searchEngine; |
| + final CompilationUnit unit; |
| - TopLevelComputer(this.searchEngine); |
| + TopLevelComputer(this.searchEngine, this.unit); |
| /** |
| * Computes [CompletionSuggestion]s for the specified position in the source. |
| @@ -25,19 +28,34 @@ class TopLevelComputer extends CompletionComputer { |
| Future<List<CompletionSuggestion>> compute() { |
| var future = searchEngine.searchTopLevelDeclarations(''); |
| return future.then((List<SearchMatch> matches) { |
| - return matches.map((SearchMatch match) { |
| - Element element = match.element; |
| - String completion = element.displayName; |
| - return new CompletionSuggestion( |
| - CompletionSuggestionKind.fromElementKind(element.kind), |
| - CompletionRelevance.DEFAULT, |
| - completion, |
| - completion.length, |
| - 0, |
| - element.isDeprecated, |
| - false // isPotential |
| - ); |
| - }).toList(); |
| + |
| + // Compute the set of visible libraries to determine relevance |
| + var visibleLibraries = new Set<LibraryElement>(); |
| + visibleLibraries.add(unit.element.library); |
| + visibleLibraries.addAll(unit.element.library.importedLibraries); |
| + |
| + // Compute the set of possible classes and top level variables |
|
scheglov
2014/08/07 02:42:25
and functions?
and function type aliases?
danrubel
2014/08/08 20:28:39
Yes, it should already include functions. I'll add
|
| + var suggestions = new List<CompletionSuggestion>(); |
| + matches.forEach((SearchMatch match) { |
| + if (match.kind == MatchKind.DECLARATION) { |
| + Element element = match.element; |
| + String completion = element.displayName; |
| + suggestions.add( |
| + new CompletionSuggestion( |
| + CompletionSuggestionKind.fromElementKind(element.kind), |
| + visibleLibraries.contains(element.library) ? |
| + CompletionRelevance.DEFAULT : |
| + CompletionRelevance.LOW, |
| + completion, |
| + completion.length, |
| + 0, |
| + element.isDeprecated, |
| + false // isPotential |
| + )); |
| + } |
| + }); |
| + return suggestions; |
| }); |
| } |
| + |
| } |