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

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

Issue 2842523002: Fix detection of bad catch-clauses and try-statements (Closed)
Patch Set: Created 3 years, 8 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/statement/statement_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/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) {
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/completion/statement/statement_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698