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

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart

Issue 972933002: add arguments to constructor completions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix tests Created 5 years, 10 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_server/lib/src/services/completion/dart_completion_cache.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart b/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
index 4dd795c1554796e364db23d9d5c76c8200a8014c..45d85fc6b89b13b8d0c69b59a6f5d08fd0da1152 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart
@@ -56,6 +56,12 @@ class DartCompletionCache extends CompletionCache {
List<CompletionSuggestion> otherImportedSuggestions;
/**
+ * Suggestions for constructors
+ * or `null` if nothing has been cached.
+ */
+ List<CompletionSuggestion> importedConstructorSuggestions;
+
+ /**
* A collection of all imported completions
* or `null` if nothing has been cached.
*/
@@ -111,6 +117,7 @@ class DartCompletionCache extends CompletionCache {
importedTypeSuggestions = <CompletionSuggestion>[];
libraryPrefixSuggestions = <CompletionSuggestion>[];
otherImportedSuggestions = <CompletionSuggestion>[];
+ importedConstructorSuggestions = <CompletionSuggestion>[];
importedVoidReturnSuggestions = <CompletionSuggestion>[];
importedClassMap = new Map<String, ClassElement>();
_importedCompletions = new HashSet<String>();
@@ -168,6 +175,25 @@ class DartCompletionCache extends CompletionCache {
_importKey != null && _importKey == _computeImportKey(unit);
/**
+ * Add constructor suggestions for the given class.
+ */
+ void _addConstructorSuggestions(ClassElement classElem, int relevance) {
+ String className = classElem.name;
+ for (ConstructorElement constructor in classElem.constructors) {
+ if (!constructor.isPrivate) {
+ CompletionSuggestion suggestion =
+ createSuggestion(constructor, relevance: relevance);
+ String name = suggestion.completion;
+ name = name.length > 0 ? '$className.$name' : className;
+ suggestion.completion = name;
+ suggestion.element.name = name;
+ suggestion.selectionOffset = suggestion.completion.length;
+ importedConstructorSuggestions.add(suggestion);
+ }
+ }
+ }
+
+ /**
* Add suggestions for implicitly imported elements in dart:core.
*/
void _addDartCoreSuggestions() {
@@ -282,6 +308,7 @@ class DartCompletionCache extends CompletionCache {
}
} else if (element is ClassElement) {
importedTypeSuggestions.add(suggestion);
+ _addConstructorSuggestions(element, relevance);
} else {
otherImportedSuggestions.add(suggestion);
}

Powered by Google App Engine
This is Rietveld 408576698