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

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

Issue 2136223004: Don't insert additional ':' when changing a named argument name. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_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/dart/arglist_contributor.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
index 102cd90be2b36799c70e1995bb703f7236c2daae..3b26f605c16df40d96fb3c05469ea56f80b94f11 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart
@@ -102,6 +102,18 @@ bool _isEditingNamedArgLabel(DartCompletionRequest request) {
}
/**
+ * Return `true` if the [request] is inside of a [NamedExpression] name.
+ */
+bool _isInNamedExpression(DartCompletionRequest request) {
+ Object entity = request.target.entity;
+ if (entity is NamedExpression) {
+ Label name = entity.name;
+ return name.offset < request.offset && request.offset < name.end;
+ }
+ return false;
+}
+
+/**
* Determine if the completion target is in the middle or beginning of the list
* of named parameters and is not preceded by a comma. This method assumes that
* _isAppendingToArgList has been called and is false.
@@ -216,19 +228,28 @@ class ArgListContributor extends DartCompletionContributor {
void _addDefaultParamSuggestions(Iterable<ParameterElement> parameters,
[bool appendComma = false]) {
+ bool appendColon = !_isInNamedExpression(request);
Iterable<String> namedArgs = _namedArgs(request);
for (ParameterElement param in parameters) {
if (param.parameterKind == ParameterKind.NAMED) {
_addNamedParameterSuggestion(request, namedArgs, param.name,
- param.type?.displayName, appendComma);
+ param.type?.displayName, appendColon, appendComma);
}
}
}
- void _addNamedParameterSuggestion(DartCompletionRequest request,
- List<String> namedArgs, String name, String paramType, bool appendComma) {
+ void _addNamedParameterSuggestion(
+ DartCompletionRequest request,
+ List<String> namedArgs,
+ String name,
+ String paramType,
+ bool appendColon,
+ bool appendComma) {
if (name != null && name.length > 0 && !namedArgs.contains(name)) {
- String completion = '$name: ';
+ String completion = name;
+ if (appendColon) {
+ completion += ': ';
+ }
if (appendComma) {
completion += ',';
}
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698