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

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

Issue 1303233008: improve keyword suggestions - fixes #24016 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years, 4 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/completion_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/keyword_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart b/pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart
index 9c32f9f14b0dad568c2906e07a38e514b123e95b..6aa3536b327097b02ba1eb97dc9b6edafbc0c194 100644
--- a/pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart
@@ -157,8 +157,13 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
previous = previous.previous;
}
if (previous != null && previous.type == TokenType.EQ) {
- _addSuggestions(
- [Keyword.FALSE, Keyword.NEW, Keyword.NULL, Keyword.TRUE]);
+ _addSuggestions([
+ Keyword.CONST,
+ Keyword.FALSE,
+ Keyword.NEW,
+ Keyword.NULL,
+ Keyword.TRUE
+ ]);
} else {
_addSuggestion(Keyword.IN, DART_RELEVANCE_HIGH);
}
@@ -232,6 +237,15 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
}
@override
+ visitIsExpression(IsExpression node) {
+ if (entity == node.isOperator) {
+ _addSuggestion(Keyword.IS, DART_RELEVANCE_HIGH);
+ } else {
+ _addExpressionKeywords(node);
+ }
+ }
+
+ @override
visitLibraryIdentifier(LibraryIdentifier node) {
// no suggestions
}
@@ -367,7 +381,13 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
}
void _addExpressionKeywords(AstNode node) {
- _addSuggestions([Keyword.FALSE, Keyword.NEW, Keyword.NULL, Keyword.TRUE,]);
+ _addSuggestions([
+ Keyword.CONST,
+ Keyword.FALSE,
+ Keyword.NEW,
+ Keyword.NULL,
+ Keyword.TRUE,
+ ]);
if (_inClassMemberBody(node)) {
_addSuggestions([Keyword.SUPER, Keyword.THIS,]);
}
@@ -404,9 +424,15 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
if (_inAsyncMethodOrFunction(node)) {
_addSuggestion2(AWAIT);
}
+ if (_inLoop(node)) {
+ _addSuggestions([Keyword.BREAK, Keyword.CONTINUE]);
+ }
+ if (_inSwitch(node)) {
+ _addSuggestions([Keyword.BREAK]);
+ }
_addSuggestions([
Keyword.ASSERT,
- Keyword.CONTINUE,
+ Keyword.CONST,
Keyword.DO,
Keyword.FINAL,
Keyword.FOR,
@@ -434,8 +460,13 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
offset = completion.length;
}
request.addSuggestion(new CompletionSuggestion(
- CompletionSuggestionKind.KEYWORD, relevance, completion, offset, 0,
- false, false));
+ CompletionSuggestionKind.KEYWORD,
+ relevance,
+ completion,
+ offset,
+ 0,
+ false,
+ false));
}
void _addSuggestions(List<Keyword> keywords,
@@ -463,4 +494,20 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
node = parent;
}
}
+
+ bool _inDoLoop(AstNode node) =>
+ node.getAncestor((p) => p is DoStatement) != null;
+
+ bool _inForLoop(AstNode node) =>
+ node.getAncestor((p) => p is ForStatement || p is ForEachStatement) !=
+ null;
+
+ bool _inLoop(AstNode node) =>
+ _inDoLoop(node) || _inForLoop(node) || _inWhileLoop(node);
+
+ bool _inSwitch(AstNode node) =>
+ node.getAncestor((p) => p is SwitchStatement) != null;
+
+ bool _inWhileLoop(AstNode node) =>
+ node.getAncestor((p) => p is WhileStatement) != null;
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698