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

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

Issue 1953363002: Code completion improvement. Recommend all 'E.x' where E is an enum, also, filter out only the cor… (Closed) Base URL: sso://user/jwren/dart-lang@cc-27-enum-constant-completions-24759
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/optype.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
index 80b98d8b6e59efb751377834662814a6464c27b3..991ca5f3098e38ed3c4bead367b8f2b2b1346120 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -504,8 +504,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
if (_isEntityPrevTokenSynthetic()) {
// Actual: if (var v i^)
// Parsed: if (v) i^;
- } else if (identical(
- entity, node.condition)) {
+ } else if (identical(entity, node.condition)) {
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
} else if (identical(entity, node.thenStatement) ||
@@ -622,6 +621,16 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
optype.includeReturnValueSuggestions = true;
optype.returnValueSuggestionsFilter = (DartType dartType, int relevance) {
DartType type = node.element?.type;
+ bool isEnum = type != null &&
+ type.element is ClassElement &&
+ (type.element as ClassElement).isEnum;
+ if (isEnum) {
+ if (type == dartType) {
+ return relevance + DART_RELEVANCE_INCREMENT;
+ } else {
+ return null;
+ }
+ }
if (type != null &&
dartType != null &&
!type.isDynamic &&
@@ -848,8 +857,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
bool _isEntityPrevTokenSynthetic() {
Object entity = this.entity;
- if (entity is AstNode && entity.beginToken.previous?.isSynthetic ??
- false) {
+ if (entity is AstNode && entity.beginToken.previous?.isSynthetic ?? false) {
return true;
}
return false;

Powered by Google App Engine
This is Rietveld 408576698