@@ -767,17 +767,29 @@ void CodeCompletionResultBuilder::addChunkWithText(
767
767
addChunkWithTextNoCopy (Kind, copyString (*Sink.Allocator , Text));
768
768
}
769
769
770
- void CodeCompletionResultBuilder::setAssociatedDecl (const Decl *D) {
770
+ void CodeCompletionResultBuilder::setAssociatedDecl (const Decl *D,
771
+ SourceFile *SF) {
771
772
assert (Kind == CodeCompletionResult::ResultKind::Declaration);
772
773
AssociatedDecl = D;
773
-
774
774
if (auto *ClangD = D->getClangDecl ())
775
775
CurrentModule = ClangD->getImportedOwningModule ();
776
776
// FIXME: macros
777
777
// FIXME: imported header module
778
778
779
- if (!CurrentModule)
780
- CurrentModule = D->getModuleContext ();
779
+ if (!CurrentModule) {
780
+ ModuleDecl *MD = D->getModuleContext ();
781
+ // If this is an underscored cross-import overlay, map it to its underlying
782
+ // module instead.
783
+ if (SF) {
784
+ while (MD->getNameStr ().startswith (" _" )) {
785
+ auto *Underlying = SF->getModuleShadowedBySeparatelyImportedOverlay (MD);
786
+ if (!Underlying)
787
+ break ;
788
+ MD = Underlying;
789
+ }
790
+ }
791
+ CurrentModule = MD;
792
+ }
781
793
782
794
if (D->getAttrs ().getDeprecated (D->getASTContext ()))
783
795
setNotRecommended (CodeCompletionResult::Deprecated);
@@ -1549,6 +1561,15 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1549
1561
Builder.addDeclDocCommentWords (llvm::makeArrayRef (Pairs));
1550
1562
}
1551
1563
1564
+ // / Sets the given declaration \p D as the associated declaration of the
1565
+ // / completion result being built in \p Builder.
1566
+ void setAssociatedDecl (const Decl *D, CodeCompletionResultBuilder &Builder) {
1567
+ SourceFile *SF = nullptr ;
1568
+ if (CurrDeclContext)
1569
+ SF = CurrDeclContext->getParentSourceFile ();
1570
+ Builder.setAssociatedDecl (D, SF);
1571
+ }
1572
+
1552
1573
bool shouldUseFunctionReference (AbstractFunctionDecl *D) {
1553
1574
if (PreferFunctionReferencesToCalls)
1554
1575
return true ;
@@ -1726,7 +1747,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1726
1747
SemanticContextKind::None,
1727
1748
expectedTypeContext);
1728
1749
auto MD = ModuleDecl::create (Ctx.getIdentifier (Pair.first ), Ctx);
1729
- Builder. setAssociatedDecl (MD);
1750
+ setAssociatedDecl (MD, Builder );
1730
1751
Builder.addTextChunk (MD->getNameStr ());
1731
1752
Builder.addTypeAnnotation (" Module" );
1732
1753
if (Pair.second )
@@ -1740,7 +1761,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1740
1761
ImportFilter |= ModuleDecl::ImportFilterKind::Public;
1741
1762
ImportFilter |= ModuleDecl::ImportFilterKind::Private;
1742
1763
ImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
1743
- // FIXME: ImportFilterKind::ShadowedBySeparateOverlay?
1744
1764
1745
1765
SmallVector<ModuleDecl::ImportedModule, 16 > Imported;
1746
1766
SmallVector<ModuleDecl::ImportedModule, 16 > FurtherImported;
@@ -1755,21 +1775,27 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
1755
1775
MD->getImportedModules (FurtherImported,
1756
1776
ModuleDecl::ImportFilterKind::Public);
1757
1777
Imported.append (FurtherImported.begin (), FurtherImported.end ());
1758
- for (auto SubMod : FurtherImported) {
1759
- Imported.push_back (SubMod);
1760
- }
1761
1778
}
1762
1779
}
1763
1780
1764
1781
void addModuleName (
1765
1782
const ModuleDecl *MD,
1766
1783
Optional<CodeCompletionResult::NotRecommendedReason> R = None) {
1784
+
1785
+ // Don't add underscored cross-import overlay modules.
1786
+ if (CurrDeclContext && MD->getNameStr ().startswith (" _" )) {
1787
+ if (auto SF = CurrDeclContext->getParentSourceFile ()) {
1788
+ if (SF->getModuleShadowedBySeparatelyImportedOverlay (MD))
1789
+ return ;
1790
+ }
1791
+ }
1792
+
1767
1793
CodeCompletionResultBuilder Builder (
1768
1794
Sink,
1769
1795
CodeCompletionResult::ResultKind::Declaration,
1770
1796
SemanticContextKind::None,
1771
1797
expectedTypeContext);
1772
- Builder. setAssociatedDecl (MD);
1798
+ setAssociatedDecl (MD, Builder );
1773
1799
Builder.addTextChunk (MD->getNameStr ());
1774
1800
Builder.addTypeAnnotation (" Module" );
1775
1801
if (R)
@@ -2163,7 +2189,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2163
2189
CodeCompletionResultBuilder Builder (
2164
2190
Sink, CodeCompletionResult::ResultKind::Declaration,
2165
2191
getSemanticContext (VD, Reason, dynamicLookupInfo), expectedTypeContext);
2166
- Builder. setAssociatedDecl (VD);
2192
+ setAssociatedDecl (VD, Builder );
2167
2193
addLeadingDot (Builder);
2168
2194
addValueBaseName (Builder, Name);
2169
2195
setClangDeclKeywords (VD, Pairs, Builder);
@@ -2413,7 +2439,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2413
2439
Sink, CodeCompletionResult::ResultKind::Declaration,
2414
2440
SemanticContext ? *SemanticContext : getSemanticContextKind (SD),
2415
2441
expectedTypeContext);
2416
- Builder. setAssociatedDecl (SD);
2442
+ setAssociatedDecl (SD, Builder );
2417
2443
setClangDeclKeywords (SD, Pairs, Builder);
2418
2444
if (!HaveLParen)
2419
2445
Builder.addLeftBracket ();
@@ -2452,7 +2478,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2452
2478
SemanticContext ? *SemanticContext : getSemanticContextKind (AFD),
2453
2479
expectedTypeContext);
2454
2480
if (AFD) {
2455
- Builder. setAssociatedDecl (AFD);
2481
+ setAssociatedDecl (AFD, Builder );
2456
2482
setClangDeclKeywords (AFD, Pairs, Builder);
2457
2483
}
2458
2484
@@ -2583,7 +2609,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2583
2609
getSemanticContext (FD, Reason, dynamicLookupInfo),
2584
2610
expectedTypeContext);
2585
2611
setClangDeclKeywords (FD, Pairs, Builder);
2586
- Builder. setAssociatedDecl (FD);
2612
+ setAssociatedDecl (FD, Builder );
2587
2613
addLeadingDot (Builder);
2588
2614
addValueBaseName (Builder, Name);
2589
2615
if (IsDynamicLookup)
@@ -2696,7 +2722,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2696
2722
getSemanticContext (CD, Reason, dynamicLookupInfo),
2697
2723
expectedTypeContext);
2698
2724
setClangDeclKeywords (CD, Pairs, Builder);
2699
- Builder. setAssociatedDecl (CD);
2725
+ setAssociatedDecl (CD, Builder );
2700
2726
if (needInit) {
2701
2727
assert (addName.empty ());
2702
2728
addLeadingDot (Builder);
@@ -2787,7 +2813,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2787
2813
CodeCompletionResultBuilder Builder (
2788
2814
Sink, CodeCompletionResult::ResultKind::Declaration,
2789
2815
getSemanticContext (SD, Reason, dynamicLookupInfo), expectedTypeContext);
2790
- Builder. setAssociatedDecl (SD);
2816
+ setAssociatedDecl (SD, Builder );
2791
2817
setClangDeclKeywords (SD, Pairs, Builder);
2792
2818
2793
2819
// '\TyName#^TOKEN^#' requires leading dot.
@@ -2822,7 +2848,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2822
2848
Sink, CodeCompletionResult::ResultKind::Declaration,
2823
2849
getSemanticContext (NTD, Reason, dynamicLookupInfo),
2824
2850
expectedTypeContext);
2825
- Builder. setAssociatedDecl (NTD);
2851
+ setAssociatedDecl (NTD, Builder );
2826
2852
setClangDeclKeywords (NTD, Pairs, Builder);
2827
2853
addLeadingDot (Builder);
2828
2854
Builder.addTextChunk (NTD->getName ().str ());
@@ -2838,7 +2864,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2838
2864
Sink, CodeCompletionResult::ResultKind::Declaration,
2839
2865
getSemanticContext (TAD, Reason, dynamicLookupInfo),
2840
2866
expectedTypeContext);
2841
- Builder. setAssociatedDecl (TAD);
2867
+ setAssociatedDecl (TAD, Builder );
2842
2868
setClangDeclKeywords (TAD, Pairs, Builder);
2843
2869
addLeadingDot (Builder);
2844
2870
Builder.addTextChunk (TAD->getName ().str ());
@@ -2868,7 +2894,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2868
2894
Sink, CodeCompletionResult::ResultKind::Declaration,
2869
2895
getSemanticContext (GP, Reason, dynamicLookupInfo), expectedTypeContext);
2870
2896
setClangDeclKeywords (GP, Pairs, Builder);
2871
- Builder. setAssociatedDecl (GP);
2897
+ setAssociatedDecl (GP, Builder );
2872
2898
addLeadingDot (Builder);
2873
2899
Builder.addTextChunk (GP->getName ().str ());
2874
2900
addTypeAnnotation (Builder, GP->getDeclaredInterfaceType ());
@@ -2882,7 +2908,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2882
2908
Sink, CodeCompletionResult::ResultKind::Declaration,
2883
2909
getSemanticContext (AT, Reason, dynamicLookupInfo), expectedTypeContext);
2884
2910
setClangDeclKeywords (AT, Pairs, Builder);
2885
- Builder. setAssociatedDecl (AT);
2911
+ setAssociatedDecl (AT, Builder );
2886
2912
addLeadingDot (Builder);
2887
2913
Builder.addTextChunk (AT->getName ().str ());
2888
2914
if (Type T = getAssociatedTypeType (AT))
@@ -2897,7 +2923,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2897
2923
semanticContext, {});
2898
2924
2899
2925
builder.addTextChunk (PGD->getName ().str ());
2900
- builder. setAssociatedDecl (PGD);
2926
+ setAssociatedDecl (PGD, builder );
2901
2927
};
2902
2928
2903
2929
void addEnumElementRef (const EnumElementDecl *EED, DeclVisibilityKind Reason,
@@ -2914,7 +2940,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2914
2940
HasTypeContext ? SemanticContextKind::ExpressionSpecific
2915
2941
: getSemanticContext (EED, Reason, dynamicLookupInfo),
2916
2942
expectedTypeContext);
2917
- Builder. setAssociatedDecl (EED);
2943
+ setAssociatedDecl (EED, Builder );
2918
2944
setClangDeclKeywords (EED, Pairs, Builder);
2919
2945
addLeadingDot (Builder);
2920
2946
addValueBaseName (Builder, EED->getName ());
@@ -2996,7 +3022,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2996
3022
getSemanticContext (AFD, Reason, dynamicLookupInfo),
2997
3023
expectedTypeContext);
2998
3024
setClangDeclKeywords (AFD, Pairs, Builder);
2999
- Builder. setAssociatedDecl (AFD);
3025
+ setAssociatedDecl (AFD, Builder );
3000
3026
3001
3027
// Base name
3002
3028
addLeadingDot (Builder);
@@ -3469,7 +3495,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3469
3495
// FIXME: handle variable amounts of space.
3470
3496
if (HaveLeadingSpace)
3471
3497
builder.setNumBytesToErase (1 );
3472
- builder. setAssociatedDecl (op);
3498
+ setAssociatedDecl (op, builder );
3473
3499
builder.addTextChunk (op->getName ().str ());
3474
3500
assert (resultType);
3475
3501
addTypeAnnotation (builder, resultType);
@@ -3515,7 +3541,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
3515
3541
CodeCompletionResultBuilder builder (
3516
3542
Sink, CodeCompletionResult::ResultKind::Declaration, semanticContext,
3517
3543
{});
3518
- builder. setAssociatedDecl (op);
3544
+ setAssociatedDecl (op, builder );
3519
3545
3520
3546
if (HaveLeadingSpace)
3521
3547
builder.addAnnotatedWhitespace (" " );
@@ -4179,6 +4205,15 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4179
4205
bool hasOverridabilityModifier = false ;
4180
4206
bool hasStaticOrClass = false ;
4181
4207
4208
+ // / Sets the given declaration \p D as the associated declaration of the
4209
+ // / completion result being built in \p Builder.
4210
+ void setAssociatedDecl (const Decl *D, CodeCompletionResultBuilder &Builder) {
4211
+ SourceFile *SF = nullptr ;
4212
+ if (CurrDeclContext)
4213
+ SF = CurrDeclContext->getParentSourceFile ();
4214
+ Builder.setAssociatedDecl (D, SF);
4215
+ }
4216
+
4182
4217
public:
4183
4218
CompletionOverrideLookup (CodeCompletionResultSink &Sink, ASTContext &Ctx,
4184
4219
const DeclContext *CurrDeclContext,
@@ -4407,7 +4442,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4407
4442
SemanticContextKind::Super, {});
4408
4443
Builder.setExpectedTypeRelation (
4409
4444
CodeCompletionResult::ExpectedTypeRelation::NotApplicable);
4410
- Builder. setAssociatedDecl (FD);
4445
+ setAssociatedDecl (FD, Builder );
4411
4446
addValueOverride (FD, Reason, dynamicLookupInfo, Builder, hasFuncIntroducer);
4412
4447
Builder.addBraceStmtWithCursor ();
4413
4448
}
@@ -4425,7 +4460,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4425
4460
CodeCompletionResultBuilder Builder (
4426
4461
Sink, CodeCompletionResult::ResultKind::Declaration,
4427
4462
SemanticContextKind::Super, {});
4428
- Builder. setAssociatedDecl (VD);
4463
+ setAssociatedDecl (VD, Builder );
4429
4464
addValueOverride (VD, Reason, dynamicLookupInfo, Builder, hasVarIntroducer);
4430
4465
}
4431
4466
@@ -4436,7 +4471,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4436
4471
SemanticContextKind::Super, {});
4437
4472
Builder.setExpectedTypeRelation (
4438
4473
CodeCompletionResult::ExpectedTypeRelation::NotApplicable);
4439
- Builder. setAssociatedDecl (SD);
4474
+ setAssociatedDecl (SD, Builder );
4440
4475
addValueOverride (SD, Reason, dynamicLookupInfo, Builder, false );
4441
4476
Builder.addBraceStmtWithCursor ();
4442
4477
}
@@ -4448,7 +4483,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4448
4483
SemanticContextKind::Super, {});
4449
4484
Builder.setExpectedTypeRelation (
4450
4485
CodeCompletionResult::ExpectedTypeRelation::NotApplicable);
4451
- Builder. setAssociatedDecl (ATD);
4486
+ setAssociatedDecl (ATD, Builder );
4452
4487
if (!hasTypealiasIntroducer && !hasAccessModifier)
4453
4488
addAccessControl (ATD, Builder);
4454
4489
if (!hasTypealiasIntroducer)
@@ -4466,7 +4501,7 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
4466
4501
SemanticContextKind::Super, {});
4467
4502
Builder.setExpectedTypeRelation (
4468
4503
CodeCompletionResult::ExpectedTypeRelation::NotApplicable);
4469
- Builder. setAssociatedDecl (CD);
4504
+ setAssociatedDecl (CD, Builder );
4470
4505
4471
4506
if (!hasAccessModifier)
4472
4507
addAccessControl (CD, Builder);
@@ -5732,7 +5767,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
5732
5767
ImportFilter |= ModuleDecl::ImportFilterKind::Public;
5733
5768
ImportFilter |= ModuleDecl::ImportFilterKind::Private;
5734
5769
ImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
5735
- // FIXME: ImportFilterKind::ShadowedBySeparateOverlay?
5736
5770
SmallVector<ModuleDecl::ImportedModule, 4 > Imports;
5737
5771
auto *SF = CurDeclContext->getParentSourceFile ();
5738
5772
SF->getImportedModules (Imports, ImportFilter);
0 commit comments