Skip to content

Commit 4a96dd1

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Respond to real assist requests
Change-Id: I1f1afca0dc746948410a56e29cf13bebef234ed7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419760 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent aa15b91 commit 4a96dd1

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,12 @@ class PluginServer {
453453
result = await _handleAnalysisUpdateContent(params);
454454

455455
case protocol.COMPLETION_REQUEST_GET_SUGGESTIONS:
456+
result = null;
457+
456458
case protocol.EDIT_REQUEST_GET_ASSISTS:
459+
var params = protocol.EditGetAssistsParams.fromRequest(request);
460+
result = await handleEditGetAssists(params);
461+
457462
case protocol.EDIT_REQUEST_GET_AVAILABLE_REFACTORINGS:
458463
result = null;
459464

pkg/analysis_server_plugin/test/src/plugin_server_test.dart

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ bool b = false;
105105
expect(assist.change.edits, hasLength(1));
106106
}
107107

108+
Future<void> test_handleEditGetAssists_viaSendRequest() async {
109+
writeAnalysisOptionsWithPlugin();
110+
newFile(filePath, 'bool b = false;');
111+
112+
await channel
113+
.sendRequest(protocol.AnalysisSetContextRootsParams([contextRoot]));
114+
115+
var response = await channel.sendRequest(
116+
protocol.EditGetAssistsParams(filePath, 'bool b = '.length, 1));
117+
var result = protocol.EditGetAssistsResult.fromResponse(response);
118+
expect(result.assists, hasLength(1));
119+
}
120+
108121
Future<void> test_handleEditGetFixes() async {
109122
writeAnalysisOptionsWithPlugin();
110123
newFile(filePath, 'bool b = false;');
@@ -118,6 +131,19 @@ bool b = false;
118131
expect(fixes.fixes, hasLength(4));
119132
}
120133

134+
Future<void> test_handleEditGetFixes_viaSendRequest() async {
135+
writeAnalysisOptionsWithPlugin();
136+
newFile(filePath, 'bool b = false;');
137+
138+
await channel
139+
.sendRequest(protocol.AnalysisSetContextRootsParams([contextRoot]));
140+
141+
var response = await channel
142+
.sendRequest(protocol.EditGetFixesParams(filePath, 'bool b = '.length));
143+
var result = protocol.EditGetFixesResult.fromResponse(response);
144+
expect(result.fixes.first.fixes, hasLength(4));
145+
}
146+
121147
Future<void> test_lintDiagnosticsAreDisabledByDefault() async {
122148
writeAnalysisOptionsWithPlugin();
123149
newFile(filePath, 'double x = 3.14;');
@@ -258,6 +284,30 @@ plugins:
258284
}
259285
}
260286

287+
class _InvertBoolean extends ResolvedCorrectionProducer {
288+
static const _invertBooleanKind =
289+
AssistKind('dart.fix.invertBooelan', 50, 'Invert Boolean value');
290+
291+
_InvertBoolean({required super.context});
292+
293+
@override
294+
CorrectionApplicability get applicability =>
295+
CorrectionApplicability.singleLocation;
296+
297+
@override
298+
AssistKind get assistKind => _invertBooleanKind;
299+
300+
@override
301+
Future<void> compute(ChangeBuilder builder) async {
302+
if (node case BooleanLiteral(:var value)) {
303+
await builder.addDartFileEdit(file, (builder) {
304+
var invertedValue = (!value).toString();
305+
builder.addSimpleReplacement(range.node(node), invertedValue);
306+
});
307+
}
308+
}
309+
}
310+
261311
class _NoLiteralsPlugin extends Plugin {
262312
@override
263313
void register(PluginRegistry registry) {
@@ -290,27 +340,3 @@ class _WrapInQuotes extends ResolvedCorrectionProducer {
290340
});
291341
}
292342
}
293-
294-
class _InvertBoolean extends ResolvedCorrectionProducer {
295-
static const _invertBooleanKind =
296-
AssistKind('dart.fix.invertBooelan', 50, 'Invert Boolean value');
297-
298-
_InvertBoolean({required super.context});
299-
300-
@override
301-
CorrectionApplicability get applicability =>
302-
CorrectionApplicability.singleLocation;
303-
304-
@override
305-
AssistKind get assistKind => _invertBooleanKind;
306-
307-
@override
308-
Future<void> compute(ChangeBuilder builder) async {
309-
if (node case BooleanLiteral(:var value)) {
310-
await builder.addDartFileEdit(file, (builder) {
311-
var invertedValue = (!value).toString();
312-
builder.addSimpleReplacement(range.node(node), invertedValue);
313-
});
314-
}
315-
}
316-
}

0 commit comments

Comments
 (0)