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

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

Issue 1989393002: Code completion improvement. Recommend all 'E.x' where E is an enum, also, filter out only the cor… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/local_reference_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
index d9778a5698eb90c6572d8ad9ceb1ea4c3f5ba63a..7687117b36d54a71dbf15007a4ea95185733ee6e 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/local_reference_contributor.dart
@@ -256,6 +256,13 @@ class _LocalVisitor extends LocalDeclarationVisitor {
_addLocalSuggestion_includeTypeNameSuggestions(
declaration.name, NO_RETURN_TYPE, protocol.ElementKind.ENUM,
isDeprecated: _isDeprecated(declaration));
+ for (EnumConstantDeclaration enumConstant in declaration.constants) {
+ if (!enumConstant.isSynthetic) {
+ _addLocalSuggestion_includeReturnValueSuggestions_enumConstant(
+ enumConstant, declaration,
+ isDeprecated: _isDeprecated(declaration));
+ }
+ }
}
}
@@ -419,6 +426,42 @@ class _LocalVisitor extends LocalDeclarationVisitor {
}
}
+ void _addLocalSuggestion_enumConstant(
+ EnumConstantDeclaration constantDeclaration,
+ EnumDeclaration enumDeclaration,
+ {bool isAbstract: false,
+ bool isDeprecated: false,
+ ClassDeclaration classDecl,
+ int relevance: DART_RELEVANCE_DEFAULT}) {
+ String completion =
+ '${enumDeclaration.name.name}.${constantDeclaration.name.name}';
+ CompletionSuggestion suggestion = new CompletionSuggestion(
+ CompletionSuggestionKind.INVOCATION,
+ isDeprecated ? DART_RELEVANCE_LOW : relevance,
+ completion,
+ completion.length,
+ 0,
+ isDeprecated,
+ false,
+ returnType: enumDeclaration.name.name);
+
+ suggestionMap.putIfAbsent(suggestion.completion, () => suggestion);
+ int flags = protocol.Element.makeFlags(
+ isAbstract: isAbstract,
+ isDeprecated: isDeprecated,
+ isPrivate: Identifier.isPrivateName(constantDeclaration.name.name));
+ suggestion.element = new protocol.Element(
+ protocol.ElementKind.ENUM_CONSTANT,
+ constantDeclaration.name.name,
+ flags,
+ location: new Location(
+ request.source.fullName,
+ constantDeclaration.name.offset,
+ constantDeclaration.name.length,
+ 0,
+ 0));
+ }
+
void _addLocalSuggestion_includeReturnValueSuggestions(
SimpleIdentifier id, TypeName typeName, protocol.ElementKind elemKind,
{bool isAbstract: false,
@@ -438,6 +481,22 @@ class _LocalVisitor extends LocalDeclarationVisitor {
}
}
+ void _addLocalSuggestion_includeReturnValueSuggestions_enumConstant(
+ EnumConstantDeclaration constantDeclaration,
+ EnumDeclaration enumDeclaration,
+ {bool isAbstract: false,
+ bool isDeprecated: false,
+ int relevance: DART_RELEVANCE_DEFAULT}) {
+ relevance = optype.returnValueSuggestionsFilter(
+ enumDeclaration.element.type, relevance);
+ if (relevance != null) {
+ _addLocalSuggestion_enumConstant(constantDeclaration, enumDeclaration,
+ isAbstract: isAbstract,
+ isDeprecated: isDeprecated,
+ relevance: relevance);
+ }
+ }
+
void _addLocalSuggestion_includeTypeNameSuggestions(
SimpleIdentifier id, TypeName typeName, protocol.ElementKind elemKind,
{bool isAbstract: false,

Powered by Google App Engine
This is Rietveld 408576698