FixCrash. Fix Search / FindDeclarations for not crashing on unnamed declarations.
Change-Id: Ia405b46cb451220ad10e5a15cbe8a757c41c6e46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493660 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
committed by
Commit Queue
parent
8999b65531
commit
df2e67bb86
@@ -78,6 +78,24 @@ void f() {}
|
||||
expect(symbolsResponse2.error, isNull);
|
||||
}
|
||||
|
||||
Future<void> test_class_unnamed() async {
|
||||
const content = '''
|
||||
class {
|
||||
void foo() {}
|
||||
}
|
||||
''';
|
||||
var code = TestCode.parse(content);
|
||||
newFile(mainFilePath, code.code);
|
||||
|
||||
failTestOnErrorDiagnostic = false;
|
||||
await provideConfig(initialize, {
|
||||
'includeDependenciesInWorkspaceSymbols': false,
|
||||
});
|
||||
|
||||
var symbols = await getWorkspaceSymbols('foo');
|
||||
expect(symbols, isEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_constructor_primary_named_noBody() async {
|
||||
const content = '''
|
||||
/*[0*/class /*[1*/UniqueClassName.namedUnique(int a)/*1]*/;/*0]*/
|
||||
@@ -292,6 +310,24 @@ class UniqueClassName {
|
||||
expect(await getWorkspaceSymbols('LocalClass12345'), isNotEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_enum_unnamed() async {
|
||||
const content = '''
|
||||
enum {
|
||||
v
|
||||
}
|
||||
''';
|
||||
var code = TestCode.parse(content);
|
||||
newFile(mainFilePath, code.code);
|
||||
|
||||
failTestOnErrorDiagnostic = false;
|
||||
await provideConfig(initialize, {
|
||||
'includeDependenciesInWorkspaceSymbols': false,
|
||||
});
|
||||
|
||||
var symbols = await getWorkspaceSymbols('v');
|
||||
expect(symbols, isEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_extensions() async {
|
||||
const content = '''
|
||||
extension StringExtensions on String {}
|
||||
@@ -348,6 +384,22 @@ extension type E(int it) {
|
||||
expect(namedExtensions.containerName, 'E');
|
||||
}
|
||||
|
||||
Future<void> test_extensionType_unnamed() async {
|
||||
const content = '''
|
||||
extension type (int it) {}
|
||||
''';
|
||||
var code = TestCode.parse(content);
|
||||
newFile(mainFilePath, code.code);
|
||||
|
||||
failTestOnErrorDiagnostic = false;
|
||||
await provideConfig(initialize, {
|
||||
'includeDependenciesInWorkspaceSymbols': false,
|
||||
});
|
||||
|
||||
var symbols = await getWorkspaceSymbols('it');
|
||||
expect(symbols, isEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_fullMatch() async {
|
||||
const content = '''
|
||||
[!String topLevel = ''!];
|
||||
@@ -425,6 +477,24 @@ class MyClass {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> test_mixin_unnamed() async {
|
||||
const content = '''
|
||||
mixin {
|
||||
void foo() {}
|
||||
}
|
||||
''';
|
||||
var code = TestCode.parse(content);
|
||||
newFile(mainFilePath, code.code);
|
||||
|
||||
failTestOnErrorDiagnostic = false;
|
||||
await provideConfig(initialize, {
|
||||
'includeDependenciesInWorkspaceSymbols': false,
|
||||
});
|
||||
|
||||
var symbols = await getWorkspaceSymbols('foo');
|
||||
expect(symbols, isEmpty);
|
||||
}
|
||||
|
||||
/// Ensure that multiple projects/drivers do not result in duplicate results
|
||||
/// for things referenced in both projects.
|
||||
Future<void> test_overlappingDrivers() async {
|
||||
|
||||
@@ -1315,12 +1315,14 @@ class _FindLibraryDeclarations {
|
||||
void _addClasses(List<InterfaceElement> elements) {
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
_addDeclaration(element, element.name!);
|
||||
_addGetters(element.getters);
|
||||
_addConstructors(element.constructors);
|
||||
_addFields(element.fields);
|
||||
_addMethods(element.methods);
|
||||
_addSetters(element.setters);
|
||||
if (element.name case var name?) {
|
||||
_addDeclaration(element, name);
|
||||
_addGetters(element.getters);
|
||||
_addConstructors(element.constructors);
|
||||
_addFields(element.fields);
|
||||
_addMethods(element.methods);
|
||||
_addSetters(element.setters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,6 +325,29 @@ testFile
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_class_unnamed() async {
|
||||
await resolveTestCode('''
|
||||
class {
|
||||
void foo() {}
|
||||
}
|
||||
''');
|
||||
var results = WorkspaceSymbols();
|
||||
await FindDeclarations(
|
||||
[driver],
|
||||
results,
|
||||
'foo',
|
||||
null,
|
||||
ownedFiles: analysisContextCollection.ownedFiles,
|
||||
performance: performance,
|
||||
).compute();
|
||||
assertDeclarationsText(
|
||||
results,
|
||||
{testFile: 'testFile'},
|
||||
r'''
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_discover() async {
|
||||
var aaaPackageRootPath = '$packagesRootPath/aaa';
|
||||
var bbbPackageRootPath = '$packagesRootPath/bbb';
|
||||
@@ -417,6 +440,29 @@ testFile
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_enum_unnamed() async {
|
||||
await resolveTestCode('''
|
||||
enum {
|
||||
foo
|
||||
}
|
||||
''');
|
||||
var results = WorkspaceSymbols();
|
||||
await FindDeclarations(
|
||||
[driver],
|
||||
results,
|
||||
'foo',
|
||||
null,
|
||||
ownedFiles: analysisContextCollection.ownedFiles,
|
||||
performance: performance,
|
||||
).compute();
|
||||
assertDeclarationsText(
|
||||
results,
|
||||
{testFile: 'testFile'},
|
||||
r'''
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_extension() async {
|
||||
await resolveTestCode('''
|
||||
extension E on int {
|
||||
@@ -509,6 +555,27 @@ testFile
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_extensionType_unnamed() async {
|
||||
await resolveTestCode('''
|
||||
extension type (int foo) {}
|
||||
''');
|
||||
var results = WorkspaceSymbols();
|
||||
await FindDeclarations(
|
||||
[driver],
|
||||
results,
|
||||
'foo',
|
||||
null,
|
||||
ownedFiles: analysisContextCollection.ownedFiles,
|
||||
performance: performance,
|
||||
).compute();
|
||||
assertDeclarationsText(
|
||||
results,
|
||||
{testFile: 'testFile'},
|
||||
r'''
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_fuzzyMatch() async {
|
||||
await resolveTestCode('''
|
||||
class A {}
|
||||
@@ -603,6 +670,29 @@ testFile
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_mixin_unnamed() async {
|
||||
await resolveTestCode('''
|
||||
mixin {
|
||||
void foo() {}
|
||||
}
|
||||
''');
|
||||
var results = WorkspaceSymbols();
|
||||
await FindDeclarations(
|
||||
[driver],
|
||||
results,
|
||||
'foo',
|
||||
null,
|
||||
ownedFiles: analysisContextCollection.ownedFiles,
|
||||
performance: performance,
|
||||
).compute();
|
||||
assertDeclarationsText(
|
||||
results,
|
||||
{testFile: 'testFile'},
|
||||
r'''
|
||||
''',
|
||||
);
|
||||
}
|
||||
|
||||
test_declarations_onlyForFile() async {
|
||||
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
||||
var b = newFile('$testPackageLibPath/b.dart', 'class B {}');
|
||||
|
||||
Reference in New Issue
Block a user