[analysis_server] Support extension types in Call Hierarchy

Change-Id: Ibc7a2df9135da1169e45b5eca4861a213eeea4f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324201
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2023-09-05 15:46:07 +00:00 committed by Commit Queue
parent 82bd6a2e43
commit cf5336c244
2 changed files with 110 additions and 0 deletions

View file

@ -26,6 +26,7 @@ Element? _getContainer(Element element) {
ElementKind.CONSTRUCTOR,
ElementKind.ENUM,
ElementKind.EXTENSION,
ElementKind.EXTENSION_TYPE,
ElementKind.FUNCTION,
ElementKind.GETTER,
ElementKind.METHOD,

View file

@ -244,6 +244,47 @@ class IncomingCallHierarchyTest extends AbstractLspAnalysisServerTest {
);
}
Future<void> test_method_extension() async {
final contents = '''
extension type E1(int a) {
void foo^() {}
}
''';
final otherContents = '''
import 'main.dart';
extension type E2(E1 a) {
void g() {
a.foo();
}
}
''';
await expectResults(
mainContents: contents,
otherContents: otherContents,
expectedResults: [
CallHierarchyIncomingCall(
// Container of the call
from: CallHierarchyItem(
name: 'g',
detail: 'E2',
kind: SymbolKind.Method,
uri: otherFileUri,
range: rangeOfPattern(
otherContents, RegExp(r'void g\(\) \{.*\ }', dotAll: true)),
selectionRange: rangeOfString(otherContents, 'g'),
),
// Ranges of calls within this container
fromRanges: [
rangeOfString(otherContents, 'foo'),
],
),
],
);
}
Future<void> test_namedConstructor() async {
final contents = '''
class Foo {
@ -517,6 +558,46 @@ class OutgoingCallHierarchyTest extends AbstractLspAnalysisServerTest {
);
}
Future<void> test_method_extensionType() async {
final contents = '''
import 'other.dart';
extension type E2(E1 a) {
void g^() {
a.foo();
}
}
''';
final otherContents = '''
extension type E1(int a) {
void foo() {}
}
''';
await expectResults(
mainContents: contents,
otherContents: otherContents,
expectedResults: [
CallHierarchyOutgoingCall(
// Target of the call.
to: CallHierarchyItem(
name: 'foo',
detail: 'E1',
kind: SymbolKind.Method,
uri: otherFileUri,
range: rangeOfString(otherContents, 'void foo() {}'),
selectionRange: rangeOfString(otherContents, 'foo'),
),
// Ranges of the outbound call.
fromRanges: [
rangeOfString(contents, 'foo'),
],
),
],
);
}
Future<void> test_namedConstructor() async {
final contents = '''
import 'other.dart';
@ -781,6 +862,34 @@ class PrepareCallHierarchyTest extends AbstractLspAnalysisServerTest {
);
}
Future<void> test_methodCall_extension() async {
final contents = '''
import 'other.dart';
void main() {
E1(1).f^();
}
''';
final otherContents = '''
extension type E1(int a) {
void f() {}
}
''';
await expectResults(
mainContents: contents,
otherContents: otherContents,
expectedResult: CallHierarchyItem(
name: 'f',
detail: 'E1',
kind: SymbolKind.Method,
uri: otherFileUri,
range: rangeOfString(otherContents, 'void f() {}'),
selectionRange: rangeOfString(otherContents, 'f')),
);
}
Future<void> test_namedConstructor() async {
final contents = '''
class Foo {