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

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

Issue 2936143002: update statement completion for fasta scanner (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/ast/utilities.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:math'; 6 import 'dart:math';
7 7
8 import 'package:analysis_server/src/protocol_server.dart' hide Element; 8 import 'package:analysis_server/src/protocol_server.dart' hide Element;
9 import 'package:analysis_server/src/services/correction/source_buffer.dart'; 9 import 'package:analysis_server/src/services/correction/source_buffer.dart';
10 import 'package:analysis_server/src/services/correction/util.dart'; 10 import 'package:analysis_server/src/services/correction/util.dart';
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 loc = newlineLoc + expr.offset; 322 loc = newlineLoc + expr.offset;
323 } else { 323 } else {
324 // add first char of src 324 // add first char of src
325 delimiter = content.substring(0, 1); 325 delimiter = content.substring(0, 1);
326 loc = expr.offset + source.length; 326 loc = expr.offset + source.length;
327 } 327 }
328 _removeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL); 328 _removeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL);
329 _addInsertEdit(loc, delimiter); 329 _addInsertEdit(loc, delimiter);
330 } 330 }
331 expr = errorMatching(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "']'"); 331 expr = errorMatching(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "']'");
332 if (expr == null) {
Brian Wilkerson 2017/06/14 04:14:31 You could also use `??` to avoid the extra weight
danrubel 2017/06/14 06:05:41 Good point. Done.
333 expr =
334 errorMatching(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "']'");
335 }
332 if (expr != null) { 336 if (expr != null) {
333 expr = expr.getAncestor((n) => n is ListLiteral); 337 expr = expr.getAncestor((n) => n is ListLiteral);
334 if (expr != null) { 338 if (expr != null) {
335 ListLiteral lit = expr; 339 ListLiteral lit = expr;
336 if (lit.rightBracket.isSynthetic) { 340 if (lit.rightBracket.isSynthetic) {
337 String src = utils.getNodeText(expr).trim(); 341 String src = utils.getNodeText(expr).trim();
338 int loc = expr.offset + src.length; 342 int loc = expr.offset + src.length;
339 if (src.contains(eol)) { 343 if (src.contains(eol)) {
340 String indent = utils.getNodePrefix(node); 344 String indent = utils.getNodePrefix(node);
341 _addInsertEdit(loc, ',' + eol + indent + ']'); 345 _addInsertEdit(loc, ',' + eol + indent + ']');
342 } else { 346 } else {
343 _addInsertEdit(loc, ']'); 347 _addInsertEdit(loc, ']');
344 } 348 }
345 _removeError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "']'"); 349 _removeError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "']'");
350 _removeError(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "']'");
346 var ms = 351 var ms =
347 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'"); 352 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'");
348 if (ms != null) { 353 if (ms != null) {
349 // Ensure the semicolon gets inserted in the correct location. 354 // Ensure the semicolon gets inserted in the correct location.
350 ms.offset = loc - 1; 355 ms.offset = loc - 1;
351 } 356 }
352 } 357 }
353 } 358 }
354 } 359 }
355 // The following code is similar to the code for ']' but does not work well. 360 // The following code is similar to the code for ']' but does not work well.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 outer is WhileStatement)) { 423 outer is WhileStatement)) {
419 return false; 424 return false;
420 } 425 }
421 int previousInsertions = _lengthOfInsertions(); 426 int previousInsertions = _lengthOfInsertions();
422 int delta = 0; 427 int delta = 0;
423 if (errors.isNotEmpty) { 428 if (errors.isNotEmpty) {
424 var error = 429 var error =
425 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'"); 430 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "';'");
426 if (error != null) { 431 if (error != null) {
427 int insertOffset; 432 int insertOffset;
428 if (expr == null || expr.isSynthetic) { 433 // Fasta scanner reports unterminated string literal errors
434 // and generates a synthetic string token with non-zero length.
435 // Because of this, check for length == 0 rather than isSynthetic.
Brian Wilkerson 2017/06/14 04:14:31 If `isSynthetic` doesn't always return a valid res
436 if (expr == null || expr.length == 0) {
429 if (node is ReturnStatement) { 437 if (node is ReturnStatement) {
430 insertOffset = (node as ReturnStatement).returnKeyword.end; 438 insertOffset = (node as ReturnStatement).returnKeyword.end;
431 } else if (node is ExpressionStatement) { 439 } else if (node is ExpressionStatement) {
432 insertOffset = 440 insertOffset =
433 ((node as ExpressionStatement).expression as ThrowExpression) 441 ((node as ExpressionStatement).expression as ThrowExpression)
434 .throwKeyword 442 .throwKeyword
435 .end; 443 .end;
436 } else { 444 } else {
437 insertOffset = node.end; // Not reached. 445 insertOffset = node.end; // Not reached.
438 } 446 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 831 }
824 } 832 }
825 } 833 }
826 return sb; 834 return sb;
827 } 835 }
828 836
829 bool _complete_methodCall() { 837 bool _complete_methodCall() {
830 var parenError = 838 var parenError =
831 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "')'"); 839 _findError(ParserErrorCode.EXPECTED_TOKEN, partialMatch: "')'");
832 if (parenError == null) { 840 if (parenError == null) {
841 parenError =
842 _findError(ScannerErrorCode.EXPECTED_TOKEN, partialMatch: "')'");
843 }
844 if (parenError == null) {
833 return false; 845 return false;
834 } 846 }
835 AstNode argList = _selectedNode(at: selectionOffset) 847 AstNode argList = _selectedNode(at: selectionOffset)
836 .getAncestor((n) => n is ArgumentList); 848 .getAncestor((n) => n is ArgumentList);
837 if (argList == null) { 849 if (argList == null) {
838 argList = _selectedNode(at: parenError.offset) 850 argList = _selectedNode(at: parenError.offset)
839 .getAncestor((n) => n is ArgumentList); 851 .getAncestor((n) => n is ArgumentList);
840 } 852 }
841 if (argList?.getAncestor((n) => n == node) == null) { 853 if (argList?.getAncestor((n) => n == node) == null) {
842 return false; 854 return false;
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 final Token keyword; 1245 final Token keyword;
1234 final Token leftParenthesis, rightParenthesis; 1246 final Token leftParenthesis, rightParenthesis;
1235 final Expression condition; 1247 final Expression condition;
1236 final Statement block; 1248 final Statement block;
1237 1249
1238 _KeywordConditionBlockStructure(this.keyword, this.leftParenthesis, 1250 _KeywordConditionBlockStructure(this.keyword, this.leftParenthesis,
1239 this.condition, this.rightParenthesis, this.block); 1251 this.condition, this.rightParenthesis, this.block);
1240 1252
1241 int get offset => keyword.offset; 1253 int get offset => keyword.offset;
1242 } 1254 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/ast/utilities.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698