| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analysis_server.src.provisional.completion.dart.completion_target; | 5 library analysis_server.src.provisional.completion.dart.completion_target; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/src/generated/utilities_dart.dart'; | 11 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 12 | 12 |
| 13 int _computeArgIndex(AstNode containingNode, Object entity) { | 13 int _computeArgIndex(AstNode containingNode, Object entity) { |
| 14 var argList = containingNode; | 14 var argList = containingNode; |
| 15 if (argList is ArgumentList) { | 15 if (argList is ArgumentList) { |
| 16 NodeList<Expression> args = argList.arguments; | 16 NodeList<Expression> args = argList.arguments; |
| 17 for (int index = 0; index < args.length; ++index) { | 17 for (int index = 0; index < args.length; ++index) { |
| 18 if (entity == args[index]) { | 18 if (entity == args[index]) { |
| 19 return index; | 19 return index; |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 if (args.isEmpty) { | 22 if (args.isEmpty) { |
| 23 return 0; | 23 return 0; |
| 24 } | 24 } |
| 25 if (entity == argList.rightParenthesis) { |
| 26 // Parser ignores trailing commas |
| 27 if (argList.rightParenthesis.previous?.lexeme == ',') { |
| 28 return args.length; |
| 29 } |
| 30 return args.length - 1; |
| 31 } |
| 25 } | 32 } |
| 26 return null; | 33 return null; |
| 27 } | 34 } |
| 28 | 35 |
| 29 /** | 36 /** |
| 30 * A CompletionTarget represents an edge in the parse tree which connects an | 37 * A CompletionTarget represents an edge in the parse tree which connects an |
| 31 * AST node (the [containingNode] of the completion) to one of its children | 38 * AST node (the [containingNode] of the completion) to one of its children |
| 32 * (the [entity], which represents the place in the parse tree where the newly | 39 * (the [entity], which represents the place in the parse tree where the newly |
| 33 * completed text will be inserted). | 40 * completed text will be inserted). |
| 34 * | 41 * |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 if (param.parameterKind == ParameterKind.NAMED) { | 423 if (param.parameterKind == ParameterKind.NAMED) { |
| 417 // TODO(danrubel) handle named parameters | 424 // TODO(danrubel) handle named parameters |
| 418 return false; | 425 return false; |
| 419 } else { | 426 } else { |
| 420 return paramType is FunctionType || paramType is FunctionTypeAlias; | 427 return paramType is FunctionType || paramType is FunctionTypeAlias; |
| 421 } | 428 } |
| 422 } | 429 } |
| 423 return false; | 430 return false; |
| 424 } | 431 } |
| 425 } | 432 } |
| OLD | NEW |