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

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

Issue 1953893004: Suggest 'var' and 'final' in intializer of 'for'. (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
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart
index 5ba7fa1c599bc6151fa5f91b3c4aad22b5bb2ed1..a79bb40a566e4318400067b31087c8377436a5c1 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/keyword_contributor.dart
@@ -9,12 +9,12 @@ import 'dart:async';
import 'package:analysis_server/plugin/protocol/protocol.dart';
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
+import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
+import 'package:analysis_server/src/services/completion/dart/optype.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/dart/ast/token.dart';
-import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
-import 'package:analysis_server/src/services/completion/dart/optype.dart';
const ASYNC = 'async';
const ASYNC_STAR = 'async*';
@@ -221,11 +221,19 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
@override
visitForStatement(ForStatement node) {
+ // Actual: for (va^)
+ // Parsed: for (va^; ;)
+ if (node.initialization == entity && entity is SimpleIdentifier) {
+ if (_isNextTokenSynthetic(entity, TokenType.SEMICOLON)) {
+ _addSuggestion(Keyword.VAR, DART_RELEVANCE_HIGH);
+ _addSuggestion(Keyword.FINAL, DART_RELEVANCE_HIGH);
+ }
+ }
+ // Actual: for (int x i^)
+ // Parsed: for (int x; i^;)
// Handle the degenerate case while typing - for (int x i^)
if (node.condition == entity && entity is SimpleIdentifier) {
- Token entityToken = (entity as SimpleIdentifier).beginToken;
- if (entityToken.previous.isSynthetic &&
- entityToken.previous.type == TokenType.SEMICOLON) {
+ if (_isPreviousTokenSynthetic(entity, TokenType.SEMICOLON)) {
_addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH);
}
}
@@ -570,4 +578,22 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
bool _inWhileLoop(AstNode node) =>
node.getAncestor((p) => p is WhileStatement) != null;
+
+ static bool _isNextTokenSynthetic(Object entity, TokenType type) {
+ if (entity is AstNode) {
+ Token token = entity.beginToken;
+ Token nextToken = token.next;
+ return nextToken.isSynthetic && nextToken.type == type;
+ }
+ return false;
+ }
+
+ static bool _isPreviousTokenSynthetic(Object entity, TokenType type) {
+ if (entity is AstNode) {
+ Token token = entity.beginToken;
+ Token previousToken = token.previous;
+ return previousToken.isSynthetic && previousToken.type == type;
+ }
+ return false;
+ }
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698