Skip to content

Commit

Permalink
Update edit.importElements response data to support part files
Browse files Browse the repository at this point in the history
R=devoncarew@google.com

Review-Url: https://codereview.chromium.org/3001723002 .
  • Loading branch information
bwilkerson committed Aug 15, 2017
1 parent d2676d2 commit 44b5341
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/protocol/protocol_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const String EDIT_RESPONSE_GET_REFACTORING_POTENTIAL_EDITS = 'potentialEdits';
const String EDIT_RESPONSE_GET_STATEMENT_COMPLETION_CHANGE = 'change';
const String EDIT_RESPONSE_GET_STATEMENT_COMPLETION_WHITESPACE_ONLY =
'whitespaceOnly';
const String EDIT_RESPONSE_IMPORT_ELEMENTS_EDITS = 'edits';
const String EDIT_RESPONSE_IMPORT_ELEMENTS_EDIT = 'edit';
const String EDIT_RESPONSE_IS_POSTFIX_COMPLETION_APPLICABLE_VALUE = 'value';
const String EDIT_RESPONSE_LIST_POSTFIX_COMPLETION_TEMPLATES_TEMPLATES =
'templates';
Expand Down
50 changes: 26 additions & 24 deletions pkg/analysis_server/lib/protocol/protocol_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7942,31 +7942,37 @@ class EditImportElementsParams implements RequestParams {
* edit.importElements result
*
* {
* "edits": List<SourceEdit>
* "edit": SourceFileEdit
* }
*
* Clients may not extend, implement or mix-in this class.
*/
class EditImportElementsResult implements ResponseResult {
List<SourceEdit> _edits;
SourceFileEdit _edit;

/**
* The edit(s) to be applied in order to make the specified elements
* accessible.
* The edits to be applied in order to make the specified elements
* accessible. The file to be edited will be the defining compilation unit of
* the library containing the file specified in the request, which can be
* different than the file specified in the request if the specified file is
* a part file.
*/
List<SourceEdit> get edits => _edits;
SourceFileEdit get edit => _edit;

/**
* The edit(s) to be applied in order to make the specified elements
* accessible.
* The edits to be applied in order to make the specified elements
* accessible. The file to be edited will be the defining compilation unit of
* the library containing the file specified in the request, which can be
* different than the file specified in the request if the specified file is
* a part file.
*/
void set edits(List<SourceEdit> value) {
void set edit(SourceFileEdit value) {
assert(value != null);
this._edits = value;
this._edit = value;
}

EditImportElementsResult(List<SourceEdit> edits) {
this.edits = edits;
EditImportElementsResult(SourceFileEdit edit) {
this.edit = edit;
}

factory EditImportElementsResult.fromJson(
Expand All @@ -7975,17 +7981,14 @@ class EditImportElementsResult implements ResponseResult {
json = {};
}
if (json is Map) {
List<SourceEdit> edits;
if (json.containsKey("edits")) {
edits = jsonDecoder.decodeList(
jsonPath + ".edits",
json["edits"],
(String jsonPath, Object json) =>
new SourceEdit.fromJson(jsonDecoder, jsonPath, json));
SourceFileEdit edit;
if (json.containsKey("edit")) {
edit = new SourceFileEdit.fromJson(
jsonDecoder, jsonPath + ".edit", json["edit"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "edits");
throw jsonDecoder.mismatch(jsonPath, "edit");
}
return new EditImportElementsResult(edits);
return new EditImportElementsResult(edit);
} else {
throw jsonDecoder.mismatch(jsonPath, "edit.importElements result", json);
}
Expand All @@ -8001,7 +8004,7 @@ class EditImportElementsResult implements ResponseResult {
@override
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {};
result["edits"] = edits.map((SourceEdit value) => value.toJson()).toList();
result["edit"] = edit.toJson();
return result;
}

Expand All @@ -8016,16 +8019,15 @@ class EditImportElementsResult implements ResponseResult {
@override
bool operator ==(other) {
if (other is EditImportElementsResult) {
return listEqual(
edits, other.edits, (SourceEdit a, SourceEdit b) => a == b);
return edit == other.edit;
}
return false;
}

@override
int get hashCode {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, edits.hashCode);
hash = JenkinsSmiHash.combine(hash, edit.hashCode);
return JenkinsSmiHash.finish(hash);
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/analysis_server/lib/src/edit/edit_domain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ class EditDomainHandler extends AbstractRequestHandler {
//
// Send the response.
//
server.sendResponse(new EditImportElementsResult(change.edits[0].edits)
.toResponse(request.id));
server.sendResponse(
new EditImportElementsResult(change.edits[0]).toResponse(request.id));
}

Future isPostfixCompletionApplicable(Request request) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class AnalysisGetImportElementsIntegrationTest
EditImportElementsResult result =
await sendEditImportElements(pathname, elements);

expect(result.edits, hasLength(expected.length));
SourceFileEdit edit = result.edit;
expect(edit, isNotNull);
expect(edit.edits, hasLength(expected.length));
// TODO(brianwilkerson) Finish implementing this.
}

Expand All @@ -51,7 +53,9 @@ class AnalysisGetImportElementsIntegrationTest
EditImportElementsResult result =
await sendEditImportElements(pathname, <ImportedElements>[]);

expect(result.edits, hasLength(0));
SourceFileEdit edit = result.edit;
expect(edit, isNotNull);
expect(edit.edits, hasLength(0));
}

setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1665,10 +1665,13 @@ abstract class IntegrationTestMixin {
*
* Returns
*
* edits: List<SourceEdit>
* edit: SourceFileEdit
*
* The edit(s) to be applied in order to make the specified elements
* accessible.
* The edits to be applied in order to make the specified elements
* accessible. The file to be edited will be the defining compilation unit
* of the library containing the file specified in the request, which can
* be different than the file specified in the request if the specified
* file is a part file.
*/
Future<EditImportElementsResult> sendEditImportElements(
String file, List<ImportedElements> elements) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2051,12 +2051,12 @@ final Matcher isEditImportElementsParams = new LazyMatcher(() =>
* edit.importElements result
*
* {
* "edits": List<SourceEdit>
* "edit": SourceFileEdit
* }
*/
final Matcher isEditImportElementsResult = new LazyMatcher(() =>
new MatchesJsonObject(
"edit.importElements result", {"edits": isListOf(isSourceEdit)}));
"edit.importElements result", {"edit": isSourceFileEdit}));

/**
* edit.isPostfixCompletionApplicable params
Expand Down
13 changes: 7 additions & 6 deletions pkg/analysis_server/tool/spec/spec_input.html
Original file line number Diff line number Diff line change
Expand Up @@ -2134,13 +2134,14 @@ <h4>Options</h4>
</field>
</params>
<result>
<field name="edits">
<list>
<ref>SourceEdit</ref>
</list>
<field name="edit">
<ref>SourceFileEdit</ref>
<p>
The edit(s) to be applied in order to make the specified elements
accessible.
The edits to be applied in order to make the specified elements
accessible. The file to be edited will be the defining compilation
unit of the library containing the file specified in the request,
which can be different than the file specified in the request if the
specified file is a part file.
</p>
</field>
</result>
Expand Down

0 comments on commit 44b5341

Please sign in to comment.