Skip to content

Commit

Permalink
Revise the analysis server edit.dartfix protocol
Browse files Browse the repository at this point in the history
This updates the edit.dartfix protocol to separate location from the text
describing the changes so that the dartfix client can choose
what location information to display and how it should be displayed.

Change-Id: Ic56a4cb187538571d60136d6de9265d879fccb53
Reviewed-on: https://dart-review.googlesource.com/c/81780
Commit-Queue: Dan Rubel <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
danrubel authored and [email protected] committed Oct 29, 2018
1 parent ae24413 commit 0fe448a
Show file tree
Hide file tree
Showing 14 changed files with 591 additions and 230 deletions.
7 changes: 4 additions & 3 deletions pkg/analysis_server/doc/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -2658,6 +2658,7 @@ <h2 class="domain"><a name="types">Types</a></h2>






<dl><dt class="typeDefinition"><a name="type_AddContentOverlay">AddContentOverlay: object</a></dt><dd>
Expand Down Expand Up @@ -4379,9 +4380,9 @@ <h2 class="domain"><a name="types">Types</a></h2>
</dd></dl></dd><dt class="typeDefinition"><a name="type_RuntimeCompletionExpression">RuntimeCompletionExpression: object</a></dt><dd>
<p>
An expression for which we want to know its runtime type.
In expressions like `a.b.c.where((e) =&gt; e.^)` we want to know the
runtime type of `a.b.c` to enforce it statically at the time when we
compute completion suggestions, and get better type for `e`.
In expressions like 'a.b.c.where((e) =&gt; e.^)' we want to know the
runtime type of 'a.b.c' to enforce it statically at the time when we
compute completion suggestions, and get better type for 'e'.
</p>

<dl><dt class="field"><b>offset: int</b></dt><dd>
Expand Down
7 changes: 3 additions & 4 deletions pkg/analysis_server/lib/protocol/protocol_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ const String EDIT_REQUEST_ORGANIZE_DIRECTIVES = 'edit.organizeDirectives';
const String EDIT_REQUEST_ORGANIZE_DIRECTIVES_FILE = 'file';
const String EDIT_REQUEST_SORT_MEMBERS = 'edit.sortMembers';
const String EDIT_REQUEST_SORT_MEMBERS_FILE = 'file';
const String EDIT_RESPONSE_DARTFIX_DESCRIPTION_OF_FIXES = 'descriptionOfFixes';
const String EDIT_RESPONSE_DARTFIX_FIXES = 'fixes';
const String EDIT_RESPONSE_DARTFIX_EDITS = 'edits';
const String EDIT_RESPONSE_DARTFIX_HAS_ERRORS = 'hasErrors';
const String EDIT_RESPONSE_DARTFIX_OTHER_RECOMMENDATIONS =
'otherRecommendations';
const String EDIT_RESPONSE_DARTFIX_OTHER_SUGGESTIONS = 'otherSuggestions';
const String EDIT_RESPONSE_DARTFIX_SUGGESTIONS = 'suggestions';
const String EDIT_RESPONSE_FORMAT_EDITS = 'edits';
const String EDIT_RESPONSE_FORMAT_SELECTION_LENGTH = 'selectionLength';
const String EDIT_RESPONSE_FORMAT_SELECTION_OFFSET = 'selectionOffset';
Expand Down
232 changes: 168 additions & 64 deletions pkg/analysis_server/lib/protocol/protocol_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5931,6 +5931,105 @@ class ConvertMethodToGetterOptions extends RefactoringOptions
}
}

/**
* DartFixSuggestion
*
* {
* "description": String
* "location": optional Location
* }
*
* Clients may not extend, implement or mix-in this class.
*/
class DartFixSuggestion implements HasToJson {
String _description;

Location _location;

/**
* A human readable description of the suggested change.
*/
String get description => _description;

/**
* A human readable description of the suggested change.
*/
void set description(String value) {
assert(value != null);
this._description = value;
}

/**
* The location of the suggested change.
*/
Location get location => _location;

/**
* The location of the suggested change.
*/
void set location(Location value) {
this._location = value;
}

DartFixSuggestion(String description, {Location location}) {
this.description = description;
this.location = location;
}

factory DartFixSuggestion.fromJson(
JsonDecoder jsonDecoder, String jsonPath, Object json) {
if (json == null) {
json = {};
}
if (json is Map) {
String description;
if (json.containsKey("description")) {
description = jsonDecoder.decodeString(
jsonPath + ".description", json["description"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "description");
}
Location location;
if (json.containsKey("location")) {
location = new Location.fromJson(
jsonDecoder, jsonPath + ".location", json["location"]);
}
return new DartFixSuggestion(description, location: location);
} else {
throw jsonDecoder.mismatch(jsonPath, "DartFixSuggestion", json);
}
}

@override
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {};
result["description"] = description;
if (location != null) {
result["location"] = location.toJson();
}
return result;
}

@override
String toString() => json.encode(toJson());

@override
bool operator ==(other) {
if (other is DartFixSuggestion) {
return description == other.description && location == other.location;
}
return false;
}

@override
int get hashCode {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, description.hashCode);
hash = JenkinsSmiHash.combine(hash, location.hashCode);
return JenkinsSmiHash.finish(hash);
}
}

