diff --git a/pkg/analysis_server/lib/src/computer/computer_lazy_type_hierarchy.dart b/pkg/analysis_server/lib/src/computer/computer_lazy_type_hierarchy.dart index 2ad21309f38..b290667296f 100644 --- a/pkg/analysis_server/lib/src/computer/computer_lazy_type_hierarchy.dart +++ b/pkg/analysis_server/lib/src/computer/computer_lazy_type_hierarchy.dart @@ -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(); - element = type?.name.staticElement; + type = node?.thisOrAncestorOfType()?.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]. diff --git a/pkg/analysis_server/test/src/computer/type_hierarchy_computer_test.dart b/pkg/analysis_server/test/src/computer/type_hierarchy_computer_test.dart index 5e9df760714..bdef622ffc5 100644 --- a/pkg/analysis_server/test/src/computer/type_hierarchy_computer_test.dart +++ b/pkg/analysis_server/test/src/computer/type_hierarchy_computer_test.dart @@ -728,4 +728,22 @@ int? b; ), ); } + + /// Ensure invocations directly on a type with type args retain those args. + Future test_typeReference_generic() async { + final content = ''' +/*[0*/class /*[1*/MyClass1/*1]*/ {}/*0]*/ +MyCl^ass1? a; + '''; + + addTestSource(content); + await expectTarget( + _isItem( + 'MyClass1', + testFile, + codeRange: code.ranges[0].sourceRange, + nameRange: code.ranges[1].sourceRange, + ), + ); + } }