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

Unified Diff: pkg/analysis_server/lib/src/services/completion/dart/optype.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
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 dfc9ab90b67bc52929a94066c6212cfa2ea7f8f7..975e9107a6a3b1b10071758beb25929651fd09de 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -153,6 +153,22 @@ class OpType {
!includeNamedArgumentSuggestions &&
!includeReturnValueSuggestions &&
!includeVoidReturnSuggestions;
+
+ /// Return the statement before [entity]
+ /// where [entity] can be a statement or the `}` closing the given block.
+ static Statement getPreviousStatement(Block node, Object entity) {
+ if (entity == node.rightBracket) {
+ return node.statements.isNotEmpty ? node.statements.last : null;
+ }
+ if (entity is Statement) {
+ int index = node.statements.indexOf(entity);
+ if (index > 0) {
+ return node.statements[index - 1];
+ }
+ return null;
+ }
+ return null;
+ }
}
class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@@ -207,8 +223,7 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
// If unresolved, then include named arguments
optype.includeNamedArgumentSuggestions = true;
}
- } else
- if (parent is InvocationExpression) {
+ } else if (parent is InvocationExpression) {
Expression function = parent.function;
if (function is SimpleIdentifier) {
var elem = function.bestElement;
@@ -298,6 +313,12 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
@override
void visitBlock(Block node) {
+ Statement prevStmt = OpType.getPreviousStatement(node, entity);
+ if (prevStmt is TryStatement) {
+ if (prevStmt.catchClauses.isEmpty && prevStmt.finallyBlock == null) {
+ return;
+ }
+ }
optype.includeReturnValueSuggestions = true;
optype.includeTypeNameSuggestions = true;
optype.includeVoidReturnSuggestions = true;

Powered by Google App Engine
This is Rietveld 408576698