mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Name translation: Allow type name translation when cursor points to constructor call. rdar://33163114 (#10872)
This commit is contained in:
@@ -952,8 +952,18 @@ static DeclName getSwiftDeclName(const ValueDecl *VD,
|
||||
}
|
||||
|
||||
/// Returns true for failure to resolve.
|
||||
static bool passNameInfoForDecl(const ValueDecl *VD, NameTranslatingInfo &Info,
|
||||
static bool passNameInfoForDecl(SemaToken SemaTok, NameTranslatingInfo &Info,
|
||||
std::function<void(const NameTranslatingInfo &)> Receiver) {
|
||||
auto *VD = SemaTok.ValueD;
|
||||
|
||||
// If the given name is not a function name, and the cursor points to
|
||||
// a contructor call, we use the type declaration instead of the init
|
||||
// declaration to translate the name.
|
||||
if (Info.ArgNames.empty() && !Info.IsZeroArgSelector) {
|
||||
if (auto *TD = SemaTok.CtorTyRef) {
|
||||
VD = TD;
|
||||
}
|
||||
}
|
||||
switch (SwiftLangSupport::getNameKindForUID(Info.NameKind)) {
|
||||
case NameKind::Swift: {
|
||||
NameTranslatingInfo Result;
|
||||
@@ -993,6 +1003,7 @@ static bool passNameInfoForDecl(const ValueDecl *VD, NameTranslatingInfo &Info,
|
||||
|
||||
const clang::NamedDecl *Named = nullptr;
|
||||
auto *BaseDecl = VD;
|
||||
|
||||
while (!Named && BaseDecl) {
|
||||
Named = dyn_cast_or_null<clang::NamedDecl>(BaseDecl->getClangDecl());
|
||||
BaseDecl = BaseDecl->getOverriddenDecl();
|
||||
@@ -1274,7 +1285,7 @@ static void resolveName(SwiftLangSupport &Lang, StringRef InputFile,
|
||||
return;
|
||||
|
||||
case SemaTokenKind::ValueRef: {
|
||||
bool Failed = passNameInfoForDecl(SemaTok.ValueD, Input, Receiver);
|
||||
bool Failed = passNameInfoForDecl(SemaTok, Input, Receiver);
|
||||
if (Failed) {
|
||||
if (!getPreviousASTSnaps().empty()) {
|
||||
// Attempt again using the up-to-date AST.
|
||||
@@ -1504,10 +1515,8 @@ getNameInfo(StringRef InputFile, unsigned Offset, NameTranslatingInfo &Input,
|
||||
if (Entity.Mod) {
|
||||
// Module is ignored
|
||||
} else {
|
||||
NameTranslatingInfo NewInput = Input;
|
||||
// FIXME: Should pass the main module for the interface but currently
|
||||
// it's not necessary.
|
||||
passNameInfoForDecl(Entity.Dcl, NewInput, Receiver);
|
||||
}
|
||||
} else {
|
||||
Receiver({});
|
||||
|
||||
Reference in New Issue
Block a user