Skip to content

Commit 1a65b84

Browse files
author
Nathan Hawes
committed
[IDE] Completion after a qualifying module should return symbols from its shadowing cross-import overlays.
1 parent 9f6f763 commit 1a65b84

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
17631763
}
17641764

17651765
void addModuleName(
1766-
const ModuleDecl *MD,
1766+
ModuleDecl *MD,
17671767
Optional<CodeCompletionResult::NotRecommendedReason> R = None) {
17681768

17691769
// Don't add underscored cross-import overlay modules.
@@ -3293,16 +3293,29 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
32933293
bool tryModuleCompletions(Type ExprType, bool TypesOnly = false) {
32943294
if (auto MT = ExprType->getAs<ModuleType>()) {
32953295
ModuleDecl *M = MT->getModule();
3296-
if (CurrModule != M) {
3297-
// Only use the cache if it is not the current module.
3296+
3297+
// Only lookup this module's symbols from the cache if it is not the
3298+
// current module.
3299+
if (M == CurrModule)
3300+
return false;
3301+
3302+
// If the module is shadowed by a separately imported overlay(s), look up
3303+
// the symbols from the overlay(s) instead.
3304+
SmallVector<ModuleDecl *, 1> ShadowingOrOriginal;
3305+
if (auto *SF = CurrDeclContext->getParentSourceFile()) {
3306+
SF->getSeparatelyImportedOverlays(M, ShadowingOrOriginal);
3307+
if (ShadowingOrOriginal.empty())
3308+
ShadowingOrOriginal.push_back(M);
3309+
}
3310+
for (ModuleDecl *M: ShadowingOrOriginal) {
32983311
RequestedResultsTy Request = RequestedResultsTy::fromModule(M)
32993312
.needLeadingDot(needDot())
33003313
.withModuleQualifier(false);
33013314
if (TypesOnly)
33023315
Request = Request.onlyTypes();
33033316
RequestedCachedResults.push_back(Request);
3304-
return true;
33053317
}
3318+
return true;
33063319
}
33073320
return false;
33083321
}

test/IDE/complete_cross_import.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// RUN: %FileCheck --input-file %t/results.tmp --check-prefix=IMPORT %s
88
// RUN: %FileCheck --input-file %t/results.tmp --check-prefix=IMPORT-NEGATIVE %s
99

10+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -enable-cross-import-overlays -I %S/Inputs/CrossImport -code-completion-token=SCOPED > %t/results.tmp
11+
// RUN: %FileCheck --input-file %t/results.tmp --check-prefix=SCOPED %s
12+
// RUN: %FileCheck --input-file %t/results.tmp --check-prefix=SCOPED-NEGATIVE %s
13+
1014
import A
1115
import B
1216

@@ -39,3 +43,17 @@ import #^IMPORT^#
3943
// IMPORT-NEGATIVE-NOT: _ABAdditions
4044
// IMPORT-NEGATIVE-NOT: __ABAdditionsDAdditions
4145

46+
47+
func bar() {
48+
A.#^SCOPED^#
49+
}
50+
51+
// SCOPED-DAG: Decl[FreeFunction]/OtherModule[A]: from_ABAdditions()[#Void#]; name=from_ABAdditions()
52+
// SCOPED-DAG: Decl[FreeFunction]/OtherModule[A]: fromA()[#Void#]; name=fromA()
53+
54+
// SCOPED-NEGATIVE-NOT: name=_ABAdditions
55+
// SCOPED-NEGATIVE-NOT: name=__ABAdditionsDAdditions
56+
// SCOPED-NEGATIVE-NOT: name=fromB
57+
// SCOPED-NEGATIVE-NOT: [_ABAdditions]
58+
// SCOPED-NEGATIVE-NOT: [__ABAdditionsDAdditions]
59+

0 commit comments

Comments
 (0)