mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
[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:
parent
b848f4df59
commit
77a480ca49
|
@ -83,22 +83,22 @@ class DartLazyTypeHierarchyComputer {
|
||||||
TypeHierarchyItem? findTarget(int offset) {
|
TypeHierarchyItem? findTarget(int offset) {
|
||||||
final node = NodeLocator2(offset).searchWithin(_result.unit);
|
final node = NodeLocator2(offset).searchWithin(_result.unit);
|
||||||
|
|
||||||
Element? element;
|
DartType? type;
|
||||||
|
|
||||||
// Try named types.
|
// Try named types.
|
||||||
final type = node?.thisOrAncestorOfType<NamedType>();
|
type = node?.thisOrAncestorOfType<NamedType>()?.type;
|
||||||
element = type?.name.staticElement;
|
|
||||||
|
|
||||||
if (element == null) {
|
if (type == null) {
|
||||||
// Try enclosing class/mixins.
|
// Try enclosing class/mixins.
|
||||||
final Declaration? declaration = node
|
final Declaration? declaration = node
|
||||||
?.thisOrAncestorMatching((node) => _isValidTargetDeclaration(node));
|
?.thisOrAncestorMatching((node) => _isValidTargetDeclaration(node));
|
||||||
element = declaration?.declaredElement;
|
final element = declaration?.declaredElement;
|
||||||
|
if (element is InterfaceElement) {
|
||||||
|
type = element.thisType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return element is InterfaceElement
|
return type is InterfaceType ? TypeHierarchyItem.forType(type) : null;
|
||||||
? TypeHierarchyItem.forType(element.thisType)
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locate the [Element] referenced by [location].
|
/// Locate the [Element] referenced by [location].
|
||||||
|
|
|
@ -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,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue