2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
+ import 'dart:convert' ;
6
+ import 'dart:isolate' ;
7
+
5
8
import 'package:analyzer/dart/analysis/analysis_context.dart' ;
6
9
import 'package:analyzer/dart/analysis/analysis_context_collection.dart' ;
7
10
import 'package:analyzer/file_system/file_system.dart' ;
@@ -11,6 +14,7 @@ import 'package:analyzer_plugin/plugin/plugin.dart';
11
14
import 'package:analyzer_plugin/protocol/protocol.dart' ;
12
15
import 'package:analyzer_plugin/protocol/protocol_common.dart' ;
13
16
import 'package:analyzer_plugin/protocol/protocol_generated.dart' ;
17
+ import 'package:analyzer_plugin/src/protocol/protocol_internal.dart' ;
14
18
import 'package:meta/meta.dart' ;
15
19
import 'package:pub_semver/pub_semver.dart' ;
16
20
import 'package:test/test.dart' ;
@@ -64,6 +68,31 @@ class ServerPluginTest extends AbstractPluginTest {
64
68
late String filePath2;
65
69
late ContextRoot contextRoot2;
66
70
71
+ /// Asserts that [params] is valid to send to an [Isolate] started with
72
+ /// [Isolate.spawnUri] .
73
+ Future <void > assertValidForIsolateSend (RequestParams params) async {
74
+ const isolateSource = r'''
75
+ import 'dart:isolate';
76
+
77
+ void main(List<String> args, SendPort sendPort) {
78
+ final receivePort = ReceivePort();
79
+ sendPort.send(receivePort.sendPort);
80
+ receivePort.listen((msg) => sendPort.send('ECHO: $msg'));
81
+ }
82
+ ''' ;
83
+ final isolateUri = Uri .dataFromString (isolateSource, encoding: utf8);
84
+ final receivePort = ReceivePort ();
85
+ final isolate =
86
+ await Isolate .spawnUri (isolateUri, [], receivePort.sendPort);
87
+ final sendPort = (await receivePort.first) as SendPort ;
88
+ try {
89
+ sendPort.send (params.toJson ());
90
+ } catch (e) {
91
+ fail ('Failed to send ${params .runtimeType } across Isolate: $e ' );
92
+ }
93
+ isolate.kill ();
94
+ }
95
+
67
96
@override
68
97
ServerPlugin createPlugin () {
69
98
return _TestServerPlugin (resourceProvider);
@@ -229,6 +258,78 @@ class ServerPluginTest extends AbstractPluginTest {
229
258
fail ('Not yet implemented.' );
230
259
}
231
260
261
+ Future <void > test_isolateSend_analysisGetNavigation () async {
262
+ await assertValidForIsolateSend (AnalysisGetNavigationParams ('' , 1 , 2 ));
263
+ }
264
+
265
+ Future <void > test_isolateSend_analysisHandleWatchEvents () async {
266
+ await assertValidForIsolateSend (AnalysisHandleWatchEventsParams ([]));
267
+ }
268
+
269
+ Future <void > test_isolateSend_analysisSetPriorityFiles () async {
270
+ await assertValidForIsolateSend (
271
+ AnalysisSetPriorityFilesParams ([filePath1]));
272
+ }
273
+
274
+ Future <void > test_isolateSend_analysisSetSubscriptions () async {
275
+ await assertValidForIsolateSend (AnalysisSetSubscriptionsParams ({
276
+ AnalysisService .OUTLINE : [filePath1]
277
+ }));
278
+ }
279
+
280
+ Future <void > test_isolateSend_analysisUpdateContent_add () async {
281
+ await assertValidForIsolateSend (AnalysisUpdateContentParams (
282
+ {filePath1: AddContentOverlay ('class C {}' )}));
283
+ }
284
+
285
+ Future <void > test_isolateSend_analysisUpdateContent_change () async {
286
+ await assertValidForIsolateSend (AnalysisUpdateContentParams ({
287
+ filePath1: ChangeContentOverlay ([SourceEdit (7 , 0 , ' extends Object' )])
288
+ }));
289
+ }
290
+
291
+ Future <void > test_isolateSend_analysisUpdateContent_remove () async {
292
+ await assertValidForIsolateSend (
293
+ AnalysisUpdateContentParams ({filePath1: RemoveContentOverlay ()}));
294
+ }
295
+
296
+ Future <void > test_isolateSend_completionGetSuggestions () async {
297
+ await assertValidForIsolateSend (
298
+ CompletionGetSuggestionsParams (filePath1, 12 ));
299
+ }
300
+
301
+ Future <void > test_isolateSend_editGetAssists () async {
302
+ await assertValidForIsolateSend (EditGetAssistsParams (filePath1, 10 , 0 ));
303
+ }
304
+
305
+ Future <void > test_isolateSend_editGetAvailableRefactorings () async {
306
+ await assertValidForIsolateSend (
307
+ EditGetAvailableRefactoringsParams (filePath1, 10 , 0 ));
308
+ }
309
+
310
+ Future <void > test_isolateSend_editGetFixes () async {
311
+ await assertValidForIsolateSend (EditGetFixesParams (filePath1, 13 ));
312
+ }
313
+
314
+ Future <void > test_isolateSend_editGetRefactoring () async {
315
+ await assertValidForIsolateSend (EditGetRefactoringParams (
316
+ RefactoringKind .RENAME , filePath1, 7 , 0 , false ));
317
+ }
318
+
319
+ Future <void > test_isolateSend_pluginShutdown () async {
320
+ await assertValidForIsolateSend (PluginShutdownParams ());
321
+ }
322
+
323
+ Future <void > test_isolateSend_pluginVersionCheck () async {
324
+ await assertValidForIsolateSend (
325
+ PluginVersionCheckParams ('byteStorePath' , 'sdkPath' , '0.1.0' ));
326
+ }
327
+
328
+ Future <void > test_isolateSend_setContextRoots () async {
329
+ await assertValidForIsolateSend (
330
+ AnalysisSetContextRootsParams ([contextRoot1]));
331
+ }
332
+
232
333
void test_onDone () {
233
334
channel.sendDone ();
234
335
}
0 commit comments