@@ -952,8 +952,18 @@ static DeclName getSwiftDeclName(const ValueDecl *VD,
952
952
}
953
953
954
954
// / Returns true for failure to resolve.
955
- static bool passNameInfoForDecl (const ValueDecl *VD , NameTranslatingInfo &Info,
955
+ static bool passNameInfoForDecl (SemaToken SemaTok , NameTranslatingInfo &Info,
956
956
std::function<void (const NameTranslatingInfo &)> Receiver) {
957
+ auto *VD = SemaTok.ValueD ;
958
+
959
+ // If the given name is not a function name, and the cursor points to
960
+ // a contructor call, we use the type declaration instead of the init
961
+ // declaration to translate the name.
962
+ if (Info.ArgNames .empty () && !Info.IsZeroArgSelector ) {
963
+ if (auto *TD = SemaTok.CtorTyRef ) {
964
+ VD = TD;
965
+ }
966
+ }
957
967
switch (SwiftLangSupport::getNameKindForUID (Info.NameKind )) {
958
968
case NameKind::Swift: {
959
969
NameTranslatingInfo Result;
@@ -993,6 +1003,7 @@ static bool passNameInfoForDecl(const ValueDecl *VD, NameTranslatingInfo &Info,
993
1003
994
1004
const clang::NamedDecl *Named = nullptr ;
995
1005
auto *BaseDecl = VD;
1006
+
996
1007
while (!Named && BaseDecl) {
997
1008
Named = dyn_cast_or_null<clang::NamedDecl>(BaseDecl->getClangDecl ());
998
1009
BaseDecl = BaseDecl->getOverriddenDecl ();
@@ -1273,7 +1284,7 @@ static void resolveName(SwiftLangSupport &Lang, StringRef InputFile,
1273
1284
return ;
1274
1285
1275
1286
case SemaTokenKind::ValueRef: {
1276
- bool Failed = passNameInfoForDecl (SemaTok. ValueD , Input, Receiver);
1287
+ bool Failed = passNameInfoForDecl (SemaTok, Input, Receiver);
1277
1288
if (Failed) {
1278
1289
if (!getPreviousASTSnaps ().empty ()) {
1279
1290
// Attempt again using the up-to-date AST.
@@ -1502,10 +1513,8 @@ getNameInfo(StringRef InputFile, unsigned Offset, NameTranslatingInfo &Input,
1502
1513
if (Entity.Mod ) {
1503
1514
// Module is ignored
1504
1515
} else {
1505
- NameTranslatingInfo NewInput = Input;
1506
1516
// FIXME: Should pass the main module for the interface but currently
1507
1517
// it's not necessary.
1508
- passNameInfoForDecl (Entity.Dcl , NewInput, Receiver);
1509
1518
}
1510
1519
} else {
1511
1520
Receiver ({});
0 commit comments