[analysis_server] Add failing test for auto-import extensions
See https://github.com/dart-lang/sdk/issues/56320 Change-Id: I6a21ef528d6d67a34e7f845c6cb279f246fe2762 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382621 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Keerti Parthasarathy <keertip@google.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com>
This commit is contained in:
committed by
Commit Queue
parent
6addfa0acb
commit
ddab694633
@@ -3271,6 +3271,65 @@ void f() {
|
||||
expect(resolved.detail, isNot(contains('Auto import from')));
|
||||
}
|
||||
|
||||
/// Verify extensions can be auto-imported if not already in-scope.
|
||||
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/56320')
|
||||
Future<void> test_unimportedSymbols_extension() async {
|
||||
// Define extensions in 'extensions.dart'.
|
||||
newFile(
|
||||
join(projectFolderPath, 'lib', 'extensions.dart'),
|
||||
'''
|
||||
extension StringExtensions on String {
|
||||
String get empty => '';
|
||||
}
|
||||
''',
|
||||
);
|
||||
|
||||
// Also import the extensions into an unrelated file to ensure this doesn't
|
||||
// cause extra suggestions (https://github.com/dart-lang/sdk/issues/56320).
|
||||
newFile(
|
||||
join(projectFolderPath, 'lib', 'other.dart'),
|
||||
'import "extensions.dart";',
|
||||
);
|
||||
|
||||
var content = '''
|
||||
void f(String a) {
|
||||
a.empt^
|
||||
}
|
||||
''';
|
||||
|
||||
await initialize();
|
||||
var code = TestCode.parse(content);
|
||||
await openFile(mainFileUri, code.code);
|
||||
await initialAnalysis;
|
||||
var res = await getCompletion(mainFileUri, code.position.position);
|
||||
|
||||
// Expect only a single entry for the 'empty' extension member.
|
||||
var completions = res.where((c) => c.label == 'empty');
|
||||
expect(completions, hasLength(1));
|
||||
|
||||
// Expect it to auto-import from 'extensions.dart'.
|
||||
var resolved = await resolveCompletion(completions.single);
|
||||
expect(
|
||||
resolved.detail,
|
||||
startsWith("Auto import from 'package:test/extensions.dart'"),
|
||||
);
|
||||
|
||||
// Verify the edits.
|
||||
var newContent = applyTextEdits(
|
||||
code.code,
|
||||
[toTextEdit(resolved.textEdit!)]
|
||||
.followedBy(resolved.additionalTextEdits!)
|
||||
.toList(),
|
||||
);
|
||||
expect(newContent, equals('''
|
||||
import 'package:test/extensions.dart';
|
||||
|
||||
void f(String a) {
|
||||
a.empty
|
||||
}
|
||||
'''));
|
||||
}
|
||||
|
||||
Future<void> test_unimportedSymbols_filtersOutAlreadyImportedSymbols() async {
|
||||
newFile(
|
||||
join(projectFolderPath, 'lib', 'source_file.dart'),
|
||||
|
||||
Reference in New Issue
Block a user