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

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

Issue 2662973007: suggest catch and finally keywords (Closed)
Patch Set: merge Created 3 years, 10 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/lib/src/services/completion/dart/optype.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 5a8d8cbacf4ca3c93dde5a0f41d88f2da699b76c..ee485ffe846bc698b47a46636b981fa7a9045f88 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
@@ -88,6 +88,20 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
@override
visitBlock(Block node) {
+ Statement prevStmt = OpType.getPreviousStatement(node, entity);
+ if (prevStmt is TryStatement) {
+ if (prevStmt.finallyBlock == null) {
+ _addSuggestion2('on');
+ _addSuggestion(Keyword.CATCH);
+ _addSuggestion(Keyword.FINALLY);
+ if (prevStmt.catchClauses.isEmpty) {
+ // If try statement with no catch, on, or finally
+ // then only suggest these keywords
+ return;
+ }
+ }
+ }
+
if (entity is ExpressionStatement) {
Expression expression = (entity as ExpressionStatement).expression;
if (expression is SimpleIdentifier) {
@@ -411,6 +425,18 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
}
@override
+ visitTryStatement(TryStatement node) {
+ var obj = entity;
+ if (obj is CatchClause ||
+ (obj is KeywordToken && obj.value() == Keyword.FINALLY)) {
+ _addSuggestion2('on');
+ _addSuggestion(Keyword.CATCH);
+ return null;
+ }
+ return visitStatement(node);
+ }
+
+ @override
visitVariableDeclaration(VariableDeclaration node) {
if (entity == node.initializer) {
_addExpressionKeywords(node);
@@ -467,7 +493,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
Keyword.TRUE,
]);
if (_inClassMemberBody(node)) {
- _addSuggestions([Keyword.SUPER, Keyword.THIS,]);
+ _addSuggestions([Keyword.SUPER, Keyword.THIS]);
}
if (_inAsyncMethodOrFunction(node)) {
_addSuggestion2(AWAIT);
@@ -497,7 +523,7 @@ class _KeywordVisitor extends GeneralizingAstVisitor {
void _addStatementKeywords(AstNode node) {
if (_inClassMemberBody(node)) {
- _addSuggestions([Keyword.SUPER, Keyword.THIS,]);
+ _addSuggestions([Keyword.SUPER, Keyword.THIS]);
}
if (_inAsyncMethodOrFunction(node)) {
_addSuggestion2(AWAIT);
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart/optype.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698