Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -1017,25 +1017,11 @@ const SemaCompleteInput &Input, IncludeStructure *Includes = nullptr) { trace::Span Tracer("Sema completion"); - std::vector ArgStrs; - for (const auto &S : Input.Command.CommandLine) - ArgStrs.push_back(S.c_str()); - - if (Input.VFS->setCurrentWorkingDirectory(Input.Command.Directory)) { - log("Couldn't set working directory"); - // We run parsing anyway, our lit-tests rely on results for non-existing - // working dirs. - } - llvm::IntrusiveRefCntPtr VFS = Input.VFS; if (Input.Preamble && Input.Preamble->StatCache) VFS = Input.Preamble->StatCache->getConsumingFS(std::move(VFS)); - IgnoreDiagnostics DummyDiagsConsumer; - auto CI = createInvocationFromCommandLine( - ArgStrs, - CompilerInstance::createDiagnostics(new DiagnosticOptions, - &DummyDiagsConsumer, false), - VFS); + auto CI = + buildCompilerInvocation(ParseInputs{Input.Command, VFS, Input.Contents}); if (!CI) { elog("Couldn't create CompilerInvocation"); return false; @@ -1073,6 +1059,7 @@ *Offset; // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise // the remapped buffers do not get freed. + IgnoreDiagnostics DummyDiagsConsumer; auto Clang = prepareCompilerInstance( std::move(CI), (Input.Preamble && !CompletingInPreamble) ? &Input.Preamble->Preamble