@@ -3271,6 +3271,65 @@ void f() {
3271
3271
expect (resolved.detail, isNot (contains ('Auto import from' )));
3272
3272
}
3273
3273
3274
+ /// Verify extensions can be auto-imported if not already in-scope.
3275
+ @FailingTest (issue: 'https://github.com/dart-lang/sdk/issues/56320' )
3276
+ Future <void > test_unimportedSymbols_extension () async {
3277
+ // Define extensions in 'extensions.dart'.
3278
+ newFile (
3279
+ join (projectFolderPath, 'lib' , 'extensions.dart' ),
3280
+ '''
3281
+ extension StringExtensions on String {
3282
+ String get empty => '';
3283
+ }
3284
+ ''' ,
3285
+ );
3286
+
3287
+ // Also import the extensions into an unrelated file to ensure this doesn't
3288
+ // cause extra suggestions (https://github.com/dart-lang/sdk/issues/56320).
3289
+ newFile (
3290
+ join (projectFolderPath, 'lib' , 'other.dart' ),
3291
+ 'import "extensions.dart";' ,
3292
+ );
3293
+
3294
+ var content = '''
3295
+ void f(String a) {
3296
+ a.empt^
3297
+ }
3298
+ ''' ;
3299
+
3300
+ await initialize ();
3301
+ var code = TestCode .parse (content);
3302
+ await openFile (mainFileUri, code.code);
3303
+ await initialAnalysis;
3304
+ var res = await getCompletion (mainFileUri, code.position.position);
3305
+
3306
+ // Expect only a single entry for the 'empty' extension member.
3307
+ var completions = res.where ((c) => c.label == 'empty' );
3308
+ expect (completions, hasLength (1 ));
3309
+
3310
+ // Expect it to auto-import from 'extensions.dart'.
3311
+ var resolved = await resolveCompletion (completions.single);
3312
+ expect (
3313
+ resolved.detail,
3314
+ startsWith ("Auto import from 'package:test/extensions.dart'" ),
3315
+ );
3316
+
3317
+ // Verify the edits.
3318
+ var newContent = applyTextEdits (
3319
+ code.code,
3320
+ [toTextEdit (resolved.textEdit! )]
3321
+ .followedBy (resolved.additionalTextEdits! )
3322
+ .toList (),
3323
+ );
3324
+ expect (newContent, equals ('''
3325
+ import 'package:test/extensions.dart';
3326
+
3327
+ void f(String a) {
3328
+ a.empty
3329
+ }
3330
+ ''' ));
3331
+ }
3332
+
3274
3333
Future <void > test_unimportedSymbols_filtersOutAlreadyImportedSymbols () async {
3275
3334
newFile (
3276
3335
join (projectFolderPath, 'lib' , 'source_file.dart' ),
0 commit comments