Skip to content

Commit 5d5b93d

Browse files
committed
[CodeCompletion] Make lookupCodeCompletionResultsFromModule() only accept
SourceFile as the decl context.
1 parent 4617bbb commit 5d5b93d

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
@@ -7440,10 +7440,9 @@ swift::ide::makeCodeCompletionCallbacksFactory(
74407440
void swift::ide::lookupCodeCompletionResultsFromModule(
74417441
CodeCompletionResultSink &targetSink, const ModuleDecl *module,
74427442
ArrayRef<std::string> accessPath, bool needLeadingDot,
7443-
const DeclContext *currDeclContext) {
7444-
// Consisitently use the SourceFile as the decl context, to avoid decl
7445-
// context specific behaviors.
7446-
auto *SF = currDeclContext->getParentSourceFile();
7443+
const SourceFile *SF) {
7444+
// Use the SourceFile as the decl context, to avoid decl context specific
7445+
// behaviors.
74477446
CompletionLookup Lookup(targetSink, module->getASTContext(), SF);
74487447
Lookup.lookupExternalModuleDecls(module, accessPath, needLeadingDot);
74497448
}
@@ -7519,8 +7518,9 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
75197518

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

75257525
for (auto &R : requestedModules) {
75267526
// FIXME(thread-safety): lock the whole AST context. We might load a
@@ -7533,7 +7533,7 @@ void SimpleCachingCodeCompletionConsumer::handleResultsAndModules(
75337533
(*V)->Sink.annotateResult = context.getAnnotateResult();
75347534
lookupCodeCompletionResultsFromModule(
75357535
(*V)->Sink, R.TheModule, R.Key.AccessPath,
7536-
R.Key.ResultsHaveLeadingDot, DCForModules);
7536+
R.Key.ResultsHaveLeadingDot, SF);
75377537
context.Cache.set(R.Key, *V);
75387538
}
75397539
assert(V.hasValue());

0 commit comments

Comments
 (0)