@@ -1716,7 +1716,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
1716
1716
private:
1717
1717
void addKeywords (CodeCompletionResultSink &Sink, bool MaybeFuncBody);
1718
1718
bool trySolverCompletion ();
1719
- void deliverCompletionResults ();
1720
1719
};
1721
1720
} // end anonymous namespace
1722
1721
@@ -5812,10 +5811,10 @@ static void addConditionalCompilationFlags(ASTContext &Ctx,
5812
5811
}
5813
5812
}
5814
5813
5815
- static void processModuleRequests (CodeCompletionContext &CompletionContext,
5816
- CompletionLookup &Lookup,
5817
- SourceFile &SF,
5818
- CodeCompletionConsumer &Consumer) {
5814
+ static void deliverCompletionResults (CodeCompletionContext &CompletionContext,
5815
+ CompletionLookup &Lookup,
5816
+ SourceFile &SF,
5817
+ CodeCompletionConsumer &Consumer) {
5819
5818
llvm::SmallPtrSet<Identifier, 8 > seenModuleNames;
5820
5819
std::vector<RequestedCachedModule> RequestedModules;
5821
5820
@@ -5890,7 +5889,6 @@ static void processModuleRequests(CodeCompletionContext &CompletionContext,
5890
5889
5891
5890
// Add results for all imported modules.
5892
5891
SmallVector<ModuleDecl::ImportedModule, 4 > Imports;
5893
- // auto *SF = CurDeclContext->getParentSourceFile();
5894
5892
SF.getImportedModules (
5895
5893
Imports, {ModuleDecl::ImportFilterKind::Public,
5896
5894
ModuleDecl::ImportFilterKind::Private,
@@ -5903,7 +5901,11 @@ static void processModuleRequests(CodeCompletionContext &CompletionContext,
5903
5901
}
5904
5902
}
5905
5903
Lookup.RequestedCachedResults .clear ();
5904
+ CompletionContext.typeContextKind = Lookup.typeContextKind ();
5906
5905
5906
+ // Use the current SourceFile as the DeclContext so that we can use it to
5907
+ // perform qualified lookup, and to get the correct visibility for
5908
+ // @testable imports.
5907
5909
DeclContext *DCForModules = &SF;
5908
5910
Consumer.handleResultsAndModules (CompletionContext, RequestedModules,
5909
5911
DCForModules);
@@ -5935,19 +5937,17 @@ void DotExprLookup::performLookup(ide::CodeCompletionContext &CompletionCtx,
5935
5937
5936
5938
for (auto &Solution: Solutions) {
5937
5939
Lookup.setIsStaticMetatype (Solution.BaseIsStaticMetaType );
5938
- Lookup.getPostfixKeywordCompletions (Solution.Ty , BaseExpr);
5940
+ Lookup.getPostfixKeywordCompletions (Solution.BaseTy , BaseExpr);
5939
5941
Lookup.setExpectedTypes (Solution.ExpectedTypes ,
5940
- Solution.IsSingleExpressionClosure ,
5942
+ Solution.IsSingleExpressionBody ,
5941
5943
Solution.ExpectsNonVoid );
5942
- if (isDynamicLookup (Solution.Ty ))
5944
+ if (isDynamicLookup (Solution.BaseTy ))
5943
5945
Lookup.setIsDynamicLookup ();
5944
- Lookup.getValueExprCompletions (Solution.Ty , Solution.ReferencedDecl );
5946
+ Lookup.getValueExprCompletions (Solution.BaseTy , Solution.BaseDecl );
5945
5947
}
5946
5948
5947
5949
SourceFile *SF = DC->getParentSourceFile ();
5948
- // FIXME: There may be multiple of these now.
5949
- CompletionCtx.typeContextKind = Lookup.typeContextKind ();
5950
- processModuleRequests (CompletionCtx, Lookup, *SF, Consumer);
5950
+ deliverCompletionResults (CompletionCtx, Lookup, *SF, Consumer);
5951
5951
}
5952
5952
5953
5953
bool CodeCompletionCallbacksImpl::trySolverCompletion () {
@@ -5985,7 +5985,7 @@ bool CodeCompletionCallbacksImpl::trySolverCompletion() {
5985
5985
CompletionCollector (Context.CompletionCallback , &Lookup);
5986
5986
typeCheckContextAt (CurDeclContext, CompletionLoc);
5987
5987
5988
- // This (should ) only happens in cases where the expression isn't
5988
+ // This (hopefully ) only happens in cases where the expression isn't
5989
5989
// typechecked during normal compilation either (e.g. member completion in a
5990
5990
// switch case where there switched value is invalid). Having normal
5991
5991
// typechecking still resolve even these cases would be beneficial for
@@ -6529,112 +6529,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
6529
6529
break ;
6530
6530
}
6531
6531
6532
- llvm::SmallPtrSet<Identifier, 8 > seenModuleNames;
6533
-
6534
- for (auto &Request: Lookup.RequestedCachedResults ) {
6535
- // Use the current SourceFile as the DeclContext so that we can use it to
6536
- // perform qualified lookup, and to get the correct visibility for
6537
- // @testable imports.
6538
- const SourceFile &SF = P.SF ;
6539
-
6540
- llvm::DenseSet<CodeCompletionCache::Key> ImportsSeen;
6541
- auto handleImport = [&](ModuleDecl::ImportedModule Import) {
6542
- ModuleDecl *TheModule = Import.importedModule ;
6543
- ModuleDecl::AccessPathTy Path = Import.accessPath ;
6544
- if (TheModule->getFiles ().empty ())
6545
- return ;
6546
-
6547
- // Clang submodules are ignored and there's no lookup cost involved,
6548
- // so just ignore them and don't put the empty results in the cache
6549
- // because putting a lot of objects in the cache will push out
6550
- // other lookups.
6551
- if (isClangSubModule (TheModule))
6552
- return ;
6553
-
6554
- std::vector<std::string> AccessPath;
6555
- for (auto Piece : Path) {
6556
- AccessPath.push_back (std::string (Piece.Item ));
6557
- }
6558
-
6559
- StringRef ModuleFilename = TheModule->getModuleFilename ();
6560
- // ModuleFilename can be empty if something strange happened during
6561
- // module loading, for example, the module file is corrupted.
6562
- if (!ModuleFilename.empty ()) {
6563
- auto &Ctx = TheModule->getASTContext ();
6564
- CodeCompletionCache::Key K{
6565
- ModuleFilename.str (),
6566
- std::string (TheModule->getName ()),
6567
- AccessPath,
6568
- Request.NeedLeadingDot ,
6569
- SF.hasTestableOrPrivateImport (
6570
- AccessLevel::Internal, TheModule,
6571
- SourceFile::ImportQueryKind::TestableOnly),
6572
- SF.hasTestableOrPrivateImport (
6573
- AccessLevel::Internal, TheModule,
6574
- SourceFile::ImportQueryKind::PrivateOnly),
6575
- Ctx.LangOpts .CodeCompleteInitsInPostfixExpr ,
6576
- CompletionContext.getAnnotateResult (),
6577
- };
6578
-
6579
- using PairType = llvm::DenseSet<swift::ide::CodeCompletionCache::Key,
6580
- llvm::DenseMapInfo<CodeCompletionCache::Key>>::iterator;
6581
- std::pair<PairType, bool > Result = ImportsSeen.insert (K);
6582
- if (!Result.second )
6583
- return ; // already handled.
6584
- RequestedModules.push_back ({std::move (K), TheModule,
6585
- Request.OnlyTypes , Request.OnlyPrecedenceGroups });
6586
-
6587
- if (Request.IncludeModuleQualifier &&
6588
- seenModuleNames.insert (TheModule->getName ()).second )
6589
- Lookup.addModuleName (TheModule);
6590
- }
6591
- };
6592
-
6593
- if (Request.TheModule ) {
6594
- // FIXME: actually check imports.
6595
- for (auto Import : namelookup::getAllImports (Request.TheModule )) {
6596
- handleImport (Import);
6597
- }
6598
- } else {
6599
- // Add results from current module.
6600
- Lookup.getToplevelCompletions (Request.OnlyTypes );
6601
-
6602
- // Add the qualifying module name
6603
- auto curModule = CurDeclContext->getParentModule ();
6604
- if (Request.IncludeModuleQualifier &&
6605
- seenModuleNames.insert (curModule->getName ()).second )
6606
- Lookup.addModuleName (curModule);
6607
-
6608
- // Add results for all imported modules.
6609
- SmallVector<ModuleDecl::ImportedModule, 4 > Imports;
6610
- auto *SF = CurDeclContext->getParentSourceFile ();
6611
- SF->getImportedModules (
6612
- Imports, {ModuleDecl::ImportFilterKind::Public,
6613
- ModuleDecl::ImportFilterKind::Private,
6614
- ModuleDecl::ImportFilterKind::ImplementationOnly});
6615
-
6616
- for (auto Imported : Imports) {
6617
- for (auto Import : namelookup::getAllImports (Imported.importedModule ))
6618
- handleImport (Import);
6619
- }
6620
- }
6621
- }
6622
- Lookup.RequestedCachedResults .clear ();
6623
-
6624
- CompletionContext.typeContextKind = Lookup.typeContextKind ();
6625
-
6626
- deliverCompletionResults ();
6627
- }
6628
-
6629
- void CodeCompletionCallbacksImpl::deliverCompletionResults () {
6630
- // Use the current SourceFile as the DeclContext so that we can use it to
6631
- // perform qualified lookup, and to get the correct visibility for
6632
- // @testable imports.
6633
- DeclContext *DCForModules = &P.SF ;
6634
-
6635
- Consumer.handleResultsAndModules (CompletionContext, RequestedModules,
6636
- DCForModules);
6637
- RequestedModules.clear ();
6532
+ deliverCompletionResults (CompletionContext, Lookup, P.SF , Consumer);
6638
6533
}
6639
6534
6640
6535
void PrintingCodeCompletionConsumer::handleResults (
0 commit comments