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

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

Issue 2128693002: fix code completion when enableTrailingCommas is true (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 4 years, 5 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 917542cdfb92623bc8264982406a531c26e18fa1..132c8235799d3a2aaba80375d8be4d4030f90615 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/optype.dart
@@ -184,8 +184,19 @@ class _OpTypeAstVisitor extends GeneralizingAstVisitor {
if (elem is FunctionTypedElement) {
List<ParameterElement> parameters = elem.parameters;
if (parameters != null) {
- int index =
- node.arguments.isEmpty ? 0 : node.arguments.indexOf(entity);
+ int index;
+ if (node.arguments.isEmpty) {
+ index = 0;
+ } else if (entity == node.rightParenthesis) {
+ // Parser ignores trailing commas
+ if (node.rightParenthesis.previous?.lexeme == ',') {
+ index = node.arguments.length;
+ } else {
+ index = node.arguments.length - 1;
+ }
+ } else {
+ index = node.arguments.indexOf(entity);
+ }
if (0 <= index && index < parameters.length) {
ParameterElement param = parameters[index];
if (param?.parameterKind == ParameterKind.NAMED) {

Powered by Google App Engine
This is Rietveld 408576698