Chromium Code Reviews| Index: pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart |
| diff --git a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart |
| index f2a5f322fa0072940d313c6ded37f8156ab70105..95db11c024434aa076c5ec9a870f5238b34b41d2 100644 |
| --- a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart |
| +++ b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart |
| @@ -173,7 +173,22 @@ class StatementCompletionProcessor { |
| return NO_COMPLETION; |
| } |
| // TODO(messick): This needs to work for declarations. |
| - node = node.getAncestor((n) => n is Statement); |
| + AstNode newNode = node.getAncestor((n) => n is Statement); |
| + if (newNode is Block) { |
| + Block blockNode = newNode; |
| + if (blockNode.statements.isNotEmpty) { |
| + node = blockNode.statements[blockNode.statements.length - 1]; |
|
scheglov
2017/04/24 18:52:33
blockNode.statements.last
|
| + } else { |
| + newNode = node.getAncestor((n) => n is CatchClause); |
| + if (newNode != null) { |
| + node = newNode.parent; |
| + } else { |
| + node = node.getAncestor((n) => n is Statement).parent; |
| + } |
| + } |
| + } else { |
| + node = newNode; |
| + } |
| if (_isEmptyStatement(node)) { |
| node = node.parent; |
| } |
| @@ -662,7 +677,7 @@ class StatementCompletionProcessor { |
| _appendEmptyBraces(sb, true); |
| _insertBuilder(sb); |
| sb = null; |
| - } else if ((catchNode = _firstInvalidCatch(tryNode.catchClauses)) != null) { |
| + } else if ((catchNode = _findInvalidCatch(tryNode.catchClauses)) != null) { |
| if (catchNode.onKeyword != null) { |
| if (catchNode.exceptionType.length == 0) { |
| String src = utils.getNodeText(catchNode); |
| @@ -756,19 +771,12 @@ class StatementCompletionProcessor { |
| return null; |
| } |
| - CatchClause _firstInvalidCatch(NodeList<CatchClause> list) { |
| - return list.firstWhere((e) { |
| - bool found = false; |
| - for (var error in errors) { |
| - if (error.offset >= e.offset && error.offset <= e.end) { |
| - if (error.errorCode is! HintCode) { |
| - found = true; |
| - break; |
| - } |
| - } |
| - } |
| - return found; |
| - }, orElse: () => null); |
| + CatchClause _findInvalidCatch(NodeList<CatchClause> list) { |
| + return list.firstWhere( |
| + (catchClause) => |
| + selectionOffset >= catchClause.offset && |
| + selectionOffset <= catchClause.end, |
| + orElse: () => null); |
| } |
| LinkedEditGroup _getLinkedPosition(String groupId) { |