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

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

Issue 1968883002: Improve completion after IfStatement. (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 833b0ecda2ffde74ba691f61407a9f0dd0a405ed..6b328b2a8f302203e893fe3adb8d1fd55d67ae10 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
@@ -265,7 +265,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
// Actual: if (x i^)
// Parsed: if (x) i^
_addSuggestion(Keyword.IS, DART_RELEVANCE_HIGH);
- } else if (entity == node.thenStatement) {
+ } else if (entity == node.thenStatement || entity == node.elseStatement) {
_addStatementKeywords(node);
} else if (entity == node.condition) {
_addExpressionKeywords(node);
@@ -502,6 +502,9 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
if (_inSwitch(node)) {
_addSuggestions([Keyword.BREAK]);
}
+ if (_isEntityAfterIfWithoutElse(node)) {
+ _addSuggestions([Keyword.ELSE]);
+ }
_addSuggestions([
Keyword.ASSERT,
Keyword.CONST,
@@ -584,6 +587,30 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
bool _inWhileLoop(AstNode node) =>
node.getAncestor((p) => p is WhileStatement) != null;
+ bool _isEntityAfterIfWithoutElse(AstNode node) {
+ Block block = node?.getAncestor((n) => n is Block);
+ if (block == null) {
+ return false;
+ }
+ Object entity = this.entity;
+ if (entity is Statement) {
+ int entityIndex = block.statements.indexOf(entity);
+ if (entityIndex > 0) {
+ Statement prevStatement = block.statements[entityIndex - 1];
+ return prevStatement is IfStatement &&
+ prevStatement.elseStatement == null;
+ }
+ }
+ if (entity is Token) {
+ for (Statement statement in block.statements) {
+ if (statement.endToken.next == entity) {
+ return statement is IfStatement && statement.elseStatement == null;
+ }
+ }
+ }
+ return false;
+ }
+
static bool _isNextTokenSynthetic(Object entity, TokenType type) {
if (entity is AstNode) {
Token token = entity.beginToken;
« 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