diff --git a/pkg/analysis_server/lib/src/utilities/navigation/keyword_navigation_computer.dart b/pkg/analysis_server/lib/src/utilities/navigation/keyword_navigation_computer.dart index b99cc8c5bc5..2ccd6ca7fd7 100644 --- a/pkg/analysis_server/lib/src/utilities/navigation/keyword_navigation_computer.dart +++ b/pkg/analysis_server/lib/src/utilities/navigation/keyword_navigation_computer.dart @@ -65,9 +65,12 @@ class KeywordNavigationComputer { MethodDeclaration() => function.name, ConstructorDeclaration() => // For named constructors, return the name. - // For unnamed constructors, use the return type / class name. - // TODO(scheglov): support primary constructors - function.name ?? function.typeName!.beginToken, + // For unnamed constructors, use the return type / class name, or the + // `new` or `factory` keyword. + function.name ?? + function.typeName?.beginToken ?? + function.newKeyword ?? + function.factoryKeyword, _ => null, }; } diff --git a/pkg/analysis_server/test/lsp/definition_test.dart b/pkg/analysis_server/test/lsp/definition_test.dart index 2785b40a189..69b50757f96 100644 --- a/pkg/analysis_server/test/lsp/definition_test.dart +++ b/pkg/analysis_server/test/lsp/definition_test.dart @@ -1057,6 +1057,31 @@ class MyClass { await testContents(contents); } + Future test_keywordNavigation_return_toConstructor_withFactory() async { + var contents = ''' +class MyClass { + [!factory!] () { + ret^urn MyClass.n(); + } + MyClass.n(); +} +'''; + + await testContents(contents); + } + + Future test_keywordNavigation_return_toConstructor_withNew() async { + var contents = ''' +class MyClass { + [!new!] () { + ret^urn; + } +} +'''; + + await testContents(contents); + } + Future test_keywordNavigation_return_toFunction() async { var contents = ''' int [!foo!]() {