@@ -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,13 +327,20 @@ bool CompletionInstance::performCachedOperationIfPossible(
327
327
registerTypeCheckerRequestFunctions (tmpCtx->evaluator );
328
328
registerSILGenRequestFunctions (tmpCtx->evaluator );
329
329
ModuleDecl *tmpM = ModuleDecl::create (Identifier (), *tmpCtx);
330
- SourceFile *tmpSF = new (*tmpCtx) SourceFile (*tmpM, oldSF->Kind , tmpBufferID);
330
+ SourceFile *tmpSF = new (*tmpCtx)
331
+ SourceFile (*tmpM, oldSF->Kind , tmpBufferID, /* KeepParsedTokens=*/ false ,
332
+ /* BuildSyntaxTree=*/ false , oldSF->getParsingOptions ());
331
333
tmpSF->enableInterfaceHash ();
332
334
// Ensure all non-function-body tokens are hashed into the interface hash
333
335
tmpCtx->LangOpts .EnableTypeFingerprints = false ;
334
336
335
- // Couldn't find any completion token?
337
+ // FIXME: Since we don't setup module loaders on the temporary AST context,
338
+ // 'canImport()' conditional compilation directive always fails. That causes
339
+ // interface hash change and prevents fast-completion.
340
+
341
+ // Parse and get the completion context.
336
342
auto *newState = tmpSF->getDelayedParserState ();
343
+ // Couldn't find any completion token?
337
344
if (!newState->hasCodeCompletionDelayedDeclState ())
338
345
return false ;
339
346
0 commit comments