/**
* diagnostic.getDiagnostics params
*
Expand Down Expand Up @@ -6268,88 +6367,88 @@ class EditDartfixParams implements RequestParams {
* edit.dartfix result
*
* {
* "descriptionOfFixes": List<String>
* "otherRecommendations": List<String>
* "suggestions": List<DartFixSuggestion>
* "otherSuggestions": List<DartFixSuggestion>
* "hasErrors": bool
* "fixes": List<SourceFileEdit>
* "edits": List<SourceFileEdit>
* }
*
* Clients may not extend, implement or mix-in this class.
*/
class EditDartfixResult implements ResponseResult {
List<String> _descriptionOfFixes;
List<DartFixSuggestion> _suggestions;

List<String> _otherRecommendations;
List<DartFixSuggestion> _otherSuggestions;

bool _hasErrors;

List<SourceFileEdit> _fixes;
List<SourceFileEdit> _edits;

/**
* A list of human readable changes made by applying the fixes.
* A list of recommended changes that can be automatically made by applying
* the 'edits' included in this response.
*/
List<String> get descriptionOfFixes => _descriptionOfFixes;
List<DartFixSuggestion> get suggestions => _suggestions;

/**
* A list of human readable changes made by applying the fixes.
* A list of recommended changes that can be automatically made by applying
* the 'edits' included in this response.
*/
void set descriptionOfFixes(List<String> value) {
void set suggestions(List<DartFixSuggestion> value) {
assert(value != null);
this._descriptionOfFixes = value;
this._suggestions = value;
}

/**
* A list of human readable recommended changes that cannot be made
* automatically.
* A list of recommended changes that could not be automatically made.
*/
List<String> get otherRecommendations => _otherRecommendations;
List<DartFixSuggestion> get otherSuggestions => _otherSuggestions;

/**
* A list of human readable recommended changes that cannot be made
* automatically.
* A list of recommended changes that could not be automatically made.
*/
void set otherRecommendations(List<String> value) {
void set otherSuggestions(List<DartFixSuggestion> value) {
assert(value != null);
this._otherRecommendations = value;
this._otherSuggestions = value;
}

/**
* True if the analyzed source contains errors that might impact the
* correctness of the recommended fixes that can be automatically applied.
* correctness of the recommended changes that can be automatically applied.
*/
bool get hasErrors => _hasErrors;

/**
* True if the analyzed source contains errors that might impact the
* correctness of the recommended fixes that can be automatically applied.
* correctness of the recommended changes that can be automatically applied.
*/
void set hasErrors(bool value) {
assert(value != null);
this._hasErrors = value;
}

/**
* The suggested fixes.
* A list of source edits to apply the recommended changes.
*/
List<SourceFileEdit> get fixes => _fixes;
List<SourceFileEdit> get edits => _edits;

/**
* The suggested fixes.
* A list of source edits to apply the recommended changes.
*/
void set fixes(List<SourceFileEdit> value) {
void set edits(List<SourceFileEdit> value) {
assert(value != null);
this._fixes = value;
this._edits = value;
}

EditDartfixResult(
List<String> descriptionOfFixes,
List<String> otherRecommendations,
List<DartFixSuggestion> suggestions,
List<DartFixSuggestion> otherSuggestions,
bool hasErrors,
List<SourceFileEdit> fixes) {
this.descriptionOfFixes = descriptionOfFixes;
this.otherRecommendations = otherRecommendations;
List<SourceFileEdit> edits) {
this.suggestions = suggestions;
this.otherSuggestions = otherSuggestions;
this.hasErrors = hasErrors;
this.fixes = fixes;
this.edits = edits;
}

factory EditDartfixResult.fromJson(
Expand All @@ -6358,23 +6457,25 @@ class EditDartfixResult implements ResponseResult {
json = {};
}
if (json is Map) {
List<String> descriptionOfFixes;
if (json.containsKey("descriptionOfFixes")) {
descriptionOfFixes = jsonDecoder.decodeList(
jsonPath + ".descriptionOfFixes",
json["descriptionOfFixes"],
jsonDecoder.decodeString);
List<DartFixSuggestion> suggestions;
if (json.containsKey("suggestions")) {
suggestions = jsonDecoder.decodeList(
jsonPath + ".suggestions",
json["suggestions"],
(String jsonPath, Object json) =>
new DartFixSuggestion.fromJson(jsonDecoder, jsonPath, json));
} else {
throw jsonDecoder.mismatch(jsonPath, "descriptionOfFixes");
throw jsonDecoder.mismatch(jsonPath, "suggestions");
}
List<String> otherRecommendations;
if (json.containsKey("otherRecommendations")) {
otherRecommendations = jsonDecoder.decodeList(
jsonPath + ".otherRecommendations",
json["otherRecommendations"],
jsonDecoder.decodeString);
List<DartFixSuggestion> otherSuggestions;
if (json.containsKey("otherSuggestions")) {
otherSuggestions = jsonDecoder.decodeList(
jsonPath + ".otherSuggestions",
json["otherSuggestions"],
(String jsonPath, Object json) =>
new DartFixSuggestion.fromJson(jsonDecoder, jsonPath, json));
} else {
throw jsonDecoder.mismatch(jsonPath, "otherRecommendations");
throw jsonDecoder.mismatch(jsonPath, "otherSuggestions");
}
bool hasErrors;
if (json.containsKey("hasErrors")) {
Expand All @@ -6383,18 +6484,18 @@ class EditDartfixResult implements ResponseResult {
} else {
throw jsonDecoder.mismatch(jsonPath, "hasErrors");
}
List<SourceFileEdit> fixes;
if (json.containsKey("fixes")) {
fixes = jsonDecoder.decodeList(
jsonPath + ".fixes",
json["fixes"],
List<SourceFileEdit> edits;
if (json.containsKey("edits")) {
edits = jsonDecoder.decodeList(
jsonPath + ".edits",
json["edits"],
(String jsonPath, Object json) =>
new SourceFileEdit.fromJson(jsonDecoder, jsonPath, json));
} else {
throw jsonDecoder.mismatch(jsonPath, "fixes");
throw jsonDecoder.mismatch(jsonPath, "edits");
}
return new EditDartfixResult(
descriptionOfFixes, otherRecommendations, hasErrors, fixes);
suggestions, otherSuggestions, hasErrors, edits);
} else {
throw jsonDecoder.mismatch(jsonPath, "edit.dartfix result", json);
}
Expand All @@ -6410,11 +6511,14 @@ class EditDartfixResult implements ResponseResult {
@override
Map<String, dynamic> toJson() {
Map<String, dynamic> result = {};
result["descriptionOfFixes"] = descriptionOfFixes;
result["otherRecommendations"] = otherRecommendations;
result["suggestions"] =
suggestions.map((DartFixSuggestion value) => value.toJson()).toList();
result["otherSuggestions"] = otherSuggestions
.map((DartFixSuggestion value) => value.toJson())
.toList();
result["hasErrors"] = hasErrors;
result["fixes"] =
fixes.map((SourceFileEdit value) => value.toJson()).toList();
result["edits"] =
edits.map((SourceFileEdit value) => value.toJson()).toList();
return result;
}

Expand All @@ -6429,12 +6533,12 @@ class EditDartfixResult implements ResponseResult {
@override
bool operator ==(other) {
if (other is EditDartfixResult) {
return listEqual(descriptionOfFixes, other.descriptionOfFixes,
(String a, String b) => a == b) &&
listEqual(otherRecommendations, other.otherRecommendations,
(String a, String b) => a == b) &&
return listEqual(suggestions, other.suggestions,
(DartFixSuggestion a, DartFixSuggestion b) => a == b) &&
listEqual(otherSuggestions, other.otherSuggestions,
(DartFixSuggestion a, DartFixSuggestion b) => a == b) &&
hasErrors == other.hasErrors &&
listEqual(fixes, other.fixes,
listEqual(edits, other.edits,
(SourceFileEdit a, SourceFileEdit b) => a == b);
}
return false;
Expand All @@ -6443,10 +6547,10 @@ class EditDartfixResult implements ResponseResult {
@override
int get hashCode {
int hash = 0;
hash = JenkinsSmiHash.combine(hash, descriptionOfFixes.hashCode);
hash = JenkinsSmiHash.combine(hash, otherRecommendations.hashCode);
hash = JenkinsSmiHash.combine(hash, suggestions.hashCode);
hash = JenkinsSmiHash.combine(hash, otherSuggestions.hashCode);
hash = JenkinsSmiHash.combine(hash, hasErrors.hashCode);
hash = JenkinsSmiHash.combine(hash, fixes.hashCode);
hash = JenkinsSmiHash.combine(hash, edits.hashCode);
return JenkinsSmiHash.finish(hash);
}
}
Expand Down
Loading

0 comments on commit 0fe448a

Please sign in to comment.