diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart index 57b2493bbcf4..9d40541816d7 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart @@ -252,7 +252,10 @@ import 'package:analyzer/src/generated/parser.dart'; import 'package:linter/src/lint_codes.dart'; final _builtInLintMultiProducers = { - LinterLintCode.comment_references: [ImportLibrary.forType], + LinterLintCode.comment_references: [ + ImportLibrary.forType, + ImportLibrary.forExtension, + ], LinterLintCode.deprecated_member_use_from_same_package_without_message: [ DataDriven.new, ], @@ -1094,8 +1097,8 @@ final _builtInNonLintProducers = >{ // updated so that only the appropriate subset is generated. QualifyReference.new, ], - CompileTimeErrorCode.UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE: - [ + CompileTimeErrorCode + .UNQUALIFIED_REFERENCE_TO_STATIC_MEMBER_OF_EXTENDED_TYPE: [ // TODO(brianwilkerson): Consider adding fixes to create a field, getter, // method or setter. The existing producers would need to be updated so // that only the appropriate subset is generated. diff --git a/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart b/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart index 558ec02c215a..535471ebc5d1 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/import_library_project_test.dart @@ -314,6 +314,23 @@ void f() { await assertNoFix(); } + Future test_extension_name() async { + createAnalysisOptionsFile(lints: [LintNames.comment_references]); + newFile('$testPackageLibPath/lib.dart', ''' +extension Ext on int {} +'''); + await resolveTestCode(''' +/// This should import [Ext]. +void f() {} +'''); + await assertHasFix(''' +import 'package:test/lib.dart'; + +/// This should import [Ext]. +void f() {} +'''); + } + Future test_extension_notImported_binaryOperator() async { newFile('$testPackageLibPath/lib.dart', ''' extension E on String { @@ -2164,6 +2181,25 @@ class ImportLibraryProject2Test extends FixProcessorTest { @override FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT2; + Future test_extension_name() async { + createAnalysisOptionsFile(lints: [LintNames.comment_references]); + newFile('$testPackageLibPath/lib1.dart', ''' +extension Ext on int {} +'''); + newFile('$testPackageLibPath/lib2.dart', ''' +export 'package:test/lib1.dart';'''); + await resolveTestCode(''' +/// This should import [Ext]. +void f() {} +'''); + await assertHasFix(''' +import 'package:test/lib2.dart'; + +/// This should import [Ext]. +void f() {} +'''); + } + Future test_lib() async { newFile('$packagesRootPath/my_pkg/lib/a.dart', ''' export 'b.dart'; @@ -2540,6 +2576,23 @@ class ImportLibraryProject3Test extends FixProcessorTest { @override FixKind get kind => DartFixKind.IMPORT_LIBRARY_PROJECT3; + Future test_extension_name() async { + createAnalysisOptionsFile(lints: [LintNames.comment_references]); + newFile('$testPackageLibPath/src/lib1.dart', ''' +extension Ext on int {} +'''); + await resolveTestCode(''' +/// This should import [Ext]. +void f() {} +'''); + await assertHasFix(''' +import 'package:test/src/lib1.dart'; + +/// This should import [Ext]. +void f() {} +'''); + } + Future test_inLibSrc_thisContextRoot_extension() async { newFile('$testPackageLibPath/src/lib.dart', ''' extension E on int {