Skip to content

Commit 55590e0

Browse files
committed
[CodeCompletion] Make lookupCodeCompletionResultsFromModule() only accept
SourceFile as the decl context. (cherry picked from commit 5d5b93d)
1 parent 2281e46 commit 55590e0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Decl;
3333
class DeclContext;
3434
class FrontendOptions;
3535
class ModuleDecl;
36+
class SourceFile;
3637

3738
namespace ide {
3839

@@ -1025,7 +1026,7 @@ void lookupCodeCompletionResultsFromModule(CodeCompletionResultSink &targetSink,
10251026
const ModuleDecl *module,
10261027
ArrayRef<std::string> accessPath,
10271028
bool needLeadingDot,
1028-
const DeclContext *currDeclContext);
1029+
const SourceFile *SF);
10291030

10301031
/// Copy code completion results from \p sourceSink to \p targetSink, possibly
10311032
/// restricting by \p onlyTypes. Returns copied results in \p targetSink.

lib/IDE/CodeCompletion.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7418,10 +7418,9 @@ swift::ide::makeCodeCompletionCallbacksFactory(
74187418
void swift::ide::lookupCodeCompletionResultsFromModule(
74197419
CodeCompletionResultSink &targetSink, const ModuleDecl *module,
74207420
ArrayRef<std::string> accessPath, bool needLeadingDot,
7421-
const DeclContext *currDeclContext) {
7422-
// Consisitently use the SourceFile as the decl context, to avoid decl
7423-
// context specific behaviors.
7424-
auto *SF = currDeclContext->getParentSourceFile();
7421+
const SourceFile *SF) {
7422+
// Use the SourceFile as the decl context, to avoid decl context specific
7423+
// behaviors.
74257424
CompletionLookup Lookup(targetSink, module->getASTContext(), SF);
74267425
Lookup.lookupExternalModuleDecls(module, accessPath, needLeadingDot);
74277426
}
@@ -7497,8 +7496,9 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
74977496

74987497
// Use the current SourceFile as the DeclContext so that we can use it to
74997498
// perform qualified lookup, and to get the correct visibility for
7500-
// @testable imports.
7501-
DeclContext *DCForModules = DC->getParentSourceFile();
7499+
// @testable imports. Also it cannot use 'DC' since it would apply decl
7500+
// context changes to cached results.
7501+
const SourceFile *SF = DC->getParentSourceFile();
75027502

75037503
for (auto &R : requestedModules) {
75047504
// FIXME(thread-safety): lock the whole AST context. We might load a
@@ -7511,7 +7511,7 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
75117511
(*V)->Sink.annotateResult = context.getAnnotateResult();
75127512
lookupCodeCompletionResultsFromModule(
75137513
(*V)->Sink, R.TheModule, R.Key.AccessPath,
7514-
R.Key.ResultsHaveLeadingDot, DCForModules);
7514+
R.Key.ResultsHaveLeadingDot, SF);
75157515
context.Cache.set(R.Key, *V);
75167516
}
75177517
assert(V.hasValue());

0 commit comments

Comments
 (0)