@@ -613,9 +613,16 @@ static bool passCursorInfoForModule(ModuleEntity Mod,
613
613
return false ;
614
614
}
615
615
616
- static Optional<unsigned > getParamParentNameOffset (const ValueDecl *VD) {
616
+ static Optional<unsigned >
617
+ getParamParentNameOffset (const ValueDecl *VD, SourceLoc Cursor) {
618
+ if (Cursor.isInvalid ())
619
+ return None;
617
620
SourceLoc Loc;
618
621
if (auto PD = dyn_cast<ParamDecl>(VD)) {
622
+
623
+ // Avoid returning parent loc for internal-only names.
624
+ if (PD->getArgumentNameLoc ().isValid () && PD->getNameLoc () == Cursor)
625
+ return None;
619
626
auto *DC = PD->getDeclContext ();
620
627
switch (DC->getContextKind ()) {
621
628
case DeclContextKind::SubscriptDecl:
@@ -642,6 +649,7 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
642
649
const Type ContainerTy,
643
650
bool IsRef,
644
651
Optional<unsigned > OrigBufferID,
652
+ SourceLoc CursorLoc,
645
653
SwiftLangSupport &Lang,
646
654
const CompilerInvocation &Invok,
647
655
ArrayRef<ImmutableTextSnapshotRef> PreviousASTSnaps,
@@ -875,7 +883,7 @@ static bool passCursorInfoForDecl(const ValueDecl *VD,
875
883
Info.LocalizationKey = LocalizationKey;
876
884
Info.IsSystem = IsSystem;
877
885
Info.TypeInterface = StringRef ();
878
- Info.ParentNameOffset = getParamParentNameOffset (VD);
886
+ Info.ParentNameOffset = getParamParentNameOffset (VD, CursorLoc );
879
887
Receiver (Info);
880
888
return false ;
881
889
}
@@ -1152,7 +1160,7 @@ static void resolveCursor(SwiftLangSupport &Lang,
1152
1160
bool Failed = passCursorInfoForDecl (VD, MainModule,
1153
1161
SemaTok.ContainerType ,
1154
1162
SemaTok.ContainerType ,
1155
- SemaTok.IsRef , BufferID, Lang,
1163
+ SemaTok.IsRef , BufferID, Loc, Lang,
1156
1164
CompInvok, getPreviousASTSnaps (),
1157
1165
Receiver);
1158
1166
if (Failed) {
@@ -1406,7 +1414,7 @@ void SwiftLangSupport::getCursorInfo(
1406
1414
// it's not necessary.
1407
1415
passCursorInfoForDecl (
1408
1416
Entity.Dcl , /* MainModule*/ nullptr , Type (), Type (), Entity.IsRef ,
1409
- /* OrigBufferID=*/ None, *this , Invok, {}, Receiver);
1417
+ /* OrigBufferID=*/ None, SourceLoc (), *this , Invok, {}, Receiver);
1410
1418
}
1411
1419
} else {
1412
1420
Receiver ({});
@@ -1593,8 +1601,8 @@ resolveCursorFromUSR(SwiftLangSupport &Lang, StringRef InputFile, StringRef USR,
1593
1601
}
1594
1602
bool Failed =
1595
1603
passCursorInfoForDecl (VD, MainModule, selfTy, Type (),
1596
- /* IsRef=*/ false , BufferID, Lang, CompInvok ,
1597
- PreviousASTSnaps, Receiver);
1604
+ /* IsRef=*/ false , BufferID, SourceLoc (), Lang ,
1605
+ CompInvok, PreviousASTSnaps, Receiver);
1598
1606
if (Failed) {
1599
1607
if (!PreviousASTSnaps.empty ()) {
1600
1608
// Attempt again using the up-to-date AST.
0 commit comments