Skip to content

Commit a4ecc44

Browse files
committed
Completion protocol API for overrides.
Proposed API to allow IDEs to ask a suggestion for a displayText which may differ from the value to insert (the completion). Also, adds a new OVERRIDE suggestion kind. See: https://youtrack.jetbrains.com/issue/WEB-31130 Change-Id: Ic0644308d746ac7771bc27bc2ff2789444733af3 Reviewed-on: https://dart-review.googlesource.com/40101 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 59716fe commit a4ecc44

File tree

6 files changed

+86
-7
lines changed

6 files changed

+86
-7
lines changed

pkg/analysis_server/lib/src/services/completion/dart/override_contributor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class OverrideContributor implements DartCompletionContributor {
8787
return null;
8888
}
8989
CompletionSuggestion suggestion = new CompletionSuggestion(
90-
CompletionSuggestionKind.IDENTIFIER,
90+
CompletionSuggestionKind.OVERRIDE,
9191
DART_RELEVANCE_HIGH,
9292
completion,
9393
targetId.offset,

pkg/analysis_server/test/services/completion/dart/override_contributor_test.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class C extends B {
3636
}
3737
''');
3838
await computeSuggestions();
39+
// TODO(pquitslund): test displayText
3940
_assertOverride('''@override
4041
A suggested1(int x) {
4142
// TODO: implement suggested1
@@ -75,6 +76,7 @@ class C extends B {
7576
// assume information for context.getLibrariesContaining has been cached
7677
await computeLibrariesContaining();
7778
await computeSuggestions();
79+
// TODO(pquitslund): test displayText
7880
_assertOverride('''@override
7981
A suggested1(int x) {
8082
// TODO: implement suggested1
@@ -88,22 +90,24 @@ class C extends B {
8890
'''@override\n C suggested3([String z]) {\n // TODO: implement suggested3\n return null;\n }''');
8991
}
9092

91-
CompletionSuggestion _assertOverride(String completion) {
93+
CompletionSuggestion _assertOverride(String completion,
94+
{String displayText}) {
9295
CompletionSuggestion cs = getSuggest(
9396
completion: completion,
94-
csKind: CompletionSuggestionKind.IDENTIFIER,
97+
csKind: CompletionSuggestionKind.OVERRIDE,
9598
elemKind: null);
9699
if (cs == null) {
97100
failedCompletion('expected $completion', suggestions);
98101
}
99-
expect(cs.kind, equals(CompletionSuggestionKind.IDENTIFIER));
102+
expect(cs.kind, equals(CompletionSuggestionKind.OVERRIDE));
100103
expect(cs.relevance, equals(DART_RELEVANCE_HIGH));
101104
expect(cs.importUri, null);
102105
// expect(cs.selectionOffset, equals(completion.length));
103106
// expect(cs.selectionLength, equals(0));
104107
expect(cs.isDeprecated, isFalse);
105108
expect(cs.isPotential, isFalse);
106109
expect(cs.element, isNotNull);
110+
expect(cs.displayText, displayText);
107111
return cs;
108112
}
109113
}

pkg/analyzer_plugin/doc/api.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,14 @@ <h2 class="domain"><a name="types">Types</a></h2>
997997
additionally insert a template for the parameters. The information
998998
required in order to do so is contained in other fields.
999999
</p>
1000+
</dd><dt class="field"><b>displayText: String<span style="color:#999999"> (optional)</span></b></dt><dd>
1001+
1002+
<p>
1003+
Text to be displayed in, for example, a completion pop-up. In many cases,
1004+
this will be the same as the completion but in some cases, such as
1005+
for overriding methods, this value will be different and tailored for
1006+
presenting and to be used to lookup against.
1007+
</p>
10001008
</dd><dt class="field"><b>selectionOffset: int</b></dt><dd>
10011009

10021010
<p>
@@ -1157,7 +1165,12 @@ <h2 class="domain"><a name="types">Types</a></h2>
11571165
suggestions of this kind, the completion is the named argument
11581166
identifier including a trailing ':' and a space.
11591167
</p>
1160-
</dd><dt class="value">OPTIONAL_ARGUMENT</dt><dt class="value">PARAMETER</dt></dl></dd><dt class="typeDefinition"><a name="type_ContextRoot">ContextRoot: object</a></dt><dd>
1168+
</dd><dt class="value">OPTIONAL_ARGUMENT</dt><dt class="value">OVERRIDE</dt><dd>
1169+
1170+
<p>
1171+
An overriding implementation of a class member is being suggested.
1172+
</p>
1173+
</dd><dt class="value">PARAMETER</dt></dl></dd><dt class="typeDefinition"><a name="type_ContextRoot">ContextRoot: object</a></dt><dd>
11611174
<p>
11621175
A description of an analysis context.
11631176
</p>

pkg/analyzer_plugin/lib/protocol/protocol_common.dart

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ class ChangeContentOverlay implements HasToJson {
597597
* "kind": CompletionSuggestionKind
598598
* "relevance": int
599599
* "completion": String
600+
* "displayText": optional String
600601
* "selectionOffset": int
601602
* "selectionLength": int
602603
* "isDeprecated": bool
@@ -626,6 +627,8 @@ class CompletionSuggestion implements HasToJson {
626627

627628
String _completion;
628629

630+
String _displayText;
631+
629632
int _selectionOffset;
630633

631634
int _selectionLength;
@@ -709,6 +712,24 @@ class CompletionSuggestion implements HasToJson {
709712
this._completion = value;
710713
}
711714

715+
/**
716+
* Text to be displayed in, for example, a completion pop-up. In many cases,
717+
* this will be the same as the completion but in some cases, such as for
718+
* overriding methods, this value will be different and tailored for
719+
* presenting and to be used to lookup against.
720+
*/
721+
String get displayText => _displayText;
722+
723+
/**
724+
* Text to be displayed in, for example, a completion pop-up. In many cases,
725+
* this will be the same as the completion but in some cases, such as for
726+
* overriding methods, this value will be different and tailored for
727+
* presenting and to be used to lookup against.
728+
*/
729+
void set displayText(String value) {
730+
this._displayText = value;
731+
}
732+
712733
/**
713734
* The offset, relative to the beginning of the completion, of where the
714735
* selection should be placed after insertion.
@@ -983,7 +1004,8 @@ class CompletionSuggestion implements HasToJson {
9831004
int selectionLength,
9841005
bool isDeprecated,
9851006
bool isPotential,
986-
{String docSummary,
1007+
{String displayText,
1008+
String docSummary,
9871009
String docComplete,
9881010
String declaringType,
9891011
String defaultArgumentListString,
@@ -1000,6 +1022,7 @@ class CompletionSuggestion implements HasToJson {
10001022
this.kind = kind;
10011023
this.relevance = relevance;
10021024
this.completion = completion;
1025+
this.displayText = displayText;
10031026
this.selectionOffset = selectionOffset;
10041027
this.selectionLength = selectionLength;
10051028
this.isDeprecated = isDeprecated;
@@ -1047,6 +1070,11 @@ class CompletionSuggestion implements HasToJson {
10471070
} else {
10481071
throw jsonDecoder.mismatch(jsonPath, "completion");
10491072
}
1073+
String displayText;
1074+
if (json.containsKey("displayText")) {
1075+
displayText = jsonDecoder.decodeString(
1076+
jsonPath + ".displayText", json["displayText"]);
1077+
}
10501078
int selectionOffset;
10511079
if (json.containsKey("selectionOffset")) {
10521080
selectionOffset = jsonDecoder.decodeInt(
@@ -1151,6 +1179,7 @@ class CompletionSuggestion implements HasToJson {
11511179
}
11521180
return new CompletionSuggestion(kind, relevance, completion,
11531181
selectionOffset, selectionLength, isDeprecated, isPotential,
1182+
displayText: displayText,
11541183
docSummary: docSummary,
11551184
docComplete: docComplete,
11561185
declaringType: declaringType,
@@ -1176,6 +1205,9 @@ class CompletionSuggestion implements HasToJson {
11761205
result["kind"] = kind.toJson();
11771206
result["relevance"] = relevance;
11781207
result["completion"] = completion;
1208+
if (displayText != null) {
1209+
result["displayText"] = displayText;
1210+
}
11791211
result["selectionOffset"] = selectionOffset;
11801212
result["selectionLength"] = selectionLength;
11811213
result["isDeprecated"] = isDeprecated;
@@ -1234,6 +1266,7 @@ class CompletionSuggestion implements HasToJson {
12341266
return kind == other.kind &&
12351267
relevance == other.relevance &&
12361268
completion == other.completion &&
1269+
displayText == other.displayText &&
12371270
selectionOffset == other.selectionOffset &&
12381271
selectionLength == other.selectionLength &&
12391272
isDeprecated == other.isDeprecated &&
@@ -1265,6 +1298,7 @@ class CompletionSuggestion implements HasToJson {
12651298
hash = JenkinsSmiHash.combine(hash, kind.hashCode);
12661299
hash = JenkinsSmiHash.combine(hash, relevance.hashCode);
12671300
hash = JenkinsSmiHash.combine(hash, completion.hashCode);
1301+
hash = JenkinsSmiHash.combine(hash, displayText.hashCode);
12681302
hash = JenkinsSmiHash.combine(hash, selectionOffset.hashCode);
12691303
hash = JenkinsSmiHash.combine(hash, selectionLength.hashCode);
12701304
hash = JenkinsSmiHash.combine(hash, isDeprecated.hashCode);
@@ -1298,6 +1332,7 @@ class CompletionSuggestion implements HasToJson {
12981332
* KEYWORD
12991333
* NAMED_ARGUMENT
13001334
* OPTIONAL_ARGUMENT
1335+
* OVERRIDE
13011336
* PARAMETER
13021337
* }
13031338
*
@@ -1351,6 +1386,12 @@ class CompletionSuggestionKind implements Enum {
13511386
static const CompletionSuggestionKind OPTIONAL_ARGUMENT =
13521387
const CompletionSuggestionKind._("OPTIONAL_ARGUMENT");
13531388

1389+
/**
1390+
* An overriding implementation of a class member is being suggested.
1391+
*/
1392+
static const CompletionSuggestionKind OVERRIDE =
1393+
const CompletionSuggestionKind._("OVERRIDE");
1394+
13541395
static const CompletionSuggestionKind PARAMETER =
13551396
const CompletionSuggestionKind._("PARAMETER");
13561397

@@ -1366,6 +1407,7 @@ class CompletionSuggestionKind implements Enum {
13661407
KEYWORD,
13671408
NAMED_ARGUMENT,
13681409
OPTIONAL_ARGUMENT,
1410+
OVERRIDE,
13691411
PARAMETER
13701412
];
13711413

@@ -1390,6 +1432,8 @@ class CompletionSuggestionKind implements Enum {
13901432
return NAMED_ARGUMENT;
13911433
case "OPTIONAL_ARGUMENT":
13921434
return OPTIONAL_ARGUMENT;
1435+
case "OVERRIDE":
1436+
return OVERRIDE;
13931437
case "PARAMETER":
13941438
return PARAMETER;
13951439
}

pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ final Matcher isChangeContentOverlay = new LazyMatcher(() =>
133133
* "kind": CompletionSuggestionKind
134134
* "relevance": int
135135
* "completion": String
136+
* "displayText": optional String
136137
* "selectionOffset": int
137138
* "selectionLength": int
138139
* "isDeprecated": bool
@@ -163,6 +164,7 @@ final Matcher isCompletionSuggestion =
163164
"isDeprecated": isBool,
164165
"isPotential": isBool
165166
}, optionalFields: {
167+
"displayText": isString,
166168
"docSummary": isString,
167169
"docComplete": isString,
168170
"declaringType": isString,
@@ -190,6 +192,7 @@ final Matcher isCompletionSuggestion =
190192
* KEYWORD
191193
* NAMED_ARGUMENT
192194
* OPTIONAL_ARGUMENT
195+
* OVERRIDE
193196
* PARAMETER
194197
* }
195198
*/
@@ -202,6 +205,7 @@ final Matcher isCompletionSuggestionKind =
202205
"KEYWORD",
203206
"NAMED_ARGUMENT",
204207
"OPTIONAL_ARGUMENT",
208+
"OVERRIDE",
205209
"PARAMETER"
206210
]);
207211

pkg/analyzer_plugin/tool/spec/common_types_spec.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ <h1>Common Types</h1>
198198
required in order to do so is contained in other fields.
199199
</p>
200200
</field>
201+
<field name="displayText" optional="true">
202+
<ref>String</ref>
203+
<p>
204+
Text to be displayed in, for example, a completion pop-up. This field
205+
is only defined if the displayed text should be different than the
206+
completion. Otherwise it is omitted.
207+
</p>
208+
</field>
201209
<field name="selectionOffset">
202210
<ref>int</ref>
203211
<p>
@@ -228,7 +236,7 @@ <h1>Common Types</h1>
228236
<ref>String</ref>
229237
<p>
230238
An abbreviated version of the Dartdoc associated with the element
231-
being suggested, This field is omitted if there is no Dartdoc
239+
being suggested. This field is omitted if there is no Dartdoc
232240
associated with the element.
233241
</p>
234242
</field>
@@ -391,6 +399,12 @@ <h1>Common Types</h1>
391399
</p>
392400
</value>
393401
<value><code>OPTIONAL_ARGUMENT</code></value>
402+
<value>
403+
<code>OVERRIDE</code>
404+
<p>
405+
An overriding implementation of a class member is being suggested.
406+
</p>
407+
</value>
394408
<value><code>PARAMETER</code></value>
395409
</enum>
396410
</type>

0 commit comments

Comments
 (0)