From 8d654df5b982c97f54aab75852b9150a2bff3634 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Wed, 17 Jun 2020 18:09:54 +0200 Subject: [PATCH] [clangd] Rename FSProvider to TFS in case of ThreadsafeFS Summary: Depends on D81998 Reviewers: sammccall Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82024 --- clang-tools-extra/clangd/ClangdLSPServer.cpp | 9 +++--- clang-tools-extra/clangd/ClangdLSPServer.h | 4 +-- clang-tools-extra/clangd/ClangdServer.cpp | 26 +++++++++--------- clang-tools-extra/clangd/ClangdServer.h | 7 ++--- clang-tools-extra/clangd/CodeComplete.cpp | 11 ++++---- clang-tools-extra/clangd/Compiler.cpp | 2 +- clang-tools-extra/clangd/Compiler.h | 2 +- clang-tools-extra/clangd/ParsedAST.cpp | 5 ++-- clang-tools-extra/clangd/Preamble.cpp | 8 +++--- clang-tools-extra/clangd/SourceCode.cpp | 4 +-- clang-tools-extra/clangd/SourceCode.h | 2 +- clang-tools-extra/clangd/index/Background.cpp | 10 +++---- clang-tools-extra/clangd/index/Background.h | 2 +- clang-tools-extra/clangd/tool/ClangdMain.cpp | 7 ++--- clang-tools-extra/clangd/unittests/ClangdTests.cpp | 18 ++++++------ .../clangd/unittests/FileIndexTests.cpp | 8 +++--- .../clangd/unittests/FindSymbolsTests.cpp | 10 +++---- .../clangd/unittests/HeadersTests.cpp | 4 +-- .../clangd/unittests/ParsedASTTests.cpp | 6 ++-- .../clangd/unittests/PreambleTests.cpp | 18 ++++++------ .../clangd/unittests/TUSchedulerTests.cpp | 32 +++++++++++----------- clang-tools-extra/clangd/unittests/TestTU.cpp | 20 +++++++------- clang-tools-extra/clangd/unittests/TestTU.h | 2 +- 23 files changed, 106 insertions(+), 111 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index a426161..93f2746 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -524,7 +524,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, if (NegotiatedOffsetEncoding) WithOffsetEncoding.emplace(kCurrentOffsetEncoding, *NegotiatedOffsetEncoding); - Server.emplace(*CDB, FSProvider, ClangdServerOpts, + Server.emplace(*CDB, TFS, ClangdServerOpts, static_cast(this)); } applyConfiguration(Params.initializationOptions.ConfigSettings); @@ -1340,16 +1340,15 @@ void ClangdLSPServer::onSemanticTokensEdits( } ClangdLSPServer::ClangdLSPServer( - class Transport &Transp, const ThreadsafeFS &FSProvider, + class Transport &Transp, const ThreadsafeFS &TFS, const clangd::CodeCompleteOptions &CCOpts, const clangd::RenameOptions &RenameOpts, llvm::Optional CompileCommandsDir, bool UseDirBasedCDB, llvm::Optional ForcedOffsetEncoding, const ClangdServer::Options &Opts) : BackgroundContext(Context::current().clone()), Transp(Transp), - MsgHandler(new MessageHandler(*this)), FSProvider(FSProvider), - CCOpts(CCOpts), RenameOpts(RenameOpts), - SupportedSymbolKinds(defaultSymbolKinds()), + MsgHandler(new MessageHandler(*this)), TFS(TFS), CCOpts(CCOpts), + RenameOpts(RenameOpts), SupportedSymbolKinds(defaultSymbolKinds()), SupportedCompletionItemKinds(defaultCompletionItemKinds()), UseDirBasedCDB(UseDirBasedCDB), CompileCommandsDir(std::move(CompileCommandsDir)), ClangdServerOpts(Opts), diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index a62f2ce..6ccef95 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -41,7 +41,7 @@ public: /// for compile_commands.json in all parent directories of each file. /// If UseDirBasedCDB is false, compile commands are not read from disk. // FIXME: Clean up signature around CDBs. - ClangdLSPServer(Transport &Transp, const ThreadsafeFS &FSProvider, + ClangdLSPServer(Transport &Transp, const ThreadsafeFS &TFS, const clangd::CodeCompleteOptions &CCOpts, const clangd::RenameOptions &RenameOpts, llvm::Optional CompileCommandsDir, bool UseDirBasedCDB, @@ -207,7 +207,7 @@ private: notify("$/progress", Params); } - const ThreadsafeFS &FSProvider; + const ThreadsafeFS &TFS; /// Options used for code completion clangd::CodeCompleteOptions CCOpts; /// Options used for rename. diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index f8c0ee9..6c7255c 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -130,9 +130,9 @@ ClangdServer::Options::operator TUScheduler::Options() const { } ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB, - const ThreadsafeFS &FSProvider, const Options &Opts, + const ThreadsafeFS &TFS, const Options &Opts, Callbacks *Callbacks) - : FSProvider(FSProvider), + : TFS(TFS), DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex) : nullptr), @@ -163,7 +163,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB, AddIndex(Opts.StaticIndex); if (Opts.BackgroundIndex) { BackgroundIdx = std::make_unique( - Context::current().clone(), FSProvider, CDB, + Context::current().clone(), TFS, CDB, BackgroundIndexStorage::createDiskBackedStorageFactory( [&CDB](llvm::StringRef File) { return CDB.getProjectInfo(File); }), std::max(Opts.AsyncThreadsCount, 1u), @@ -185,12 +185,12 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents, // FIXME: call tidy options builder on the worker thread, it can do IO. if (GetClangTidyOptions) Opts.ClangTidyOpts = - GetClangTidyOptions(*FSProvider.view(/*CWD=*/llvm::None), File); + GetClangTidyOptions(*TFS.view(/*CWD=*/llvm::None), File); Opts.SuggestMissingIncludes = SuggestMissingIncludes; // Compile command is set asynchronously during update, as it can be slow. ParseInputs Inputs; - Inputs.FSProvider = &FSProvider; + Inputs.TFS = &TFS; Inputs.Contents = std::string(Contents); Inputs.Version = Version.str(); Inputs.ForceRebuild = ForceRebuild; @@ -237,7 +237,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos, } } } - ParseInputs ParseInput{IP->Command, &FSProvider, IP->Contents.str()}; + ParseInputs ParseInput{IP->Command, &TFS, IP->Contents.str()}; ParseInput.Index = Index; ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST; ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType; @@ -284,7 +284,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos, return CB(llvm::createStringError(llvm::inconvertibleErrorCode(), "Failed to parse includes")); - ParseInputs ParseInput{IP->Command, &FSProvider, IP->Contents.str()}; + ParseInputs ParseInput{IP->Command, &TFS, IP->Contents.str()}; ParseInput.Index = Index; ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST; ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType; @@ -321,7 +321,7 @@ ClangdServer::formatOnType(llvm::StringRef Code, PathRef File, Position Pos, return CursorPos.takeError(); auto Style = format::getStyle(format::DefaultFormatStyle, File, format::DefaultFallbackStyle, Code, - FSProvider.view(/*CWD=*/llvm::None).get()); + TFS.view(/*CWD=*/llvm::None).get()); if (!Style) return Style.takeError(); @@ -398,7 +398,7 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName, if (Opts.WantFormat) { auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents, - *InpAST->Inputs.FSProvider); + *InpAST->Inputs.TFS); llvm::Error Err = llvm::Error::success(); for (auto &E : *Edits) Err = @@ -499,7 +499,7 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID, for (auto &It : (*Effect)->ApplyEdits) { Edit &E = It.second; format::FormatStyle Style = - getFormatStyleForFile(File, E.InitialCode, FSProvider); + getFormatStyleForFile(File, E.InitialCode, TFS); if (llvm::Error Err = reformatEdit(E, Style)) elog("Failed to format {0}: {1}", It.first(), std::move(Err)); } @@ -550,7 +550,7 @@ void ClangdServer::switchSourceHeader( // 2) if 1) fails, we use the AST&Index approach, it is slower but supports // different code layout. if (auto CorrespondingFile = getCorrespondingHeaderOrSource( - std::string(Path), FSProvider.view(llvm::None))) + std::string(Path), TFS.view(llvm::None))) return CB(std::move(CorrespondingFile)); auto Action = [Path = Path.str(), CB = std::move(CB), this](llvm::Expected InpAST) mutable { @@ -565,7 +565,7 @@ llvm::Expected ClangdServer::formatCode(llvm::StringRef Code, PathRef File, llvm::ArrayRef Ranges) { // Call clang-format. - format::FormatStyle Style = getFormatStyleForFile(File, Code, FSProvider); + format::FormatStyle Style = getFormatStyleForFile(File, Code, TFS); tooling::Replacements IncludeReplaces = format::sortIncludes(Style, Code, Ranges, File); auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces); @@ -598,7 +598,7 @@ void ClangdServer::findHover(PathRef File, Position Pos, if (!InpAST) return CB(InpAST.takeError()); format::FormatStyle Style = getFormatStyleForFile( - File, InpAST->Inputs.Contents, *InpAST->Inputs.FSProvider); + File, InpAST->Inputs.Contents, *InpAST->Inputs.TFS); CB(clangd::getHover(InpAST->AST, Pos, std::move(Style), Index)); }; diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h index 64ac5f9..021540d 100644 --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -171,9 +171,8 @@ public: /// added file (i.e., when processing a first call to addDocument) and reuses /// those arguments for subsequent reparses. However, ClangdServer will check /// if compilation arguments changed on calls to forceReparse(). - ClangdServer(const GlobalCompilationDatabase &CDB, - const ThreadsafeFS &FSProvider, const Options &Opts, - Callbacks *Callbacks = nullptr); + ClangdServer(const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, + const Options &Opts, Callbacks *Callbacks = nullptr); /// Add a \p File to the list of tracked C++ files or update the contents if /// \p File is already tracked. Also schedules parsing of the AST for it on a @@ -330,7 +329,7 @@ private: formatCode(llvm::StringRef Code, PathRef File, ArrayRef Ranges); - const ThreadsafeFS &FSProvider; + const ThreadsafeFS &TFS; Path ResourceDir; // The index used to look up symbols. This could be: diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 4c483bf..f69424c 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -1113,8 +1113,7 @@ bool semaCodeComplete(std::unique_ptr Consumer, // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise // the remapped buffers do not get freed. llvm::IntrusiveRefCntPtr VFS = - Input.ParseInput.FSProvider->view( - Input.ParseInput.CompileCommand.Directory); + Input.ParseInput.TFS->view(Input.ParseInput.CompileCommand.Directory); if (Input.Preamble.StatCache) VFS = Input.Preamble.StatCache->getConsumingFS(std::move(VFS)); auto Clang = prepareCompilerInstance( @@ -1292,7 +1291,7 @@ public: IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration(); auto Style = getFormatStyleForFile(SemaCCInput.FileName, SemaCCInput.ParseInput.Contents, - *SemaCCInput.ParseInput.FSProvider); + *SemaCCInput.ParseInput.TFS); const auto NextToken = Lexer::findNextToken( Recorder->CCSema->getPreprocessor().getCodeCompletionLoc(), Recorder->CCSema->getSourceManager(), Recorder->CCSema->LangOpts); @@ -1364,7 +1363,7 @@ public: } CodeCompleteResult runWithoutSema(llvm::StringRef Content, size_t Offset, - const ThreadsafeFS &FSProvider) && { + const ThreadsafeFS &TFS) && { trace::Span Tracer("CodeCompleteWithoutSema"); // Fill in fields normally set by runWithSema() HeuristicPrefix = guessCompletionPrefix(Content, Offset); @@ -1380,7 +1379,7 @@ public: ProxSources[FileName].Cost = 0; FileProximity.emplace(ProxSources); - auto Style = getFormatStyleForFile(FileName, Content, FSProvider); + auto Style = getFormatStyleForFile(FileName, Content, TFS); // This will only insert verbatim headers. Inserter.emplace(FileName, Content, Style, /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr); @@ -1781,7 +1780,7 @@ CodeCompleteResult codeComplete(PathRef FileName, Position Pos, SpecFuzzyFind, Opts); return (!Preamble || Opts.RunParser == CodeCompleteOptions::NeverParse) ? std::move(Flow).runWithoutSema(ParseInput.Contents, *Offset, - *ParseInput.FSProvider) + *ParseInput.TFS) : std::move(Flow).run({FileName, *Offset, *Preamble, // We want to serve code completions with // low latency, so don't bother patching. diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp index e1882b1..2c7ef47 100644 --- a/clang-tools-extra/clangd/Compiler.cpp +++ b/clang-tools-extra/clangd/Compiler.cpp @@ -48,7 +48,7 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, for (const auto &S : Inputs.CompileCommand.CommandLine) ArgStrs.push_back(S.c_str()); - auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); + auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory); llvm::IntrusiveRefCntPtr CommandLineDiagsEngine = CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false); std::unique_ptr CI = createInvocationFromCommandLine( diff --git a/clang-tools-extra/clangd/Compiler.h b/clang-tools-extra/clangd/Compiler.h index bbec998..740a9c3 100644 --- a/clang-tools-extra/clangd/Compiler.h +++ b/clang-tools-extra/clangd/Compiler.h @@ -46,7 +46,7 @@ struct ParseOptions { /// Information required to run clang, e.g. to parse AST or do code completion. struct ParseInputs { tooling::CompileCommand CompileCommand; - const ThreadsafeFS *FSProvider; + const ThreadsafeFS *TFS; std::string Contents; // Version identifier for Contents, provided by the client and opaque to us. std::string Version = "null"; diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 2664c32..048d076 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -249,7 +249,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, trace::Span Tracer("BuildAST"); SPAN_ATTACH(Tracer, "File", Filename); - auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); + auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory); if (Preamble && Preamble->StatCache) VFS = Preamble->StatCache->getConsumingFS(std::move(VFS)); @@ -355,8 +355,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, auto BuildDir = VFS->getCurrentWorkingDirectory(); if (Inputs.Opts.SuggestMissingIncludes && Inputs.Index && !BuildDir.getError()) { - auto Style = - getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.FSProvider); + auto Style = getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.TFS); auto Inserter = std::make_shared( Filename, Inputs.Contents, Style, BuildDir.get(), &Clang->getPreprocessor().getHeaderSearchInfo()); diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp index 7a61050..8652f35 100644 --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -252,7 +252,7 @@ scanPreamble(llvm::StringRef Contents, // Build and run Preprocessor over the preamble. ParseInputs PI; PI.Contents = Contents.str(); - PI.FSProvider = FSProvider.get(); + PI.TFS = FSProvider.get(); PI.CompileCommand = Cmd; IgnoringDiagConsumer IgnoreDiags; auto CI = buildCompilerInvocation(PI, IgnoreDiags); @@ -358,7 +358,7 @@ buildPreamble(PathRef FileName, CompilerInvocation CI, CI.getPreprocessorOpts().WriteCommentListToPCH = false; CppFilePreambleCallbacks SerializedDeclsCollector(FileName, PreambleCallback); - auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); + auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory); llvm::SmallString<32> AbsFileName(FileName); VFS->makeAbsolute(AbsFileName); auto StatCache = std::make_unique(AbsFileName); @@ -395,7 +395,7 @@ bool isPreambleCompatible(const PreambleData &Preamble, llvm::MemoryBuffer::getMemBuffer(Inputs.Contents, FileName); auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0); - auto VFS = Inputs.FSProvider->view(Inputs.CompileCommand.Directory); + auto VFS = Inputs.TFS->view(Inputs.CompileCommand.Directory); return compileCommandsAreEqual(Inputs.CompileCommand, Preamble.CompileCommand) && Preamble.Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds, @@ -423,7 +423,7 @@ PreamblePatch PreamblePatch::create(llvm::StringRef FileName, SPAN_ATTACH(Tracer, "File", FileName); assert(llvm::sys::path::is_absolute(FileName) && "relative FileName!"); auto VFS = Baseline.StatCache->getConsumingFS( - Modified.FSProvider->view(/*CWD=*/llvm::None)); + Modified.TFS->view(/*CWD=*/llvm::None)); // First scan preprocessor directives in Baseline and Modified. These will be // used to figure out newly added directives in Modified. Scanning can fail, // the code just bails out and creates an empty patch in such cases, as: diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index d816f299..2b50aea 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -577,10 +577,10 @@ llvm::Optional digestFile(const SourceManager &SM, FileID FID) { format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, - const ThreadsafeFS &FSProvider) { + const ThreadsafeFS &TFS) { auto Style = format::getStyle(format::DefaultFormatStyle, File, format::DefaultFallbackStyle, Content, - FSProvider.view(/*CWD=*/llvm::None).get()); + TFS.view(/*CWD=*/llvm::None).get()); if (!Style) { log("getStyle() failed for file {0}: {1}. Fallback is LLVM style.", File, Style.takeError()); diff --git a/clang-tools-extra/clangd/SourceCode.h b/clang-tools-extra/clangd/SourceCode.h index d135550..eb63a19 100644 --- a/clang-tools-extra/clangd/SourceCode.h +++ b/clang-tools-extra/clangd/SourceCode.h @@ -168,7 +168,7 @@ llvm::Optional getCanonicalPath(const FileEntry *F, /// though the latter may have been overridden in main()! format::FormatStyle getFormatStyleForFile(llvm::StringRef File, llvm::StringRef Content, - const ThreadsafeFS &FSProvider); + const ThreadsafeFS &TFS); /// Cleanup and format the given replacements. llvm::Expected diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index bc0070a..3e68d9e 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -90,11 +90,11 @@ bool shardIsStale(const LoadedShard &LS, llvm::vfs::FileSystem *FS) { } // namespace BackgroundIndex::BackgroundIndex( - Context BackgroundContext, const ThreadsafeFS &FSProvider, + Context BackgroundContext, const ThreadsafeFS &TFS, const GlobalCompilationDatabase &CDB, BackgroundIndexStorage::Factory IndexStorageFactory, size_t ThreadPoolSize, std::function OnProgress) - : SwapIndex(std::make_unique()), FSProvider(FSProvider), CDB(CDB), + : SwapIndex(std::make_unique()), TFS(TFS), CDB(CDB), BackgroundContext(std::move(BackgroundContext)), Rebuilder(this, &IndexedSymbols, ThreadPoolSize), IndexStorageFactory(std::move(IndexStorageFactory)), @@ -244,7 +244,7 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) { SPAN_ATTACH(Tracer, "file", Cmd.Filename); auto AbsolutePath = getAbsolutePath(Cmd); - auto FS = FSProvider.view(Cmd.Directory); + auto FS = TFS.view(Cmd.Directory); auto Buf = FS->getBufferForFile(AbsolutePath); if (!Buf) return llvm::errorCodeToError(Buf.getError()); @@ -259,7 +259,7 @@ llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) { vlog("Indexing {0} (digest:={1})", Cmd.Filename, llvm::toHex(Hash)); ParseInputs Inputs; - Inputs.FSProvider = &FSProvider; + Inputs.TFS = &TFS; Inputs.CompileCommand = std::move(Cmd); IgnoreDiagnostics IgnoreDiags; auto CI = buildCompilerInvocation(Inputs, IgnoreDiags); @@ -381,7 +381,7 @@ BackgroundIndex::loadProject(std::vector MainFiles) { Rebuilder.loadedShard(LoadedShards); Rebuilder.doneLoading(); - auto FS = FSProvider.view(/*CWD=*/llvm::None); + auto FS = TFS.view(/*CWD=*/llvm::None); llvm::DenseSet TUsToIndex; // We'll accept data from stale shards, but ensure the files get reindexed // soon. diff --git a/clang-tools-extra/clangd/index/Background.h b/clang-tools-extra/clangd/index/Background.h index 7b0368e0..9ae6382 100644 --- a/clang-tools-extra/clangd/index/Background.h +++ b/clang-tools-extra/clangd/index/Background.h @@ -178,7 +178,7 @@ private: bool HadErrors); // configuration - const ThreadsafeFS &FSProvider; + const ThreadsafeFS &TFS; const GlobalCompilationDatabase &CDB; Context BackgroundContext; diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index 9322811..c77f92d 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -676,7 +676,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var CCOpts.AllScopes = AllScopesCompletion; CCOpts.RunParser = CodeCompletionParse; - RealThreadsafeFS FSProvider; + RealThreadsafeFS TFS; // Initialize and run ClangdLSPServer. // Change stdin to binary to not lose \r\n on windows. llvm::sys::ChangeStdinToBinary(); @@ -719,8 +719,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var ClangTidyOptProvider = std::make_unique( tidy::ClangTidyGlobalOptions(), /* Default */ EmptyDefaults, - /* Override */ OverrideClangTidyOptions, - FSProvider.view(/*CWD=*/llvm::None)); + /* Override */ OverrideClangTidyOptions, TFS.view(/*CWD=*/llvm::None)); Opts.GetClangTidyOptions = [&](llvm::vfs::FileSystem &, llvm::StringRef File) { // This function must be thread-safe and tidy option providers are not. @@ -771,7 +770,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var Opts.AsyncPreambleBuilds = AsyncPreamble; ClangdLSPServer LSPServer( - *TransportLayer, FSProvider, CCOpts, RenameOpts, CompileCommandsDirPath, + *TransportLayer, TFS, CCOpts, RenameOpts, CompileCommandsDirPath, /*UseDirBasedCDB=*/CompileArgsFrom == FilesystemCompileArgs, OffsetEncodingFromFlag, Opts); llvm::set_thread_name("clangd.main"); diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp index ffe752f..e1f02c8 100644 --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -272,7 +272,7 @@ int b = a; TEST_F(ClangdVFSTest, PropagatesContexts) { static Key Secret; - struct FSProvider : public ThreadsafeFS { + struct ContextReadingFS : public ThreadsafeFS { IntrusiveRefCntPtr view(llvm::NoneType) const override { Got = Context::current().getExisting(Secret); @@ -924,17 +924,17 @@ TEST_F(ClangdVFSTest, ChangedHeaderFromISystem) { // Check that running code completion doesn't stat() a bunch of files from the // preamble again. (They should be using the preamble's stat-cache) TEST(ClangdTests, PreambleVFSStatCache) { - class ListenStatsFSProvider : public ThreadsafeFS { + class StatRecordingFS : public ThreadsafeFS { public: - ListenStatsFSProvider(llvm::StringMap &CountStats) + StatRecordingFS(llvm::StringMap &CountStats) : CountStats(CountStats) {} IntrusiveRefCntPtr view(llvm::NoneType) const override { - class ListenStatVFS : public llvm::vfs::ProxyFileSystem { + class StatRecordingVFS : public llvm::vfs::ProxyFileSystem { public: - ListenStatVFS(IntrusiveRefCntPtr FS, - llvm::StringMap &CountStats) + StatRecordingVFS(IntrusiveRefCntPtr FS, + llvm::StringMap &CountStats) : ProxyFileSystem(std::move(FS)), CountStats(CountStats) {} llvm::ErrorOr> @@ -951,8 +951,8 @@ TEST(ClangdTests, PreambleVFSStatCache) { llvm::StringMap &CountStats; }; - return IntrusiveRefCntPtr( - new ListenStatVFS(buildTestFS(Files), CountStats)); + return IntrusiveRefCntPtr( + new StatRecordingVFS(buildTestFS(Files), CountStats)); } // If relative paths are used, they are resolved with testPath(). @@ -961,7 +961,7 @@ TEST(ClangdTests, PreambleVFSStatCache) { }; llvm::StringMap CountStats; - ListenStatsFSProvider FS(CountStats); + StatRecordingFS FS(CountStats); ErrorCheckingCallbacks DiagConsumer; MockCompilationDatabase CDB; ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp index b441213..1026055 100644 --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -272,14 +272,14 @@ TEST(FileIndexTest, RebuildWithPreamble) { PI.CompileCommand.Filename = FooCpp; PI.CompileCommand.CommandLine = {"clang", "-xc++", FooCpp}; - MockFS FSProvider; - FSProvider.Files[FooCpp] = ""; - FSProvider.Files[FooH] = R"cpp( + MockFS FS; + FS.Files[FooCpp] = ""; + FS.Files[FooH] = R"cpp( namespace ns_in_header { int func_in_header(); } )cpp"; - PI.FSProvider = &FSProvider; + PI.TFS = &FS; PI.Contents = R"cpp( #include "foo.h" diff --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp index 39ee286..b888ba2 100644 --- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp @@ -51,14 +51,14 @@ ClangdServer::Options optsForTests() { class WorkspaceSymbolsTest : public ::testing::Test { public: - WorkspaceSymbolsTest() : Server(CDB, FSProvider, optsForTests()) { + WorkspaceSymbolsTest() : Server(CDB, FS, optsForTests()) { // Make sure the test root directory is created. - FSProvider.Files[testPath("unused")] = ""; + FS.Files[testPath("unused")] = ""; CDB.ExtraClangFlags = {"-xc++"}; } protected: - MockFS FSProvider; + MockFS FS; MockCompilationDatabase CDB; ClangdServer Server; int Limit = 0; @@ -307,10 +307,10 @@ TEST_F(WorkspaceSymbolsTest, TempSpecs) { namespace { class DocumentSymbolsTest : public ::testing::Test { public: - DocumentSymbolsTest() : Server(CDB, FSProvider, optsForTests()) {} + DocumentSymbolsTest() : Server(CDB, FS, optsForTests()) {} protected: - MockFS FSProvider; + MockFS FS; MockCompilationDatabase CDB; ClangdServer Server; diff --git a/clang-tools-extra/clangd/unittests/HeadersTests.cpp b/clang-tools-extra/clangd/unittests/HeadersTests.cpp index 7fbf71e..13babb8 100644 --- a/clang-tools-extra/clangd/unittests/HeadersTests.cpp +++ b/clang-tools-extra/clangd/unittests/HeadersTests.cpp @@ -48,12 +48,12 @@ private: ParseInputs PI; PI.CompileCommand = *Cmd; - PI.FSProvider = &FS; + PI.TFS = &FS; auto CI = buildCompilerInvocation(PI, IgnoreDiags); EXPECT_TRUE(static_cast(CI)); // The diagnostic options must be set before creating a CompilerInstance. CI->getDiagnosticOpts().IgnoreWarnings = true; - auto VFS = PI.FSProvider->view(Cmd->Directory); + auto VFS = PI.TFS->view(Cmd->Directory); auto Clang = prepareCompilerInstance( std::move(CI), /*Preamble=*/nullptr, llvm::MemoryBuffer::getMemBuffer(FS.Files[MainFile], MainFile), diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp index 72dc9a7..2f3fbc2 100644 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -249,11 +249,11 @@ TEST(ParsedASTTest, NoCrashOnTokensWithTidyCheck) { } TEST(ParsedASTTest, CanBuildInvocationWithUnknownArgs) { - MockFS FSProvider; - FSProvider.Files = {{testPath("foo.cpp"), "void test() {}"}}; + MockFS FS; + FS.Files = {{testPath("foo.cpp"), "void test() {}"}}; // Unknown flags should not prevent a build of compiler invocation. ParseInputs Inputs; - Inputs.FSProvider = &FSProvider; + Inputs.TFS = &FS; Inputs.CompileCommand.CommandLine = {"clang", "-fsome-unknown-flag", testPath("foo.cpp")}; IgnoreDiagnostics IgnoreDiags; diff --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp b/clang-tools-extra/clangd/unittests/PreambleTests.cpp index e93ec31..5bbcb29 100644 --- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp @@ -70,11 +70,11 @@ collectPatchedIncludes(llvm::StringRef ModifiedContents, // We don't run PP directly over the patch cotents to test production // behaviour. auto Bounds = Lexer::ComputePreamble(ModifiedContents, *CI->getLangOpts()); - auto Clang = prepareCompilerInstance( - std::move(CI), &BaselinePreamble->Preamble, - llvm::MemoryBuffer::getMemBufferCopy( - ModifiedContents.slice(0, Bounds.Size).str()), - PI.FSProvider->view(PI.CompileCommand.Directory), Diags); + auto Clang = + prepareCompilerInstance(std::move(CI), &BaselinePreamble->Preamble, + llvm::MemoryBuffer::getMemBufferCopy( + ModifiedContents.slice(0, Bounds.Size).str()), + PI.TFS->view(PI.CompileCommand.Directory), Diags); PreprocessOnlyAction Action; if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0])) { ADD_FAILURE() << "failed begin source file"; @@ -518,12 +518,12 @@ TEST(PreamblePatch, ModifiedBounds) { Annotations Modified(Case.Modified); TU.Code = Modified.code().str(); - MockFS FSProvider; - auto PP = PreamblePatch::create(testPath(TU.Filename), - TU.inputs(FSProvider), *BaselinePreamble); + MockFS FS; + auto PP = PreamblePatch::create(testPath(TU.Filename), TU.inputs(FS), + *BaselinePreamble); IgnoreDiagnostics Diags; - auto CI = buildCompilerInvocation(TU.inputs(FSProvider), Diags); + auto CI = buildCompilerInvocation(TU.inputs(FS), Diags); ASSERT_TRUE(CI); const auto ExpectedBounds = diff --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp index 7e397af..53a5979 100644 --- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp +++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp @@ -74,7 +74,7 @@ protected: ParseInputs getInputs(PathRef File, std::string Contents) { ParseInputs Inputs; Inputs.CompileCommand = *CDB.getCompileCommand(File); - Inputs.FSProvider = &FSProvider; + Inputs.TFS = &FS; Inputs.Contents = std::move(Contents); Inputs.Opts = ParseOptions(); return Inputs; @@ -150,7 +150,7 @@ protected: std::move(CB)); } - MockFS FSProvider; + MockFS FS; MockCompilationDatabase CDB; }; @@ -161,10 +161,10 @@ TEST_F(TUSchedulerTests, MissingFiles) { TUScheduler S(CDB, optsForTest()); auto Added = testPath("added.cpp"); - FSProvider.Files[Added] = "x"; + FS.Files[Added] = "x"; auto Missing = testPath("missing.cpp"); - FSProvider.Files[Missing] = ""; + FS.Files[Missing] = ""; S.update(Added, getInputs(Added, "x"), WantDiagnostics::No); @@ -425,7 +425,7 @@ TEST_F(TUSchedulerTests, ManyUpdates) { for (int I = 0; I < FilesCount; ++I) { std::string Name = "foo" + std::to_string(I) + ".cpp"; Files.push_back(testPath(Name)); - this->FSProvider.Files[Files.back()] = ""; + this->FS.Files[Files.back()] = ""; } StringRef Contents1 = R"cpp(int a;)cpp"; @@ -616,8 +616,8 @@ TEST_F(TUSchedulerTests, EmptyPreamble) { auto Foo = testPath("foo.cpp"); auto Header = testPath("foo.h"); - FSProvider.Files[Header] = "void foo()"; - FSProvider.Timestamps[Header] = time_t(0); + FS.Files[Header] = "void foo()"; + FS.Timestamps[Header] = time_t(0); auto WithPreamble = R"cpp( #include "foo.h" int main() {} @@ -685,8 +685,8 @@ TEST_F(TUSchedulerTests, NoopOnEmptyChanges) { auto Source = testPath("foo.cpp"); auto Header = testPath("foo.h"); - FSProvider.Files[Header] = "int a;"; - FSProvider.Timestamps[Header] = time_t(0); + FS.Files[Header] = "int a;"; + FS.Timestamps[Header] = time_t(0); std::string SourceContents = R"cpp( #include "foo.h" @@ -714,7 +714,7 @@ TEST_F(TUSchedulerTests, NoopOnEmptyChanges) { ASSERT_EQ(S.fileStats().lookup(Source).PreambleBuilds, 1u); // Update to a header should cause a rebuild, though. - FSProvider.Timestamps[Header] = time_t(1); + FS.Timestamps[Header] = time_t(1); ASSERT_TRUE(DoUpdate(SourceContents)); ASSERT_FALSE(DoUpdate(SourceContents)); ASSERT_EQ(S.fileStats().lookup(Source).ASTBuilds, 2u); @@ -742,8 +742,8 @@ TEST_F(TUSchedulerTests, MissingHeader) { CDB.ExtraClangFlags.push_back("-I" + testPath("a")); CDB.ExtraClangFlags.push_back("-I" + testPath("b")); // Force both directories to exist so they don't get pruned. - FSProvider.Files.try_emplace("a/__unused__"); - FSProvider.Files.try_emplace("b/__unused__"); + FS.Files.try_emplace("a/__unused__"); + FS.Files.try_emplace("b/__unused__"); TUScheduler S(CDB, optsForTest(), captureDiags()); auto Source = testPath("foo.cpp"); @@ -771,8 +771,8 @@ TEST_F(TUSchedulerTests, MissingHeader) { }); S.blockUntilIdle(timeoutSeconds(10)); - FSProvider.Files[HeaderB] = "int b;"; - FSProvider.Timestamps[HeaderB] = time_t(1); + FS.Files[HeaderB] = "int b;"; + FS.Timestamps[HeaderB] = time_t(1); // The addition of the missing header file triggers a rebuild, no errors. updateWithDiags(S, Source, Inputs, WantDiagnostics::Yes, @@ -784,8 +784,8 @@ TEST_F(TUSchedulerTests, MissingHeader) { // Ensure previous assertions are done before we touch the FS again. ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10))); // Add the high-priority header file, which should reintroduce the error. - FSProvider.Files[HeaderA] = "int a;"; - FSProvider.Timestamps[HeaderA] = time_t(1); + FS.Files[HeaderA] = "int a;"; + FS.Timestamps[HeaderA] = time_t(1); // This isn't detected: we don't stat a/foo.h to validate the preamble. updateWithDiags(S, Source, Inputs, WantDiagnostics::Yes, diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp index 6bebb35..7d5c29f 100644 --- a/clang-tools-extra/clangd/unittests/TestTU.cpp +++ b/clang-tools-extra/clangd/unittests/TestTU.cpp @@ -20,7 +20,7 @@ namespace clang { namespace clangd { -ParseInputs TestTU::inputs(MockFS &FSProvider) const { +ParseInputs TestTU::inputs(MockFS &FS) const { std::string FullFilename = testPath(Filename), FullHeaderName = testPath(HeaderFilename), ImportThunk = testPath("import_thunk.h"); @@ -29,10 +29,10 @@ ParseInputs TestTU::inputs(MockFS &FSProvider) const { // guard without messing up offsets). In this case, use an intermediate file. std::string ThunkContents = "#import \"" + FullHeaderName + "\"\n"; - FSProvider.Files = AdditionalFiles; - FSProvider.Files[FullFilename] = Code; - FSProvider.Files[FullHeaderName] = HeaderCode; - FSProvider.Files[ImportThunk] = ThunkContents; + FS.Files = AdditionalFiles; + FS.Files[FullFilename] = Code; + FS.Files[FullHeaderName] = HeaderCode; + FS.Files[ImportThunk] = ThunkContents; ParseInputs Inputs; auto &Argv = Inputs.CompileCommand.CommandLine; @@ -54,7 +54,7 @@ ParseInputs TestTU::inputs(MockFS &FSProvider) const { Inputs.CompileCommand.Filename = FullFilename; Inputs.CompileCommand.Directory = testRoot(); Inputs.Contents = Code; - Inputs.FSProvider = &FSProvider; + Inputs.TFS = &FS; Inputs.Opts = ParseOptions(); Inputs.Opts.BuildRecoveryAST = true; Inputs.Opts.PreserveRecoveryASTType = true; @@ -67,8 +67,8 @@ ParseInputs TestTU::inputs(MockFS &FSProvider) const { } std::shared_ptr TestTU::preamble() const { - MockFS FSProvider; - auto Inputs = inputs(FSProvider); + MockFS FS; + auto Inputs = inputs(FS); IgnoreDiagnostics Diags; auto CI = buildCompilerInvocation(Inputs, Diags); assert(CI && "Failed to build compilation invocation."); @@ -78,8 +78,8 @@ std::shared_ptr TestTU::preamble() const { } ParsedAST TestTU::build() const { - MockFS FSProvider; - auto Inputs = inputs(FSProvider); + MockFS FS; + auto Inputs = inputs(FS); StoreDiags Diags; auto CI = buildCompilerInvocation(Inputs, Diags); assert(CI && "Failed to build compilation invocation."); diff --git a/clang-tools-extra/clangd/unittests/TestTU.h b/clang-tools-extra/clangd/unittests/TestTU.h index ebc05b3..06abd64 100644 --- a/clang-tools-extra/clangd/unittests/TestTU.h +++ b/clang-tools-extra/clangd/unittests/TestTU.h @@ -70,7 +70,7 @@ struct TestTU { // Suppress this behavior by adding an 'error-ok' comment to the code. ParsedAST build() const; std::shared_ptr preamble() const; - ParseInputs inputs(MockFS &FSProvider) const; + ParseInputs inputs(MockFS &FS) const; SymbolSlab headerSymbols() const; RefSlab headerRefs() const; std::unique_ptr index() const; -- 2.7.4