@@ -315,10 +315,10 @@ bool CompletionInstance::performCachedOperationIfPossible(
315
315
auto tmpBufferID = tmpSM.addMemBufferCopy (completionBuffer);
316
316
tmpSM.setCodeCompletionPoint (tmpBufferID, Offset);
317
317
318
- LangOptions langOpts;
318
+ LangOptions langOpts = CI. getASTContext (). LangOpts ;
319
319
langOpts.DisableParserLookup = true ;
320
- TypeCheckerOptions typeckOpts;
321
- SearchPathOptions searchPathOpts;
320
+ TypeCheckerOptions typeckOpts = CI. getASTContext (). TypeCheckerOpts ;
321
+ SearchPathOptions searchPathOpts = CI. getASTContext (). SearchPathOpts ;
322
322
DiagnosticEngine tmpDiags (tmpSM);
323
323
std::unique_ptr<ASTContext> tmpCtx (
324
324
ASTContext::get (langOpts, typeckOpts, searchPathOpts, tmpSM, tmpDiags));
@@ -327,15 +327,22 @@ bool CompletionInstance::performCachedOperationIfPossible(
327
327
registerTypeCheckerRequestFunctions (tmpCtx->evaluator );
328
328
registerSILGenRequestFunctions (tmpCtx->evaluator );
329
329
ModuleDecl *tmpM = ModuleDecl::create (Identifier (), *tmpCtx);
330
- SourceFile *tmpSF =
331
- new (*tmpCtx) SourceFile (*tmpM, oldSF->Kind , tmpBufferID,
332
- SourceFile::ImplicitModuleImportKind::None);
330
+ SourceFile *tmpSF = new (*tmpCtx)
331
+ SourceFile (*tmpM, oldSF->Kind , tmpBufferID,
332
+ SourceFile::ImplicitModuleImportKind::None,
333
+ /* KeepParsedTokens=*/ false , /* BuildSyntaxTree=*/ false ,
334
+ oldSF->getParsingOptions ());
333
335
tmpSF->enableInterfaceHash ();
334
336
// Ensure all non-function-body tokens are hashed into the interface hash
335
337
tmpCtx->LangOpts .EnableTypeFingerprints = false ;
336
338
337
- // Couldn't find any completion token?
339
+ // FIXME: Since we don't setup module loaders on the temporary AST context,
340
+ // 'canImport()' conditional compilation directive always fails. That causes
341
+ // interface hash change and prevents fast-completion.
342
+
343
+ // Parse and get the completion context.
338
344
auto *newState = tmpSF->getDelayedParserState ();
345
+ // Couldn't find any completion token?
339
346
if (!newState->hasCodeCompletionDelayedDeclState ())
340
347
return false ;
341
348
0 commit comments