Index: clangd/ClangdServer.cpp =================================================================== --- clangd/ClangdServer.cpp +++ clangd/ClangdServer.cpp @@ -171,12 +171,11 @@ llvm::Expected IP) { assert(IP && "error when trying to read preamble for codeComplete"); auto PreambleData = IP->Preamble; - auto &Command = IP->Inputs.CompileCommand; // FIXME(ibiryukov): even if Preamble is non-null, we may want to check // both the old and the new version in case only one of them matches. CompletionList Result = clangd::codeComplete( - File, Command, PreambleData ? &PreambleData->Preamble : nullptr, + File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, Contents, Pos, FS, PCHs, CodeCompleteOpts); CB(std::move(Result)); }; @@ -203,8 +202,7 @@ return CB(IP.takeError()); auto PreambleData = IP->Preamble; - auto &Command = IP->Inputs.CompileCommand; - CB(clangd::signatureHelp(File, Command, + CB(clangd::signatureHelp(File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr, Contents, Pos, FS, PCHs)); }; @@ -343,8 +341,8 @@ // Replacement with offset UINT_MAX and length 0 will be treated as include // insertion. tooling::Replacement R(File, /*Offset=*/UINT_MAX, 0, "#include " + ToInclude); - auto Replaces = format::cleanupAroundReplacements( - Code, tooling::Replacements(R), *Style); + auto Replaces = + format::cleanupAroundReplacements(Code, tooling::Replacements(R), *Style); if (!Replaces) return Replaces; return formatReplacements(Code, *Replaces, *Style); Index: clangd/TUScheduler.h =================================================================== --- clangd/TUScheduler.h +++ clangd/TUScheduler.h @@ -29,7 +29,8 @@ }; struct InputsAndPreamble { - const ParseInputs &Inputs; + llvm::StringRef Contents; + const tooling::CompileCommand &Command; const PreambleData *Preamble; }; Index: clangd/TUScheduler.cpp =================================================================== --- clangd/TUScheduler.cpp +++ clangd/TUScheduler.cpp @@ -415,7 +415,8 @@ struct TUScheduler::FileData { /// Latest inputs, passed to TUScheduler::update(). - ParseInputs Inputs; + std::string Contents; + tooling::CompileCommand Command; ASTWorkerHandle Worker; }; @@ -462,10 +463,14 @@ assert(FDIt != Files.end() && "calling updateCompileCommand on non-tracked file"); - FDIt->second->Inputs.CompileCommand = std::move(NewCommand); - FDIt->second->Inputs.FS = std::move(FS); - FDIt->second->Worker->update(FDIt->second->Inputs, WantDiags, - std::move(OnUpdated)); + FDIt->second->Command = NewCommand; + FDIt->second->Worker->update( + ParseInputs{ + std::move(NewCommand), + std::move(FS), + FDIt->second->Contents, + }, + WantDiags, std::move(OnUpdated)); } void TUScheduler::update(PathRef File, ParseInputs Inputs, @@ -478,9 +483,11 @@ File, WorkerThreads ? WorkerThreads.getPointer() : nullptr, Barrier, CppFile(File, StorePreamblesInMemory, PCHOps, ASTCallback), UpdateDebounce); - FD = std::unique_ptr(new FileData{Inputs, std::move(Worker)}); + FD = std::unique_ptr(new FileData{ + Inputs.Contents, Inputs.CompileCommand, std::move(Worker)}); } else { - FD->Inputs = Inputs; + FD->Contents = Inputs.Contents; + FD->Command = Inputs.CompileCommand; } FD->Worker->update(std::move(Inputs), WantDiags, std::move(OnUpdated)); } @@ -522,26 +529,28 @@ SPAN_ATTACH(Tracer, "file", File); std::shared_ptr Preamble = It->second->Worker->getPossiblyStalePreamble(); - Action(InputsAndPreamble{It->second->Inputs, Preamble.get()}); + Action(InputsAndPreamble{It->second->Contents, It->second->Command, + Preamble.get()}); return; } - ParseInputs InputsCopy = It->second->Inputs; std::shared_ptr Worker = It->second->Worker.lock(); - auto Task = [InputsCopy, Worker, this](std::string Name, std::string File, - Context Ctx, - decltype(Action) Action) mutable { + auto Task = [Worker, this](std::string Name, std::string File, + std::string Contents, + tooling::CompileCommand Command, Context Ctx, + decltype(Action) Action) mutable { std::lock_guard BarrierLock(Barrier); WithContext Guard(std::move(Ctx)); trace::Span Tracer(Name); SPAN_ATTACH(Tracer, "file", File); std::shared_ptr Preamble = Worker->getPossiblyStalePreamble(); - Action(InputsAndPreamble{InputsCopy, Preamble.get()}); + Action(InputsAndPreamble{Contents, Command, Preamble.get()}); }; PreambleTasks->runAsync("task:" + llvm::sys::path::filename(File), Bind(Task, std::string(Name), std::string(File), + It->second->Contents, It->second->Command, Context::current().clone(), std::move(Action))); } Index: unittests/clangd/TUSchedulerTests.cpp =================================================================== --- unittests/clangd/TUSchedulerTests.cpp +++ unittests/clangd/TUSchedulerTests.cpp @@ -226,8 +226,7 @@ EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce)); ASSERT_TRUE((bool)Preamble); - EXPECT_EQ(Preamble->Inputs.FS, Inputs.FS); - EXPECT_EQ(Preamble->Inputs.Contents, Inputs.Contents); + EXPECT_EQ(Preamble->Contents, Inputs.Contents); std::lock_guard Lock(Mut); ++TotalPreambleReads;