[analysis_server] Handle type arguments on named type references for initial Call Hierarchy item

Change-Id: I5e30c808ddda7ff7817f7be7dd0ecff9a725854c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265501
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2022-10-25 16:31:10 +00:00 committed by Commit Queue
parent b848f4df59
commit 77a480ca49
2 changed files with 26 additions and 8 deletions

View file

@ -83,22 +83,22 @@ class DartLazyTypeHierarchyComputer {
TypeHierarchyItem? findTarget(int offset) {
final node = NodeLocator2(offset).searchWithin(_result.unit);
Element? element;
DartType? type;
// Try named types.
final type = node?.thisOrAncestorOfType<NamedType>();
element = type?.name.staticElement;
type = node?.thisOrAncestorOfType<NamedType>()?.type;
if (element == null) {
if (type == null) {
// Try enclosing class/mixins.
final Declaration? declaration = node
?.thisOrAncestorMatching((node) => _isValidTargetDeclaration(node));
element = declaration?.declaredElement;
final element = declaration?.declaredElement;
if (element is InterfaceElement) {
type = element.thisType;
}
}
return element is InterfaceElement
? TypeHierarchyItem.forType(element.thisType)
: null;
return type is InterfaceType ? TypeHierarchyItem.forType(type) : null;
}
/// Locate the [Element] referenced by [location].

View file

@ -728,4 +728,22 @@ int? b;
),
);
}
/// Ensure invocations directly on a type with type args retain those args.
Future<void> test_typeReference_generic() async {
final content = '''
/*[0*/class /*[1*/MyClass1/*1]*/<T1, T2> {}/*0]*/
MyCl^ass1<String, String>? a;
''';
addTestSource(content);
await expectTarget(
_isItem(
'MyClass1<String, String>',
testFile,
codeRange: code.ranges[0].sourceRange,
nameRange: code.ranges[1].sourceRange,
),
);
}
}