Refactored API to decouple analyzer.
diff --git a/doc/generated/dartservices.dart b/doc/generated/dartservices.dart
index f5cddbf..a83bd79 100644
--- a/doc/generated/dartservices.dart
+++ b/doc/generated/dartservices.dart
@@ -721,8 +721,14 @@
}
class LinkedEditGroup {
+ /// The length of the regions that should be edited simultaneously.
core.int length;
- core.List<Position> positions;
+
+ /// The positions of the regions that should be edited simultaneously.
+ core.List<core.int> positions;
+
+ /// Pre-computed suggestions for what every region might want to be changed
+ /// to.
core.List<LinkedEditSuggestion> suggestions;
LinkedEditGroup();
@@ -732,9 +738,7 @@
length = _json["length"];
}
if (_json.containsKey("positions")) {
- positions = (_json["positions"] as core.List)
- .map<Position>((value) => new Position.fromJson(value))
- .toList();
+ positions = (_json["positions"] as core.List).cast<core.int>();
}
if (_json.containsKey("suggestions")) {
suggestions = (_json["suggestions"] as core.List)
@@ -751,7 +755,7 @@
_json["length"] = length;
}
if (positions != null) {
- _json["positions"] = positions.map((value) => (value).toJson()).toList();
+ _json["positions"] = positions;
}
if (suggestions != null) {
_json["suggestions"] =
@@ -762,7 +766,10 @@
}
class LinkedEditSuggestion {
+ /// The kind of value being proposed.
core.String kind;
+
+ /// The value that could be used to replace all of the linked edit regions.
core.String value;
LinkedEditSuggestion();
@@ -789,34 +796,6 @@
}
}
-class Position {
- core.String file;
- core.int offset;
-
- Position();
-
- Position.fromJson(core.Map _json) {
- if (_json.containsKey("file")) {
- file = _json["file"];
- }
- if (_json.containsKey("offset")) {
- offset = _json["offset"];
- }
- }
-
- core.Map<core.String, core.Object> toJson() {
- final core.Map<core.String, core.Object> _json =
- new core.Map<core.String, core.Object>();
- if (file != null) {
- _json["file"] = file;
- }
- if (offset != null) {
- _json["offset"] = offset;
- }
- return _json;
- }
-}
-
class ProblemAndFixes {
core.List<CandidateFix> fixes;
core.int length;
diff --git a/doc/generated/dartservices.json b/doc/generated/dartservices.json
index 7606c30..172319c 100644
--- a/doc/generated/dartservices.json
+++ b/doc/generated/dartservices.json
@@ -1,6 +1,6 @@
{
"kind": "discovery#restDescription",
- "etag": "e5fb2d50ad3bc13ae1c6dda90907613797073978",
+ "etag": "3782b4a662b81bc2c7a01a7d5e7e9021a4debd44",
"discoveryVersion": "v1",
"id": "dartservices:v1",
"name": "dartservices",
@@ -225,44 +225,37 @@
"properties": {
"positions": {
"type": "array",
+ "description": "The positions of the regions that should be edited simultaneously.",
"items": {
- "$ref": "Position"
+ "type": "integer",
+ "format": "int32"
}
},
"length": {
"type": "integer",
+ "description": "The length of the regions that should be edited simultaneously.",
"format": "int32"
},
"suggestions": {
"type": "array",
+ "description": "Pre-computed suggestions for what every region might want to be changed to.",
"items": {
"$ref": "LinkedEditSuggestion"
}
}
}
},
- "Position": {
- "id": "Position",
- "type": "object",
- "properties": {
- "file": {
- "type": "string"
- },
- "offset": {
- "type": "integer",
- "format": "int32"
- }
- }
- },
"LinkedEditSuggestion": {
"id": "LinkedEditSuggestion",
"type": "object",
"properties": {
"value": {
- "type": "string"
+ "type": "string",
+ "description": "The value that could be used to replace all of the linked edit regions."
},
"kind": {
- "type": "string"
+ "type": "string",
+ "description": "The kind of value being proposed."
}
}
},
diff --git a/lib/src/analysis_server.dart b/lib/src/analysis_server.dart
index 3f4fb79..952d874 100644
--- a/lib/src/analysis_server.dart
+++ b/lib/src/analysis_server.dart
@@ -352,7 +352,7 @@
sourceChange.message,
apiSourceEdits,
sourceChange.selection?.offset,
- sourceChange.linkedEditGroups,
+ _convertLinkedEditGroups(sourceChange.linkedEditGroups),
));
}
}
@@ -360,6 +360,21 @@
return assists;
}
+ /// Convert a list of the analysis server's [LinkedEditGroup]s into the API's
+ /// equivalent.
+ static List<api.LinkedEditGroup> _convertLinkedEditGroups(
+ List<LinkedEditGroup> groups) {
+ return groups?.map<api.LinkedEditGroup>((g) {
+ return api.LinkedEditGroup(
+ g.positions?.map((p) => p.offset)?.toList(),
+ g.length,
+ g.suggestions
+ ?.map((s) => api.LinkedEditSuggestion(s.value, s.kind))
+ ?.toList(),
+ );
+ })?.toList();
+ }
+
/// Cleanly shutdown the Analysis Server.
Future<dynamic> shutdown() {
// TODO(jcollins-g): calling dispose() sometimes prevents
diff --git a/lib/src/api_classes.dart b/lib/src/api_classes.dart
index 836d98e..cfca8ec 100644
--- a/lib/src/api_classes.dart
+++ b/lib/src/api_classes.dart
@@ -7,7 +7,6 @@
import 'dart:convert';
-import 'package:analysis_server_lib/analysis_server_lib.dart';
import 'package:rpc/rpc.dart';
class AnalysisResults {
@@ -184,6 +183,37 @@
[this.fixes, this.problemMessage, this.offset, this.length]);
}
+class LinkedEditSuggestion {
+ @ApiProperty(
+ description: 'The value that could be used to replace all of the linked '
+ 'edit regions.')
+ final String value;
+
+ @ApiProperty(description: 'The kind of value being proposed.')
+ final String kind;
+
+ LinkedEditSuggestion(this.value, this.kind);
+}
+
+class LinkedEditGroup {
+ @ApiProperty(
+ description: 'The positions of the regions that should be edited '
+ 'simultaneously.')
+ final List<int> positions;
+
+ @ApiProperty(
+ description: 'The length of the regions that should be edited '
+ 'simultaneously.')
+ final int length;
+
+ @ApiProperty(
+ description: 'Pre-computed suggestions for what every region might want '
+ 'to be changed to.')
+ final List<LinkedEditSuggestion> suggestions;
+
+ LinkedEditGroup(this.positions, this.length, this.suggestions);
+}
+
/// Represents a possible way of solving an Analysis Problem.
class CandidateFix {
final String message;