Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: pkg/analysis_services/lib/src/completion/imported_type_computer.dart

Issue 458073002: rename and improve imported completion computer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_services/lib/src/completion/imported_type_computer.dart
diff --git a/pkg/analysis_services/lib/src/completion/top_level_computer.dart b/pkg/analysis_services/lib/src/completion/imported_type_computer.dart
similarity index 61%
rename from pkg/analysis_services/lib/src/completion/top_level_computer.dart
rename to pkg/analysis_services/lib/src/completion/imported_type_computer.dart
index 536e473776bea44f0408ba9b16fc4e65c540f7a8..8c04570805826078bafaba08129c4050d875c875 100644
--- a/pkg/analysis_services/lib/src/completion/top_level_computer.dart
+++ b/pkg/analysis_services/lib/src/completion/imported_type_computer.dart
@@ -13,15 +13,18 @@ import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
/**
- * A computer for calculating class and top level variable
- * `completion.getSuggestions` request results
+ * A computer for calculating imported class and top level variable
+ * `completion.getSuggestions` request results.
*/
-class TopLevelComputer extends CompletionComputer {
+class ImportedTypeComputer extends CompletionComputer {
@override
bool computeFast(CompilationUnit unit,
List<CompletionSuggestion> suggestions) {
// TODO: implement computeFast
+ // - compute results based upon current search, then replace those results
+ // during the full compute phase
+ // - filter results based upon completion offset
return false;
}
@@ -31,17 +34,36 @@ class TopLevelComputer extends CompletionComputer {
var future = searchEngine.searchTopLevelDeclarations('');
return future.then((List<SearchMatch> matches) {
+ // Exclude elements from the local library
+ // which will be included by the LocalComputer
+
// Compute the set of visible libraries to determine relevance
var visibleLibraries = new Set<LibraryElement>();
+ var excludedLibraries = new Set<LibraryElement>();
var unitLibrary = unit.element.library;
- visibleLibraries.add(unitLibrary);
- visibleLibraries.addAll(unitLibrary.importedLibraries);
+ excludedLibraries.add(unitLibrary);
+ unitLibrary.importedLibraries.forEach((LibraryElement library) {
+ if (library.isDartCore) {
+ visibleLibraries.add(library);
+ }
+ });
+ unit.directives.forEach((Directive directive) {
+ if (directive is ImportDirective) {
+ LibraryElement library = directive.element.importedLibrary;
+ if (directive.prefix == null) {
+ visibleLibraries.add(library);
+ } else {
+ excludedLibraries.add(library);
+ }
+ }
+ });
- // Compute the set of possible classes and top level variables
+ // Compute the set of possible classes, functions, and top level variables
matches.forEach((SearchMatch match) {
if (match.kind == MatchKind.DECLARATION) {
Element element = match.element;
- if (element.isPublic || element.library == unitLibrary) {
+ if (element.isPublic &&
+ !excludedLibraries.contains(element.library)) {
String completion = element.displayName;
var relevance = visibleLibraries.contains(element.library) ?
CompletionRelevance.DEFAULT :

Powered by Google App Engine
This is Rietveld 408576698