3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'package:analysis_server/src/cider/completion.dart' ;
6
+ import 'package:analyzer/dart/analysis/results.dart' ;
6
7
import 'package:analyzer/source/line_info.dart' ;
8
+ import 'package:analyzer/src/test_utilities/function_ast_visitor.dart' ;
7
9
import 'package:analyzer_plugin/protocol/protocol_common.dart'
8
10
show CompletionSuggestion, CompletionSuggestionKind, ElementKind;
9
11
import 'package:meta/meta.dart' ;
@@ -23,11 +25,11 @@ class CiderCompletionComputerTest extends CiderServiceTest {
23
25
final CiderCompletionCache _completionCache = CiderCompletionCache ();
24
26
25
27
CiderCompletionComputer _computer;
28
+ void Function (ResolvedUnitResult ) _testResolvedUnit;
29
+
26
30
CiderCompletionResult _completionResult;
27
31
List <CompletionSuggestion > _suggestions;
28
32
29
- Future <void > test_limitedResolution_;
30
-
31
33
@override
32
34
void setUp () {
33
35
super .setUp ();
@@ -295,10 +297,34 @@ main() {
295
297
]);
296
298
}
297
299
298
- Future <void > test_limitedResolution_class_method () async {
300
+ Future <void > test_limitedResolution_class_field_startWithType () async {
301
+ _configureToCheckNotResolved (
302
+ identifiers: {'print' },
303
+ );
304
+
305
+ await _compute (r'''
306
+ class A {
307
+ void foo() {
308
+ print(0);
309
+ }
310
+
311
+ Str^
312
+ }
313
+ ''' );
314
+
315
+ _assertHasClass (text: 'String' );
316
+ }
317
+
318
+ Future <void > test_limitedResolution_class_method_body () async {
319
+ _configureToCheckNotResolved (
320
+ identifiers: {'print' },
321
+ );
322
+
299
323
await _compute (r'''
300
324
class A<T> {
301
- void foo() {}
325
+ void foo() {
326
+ print(0);
327
+ }
302
328
303
329
void bar<U>(int a) {
304
330
^
@@ -323,31 +349,44 @@ enum E { e }
323
349
_assertHasTypeParameter (text: 'U' );
324
350
}
325
351
326
- Future <void > test_limitedResolution_unit_function () async {
352
+ Future <void > test_limitedResolution_class_method_parameterType () async {
353
+ _configureToCheckNotResolved (
354
+ identifiers: {'print' },
355
+ );
356
+
327
357
await _compute (r'''
328
- void foo() {}
358
+ class A {
359
+ void foo() {
360
+ print(0);
361
+ }
329
362
330
- void bar(int a) {
331
- ^
363
+ void bar(Str^) {}
332
364
}
333
365
''' );
334
366
335
- _assertHasFunction (text: 'foo' );
336
- _assertHasParameter (text: 'a' );
367
+ _assertHasClass (text: 'String' );
337
368
}
338
369
339
- Future <void > test_localTypeInference () async {
370
+ Future <void >
371
+ test_limitedResolution_class_method_returnType_hasPartial () async {
372
+ _configureToCheckNotResolved (
373
+ identifiers: {'print' },
374
+ );
375
+
340
376
await _compute (r'''
341
- void foo() {
342
- var a = 0;
343
- a.^
377
+ class A {
378
+ void foo() {
379
+ print(0);
380
+ }
381
+
382
+ Str^ bar() {}
344
383
}
345
384
''' );
346
385
347
- _assertHasGetter (text: 'isEven ' );
386
+ _assertHasClass (text: 'String ' );
348
387
}
349
388
350
- Future <void > test_partialResolution_hasPart () async {
389
+ Future <void > test_limitedResolution_hasPart () async {
351
390
newFile ('/workspace/dart/test/lib/a.dart' , content: r'''
352
391
class A {}
353
392
''' );
@@ -361,6 +400,36 @@ part 'a.dart';
361
400
_assertHasClass (text: 'A' );
362
401
}
363
402
403
+ Future <void > test_limitedResolution_unit_function_body () async {
404
+ _configureToCheckNotResolved (
405
+ identifiers: {'print' },
406
+ );
407
+
408
+ await _compute (r'''
409
+ void foo() {
410
+ print(0);
411
+ }
412
+
413
+ void bar(int a) {
414
+ ^
415
+ }
416
+ ''' );
417
+
418
+ _assertHasFunction (text: 'foo' );
419
+ _assertHasParameter (text: 'a' );
420
+ }
421
+
422
+ Future <void > test_localTypeInference () async {
423
+ await _compute (r'''
424
+ void foo() {
425
+ var a = 0;
426
+ a.^
427
+ }
428
+ ''' );
429
+
430
+ _assertHasGetter (text: 'isEven' );
431
+ }
432
+
364
433
Future <void > test_warmUp_cachesImportedLibraries () async {
365
434
var aPath = convertPath ('/workspace/dart/test/lib/a.dart' );
366
435
newFile (aPath, content: r'''
@@ -550,10 +619,28 @@ import 'a.dart';
550
619
path: convertPath (testPath),
551
620
line: context.line,
552
621
column: context.character,
622
+ testResolvedUnit: _testResolvedUnit,
553
623
);
554
624
_suggestions = _completionResult.suggestions;
555
625
}
556
626
627
+ /// Configure the [CiderCompletionComputer] to check that when resolving
628
+ /// for completion we don't resolve unnecessary node.
629
+ void _configureToCheckNotResolved ({Set <String > identifiers}) {
630
+ _testResolvedUnit = (resolvedUnitResult) {
631
+ var unit = resolvedUnitResult.unit;
632
+ unit.accept (
633
+ FunctionAstVisitor (
634
+ simpleIdentifier: (node) {
635
+ if (identifiers.contains (node.name) && node.staticElement != null ) {
636
+ fail ('Unexpectedly resolved node: $node ' );
637
+ }
638
+ },
639
+ ),
640
+ );
641
+ };
642
+ }
643
+
557
644
/// TODO(scheglov) Implement incremental updating
558
645
void _createFileResolver () {
559
646
createFileResolver ();
0 commit comments