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

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

Issue 1956813004: Fixes for completing 'for (var v in^)' and 'if (v is^)'. (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/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 e8cc82d7ceba25822c5dc0339a2c909078144abb..80b98d8b6e59efb751377834662814a6464c27b3 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -464,6 +464,11 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@override
void visitForStatement(ForStatement node) {
+ if (_isEntityPrevTokenSynthetic()) {
+ // Actual: for (var v i^)
+ // Parsed: for (var i; i^;)
+ return;
+ }
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
optype.includeVoidReturnSuggestions = true;
@@ -496,7 +501,11 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@override
void visitIfStatement(IfStatement node) {
- if (identical(entity, node.condition)) {
+ if (_isEntityPrevTokenSynthetic()) {
+ // Actual: if (var v i^)
+ // Parsed: if (v) i^;
+ } else if (identical(
+ entity, node.condition)) {
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
} else if (identical(entity, node.thenStatement) ||
@@ -765,6 +774,16 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
}
@override
+ void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
+ if (entity is Token) {
+ Token token = entity;
+ if (token.isSynthetic || token.lexeme == ';') {
+ optype.includeVarNameSuggestions = true;
+ }
+ }
+ }
+
+ @override
void visitTypeArgumentList(TypeArgumentList node) {
NodeList<TypeName> arguments = node.arguments;
for (TypeName typeName in arguments) {
@@ -817,16 +836,6 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
}
@override
- void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
- if (entity is Token) {
- Token token = entity;
- if (token.isSynthetic || token.lexeme == ';') {
- optype.includeVarNameSuggestions = true;
- }
- }
- }
-
- @override
void visitVariableDeclarationStatement(VariableDeclarationStatement node) {}
@override
@@ -836,4 +845,13 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
optype.includeTypeNameSuggestions = true;
}
}
+
+ bool _isEntityPrevTokenSynthetic() {
+ Object entity = this.entity;
+ if (entity is AstNode && entity.beginToken.previous?.isSynthetic ??
+ false) {
+ return true;
+ }
+ return false;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698