From: Sam McCall Date: Fri, 2 Nov 2018 14:07:51 +0000 (+0000) Subject: [clangd] Add fallbackFlags initialization extension. X-Git-Tag: llvmorg-8.0.0-rc1~5142 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6980edb8fbf839724ba2356171dce387a6abb487;p=platform%2Fupstream%2Fllvm.git [clangd] Add fallbackFlags initialization extension. Summary: This allows customizing the flags used when no compile database is available. It addresses some uses of the old extraFlags extension. Reviewers: ilya-biryukov Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D53688 llvm-svn: 345973 --- diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp index 2d4a9cf..75a99a2 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.cpp +++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp @@ -308,7 +308,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params, if (UseDirBasedCDB) BaseCDB = llvm::make_unique( CompileCommandsDir); - CDB.emplace(BaseCDB.get()); + CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags); Server.emplace(*CDB, FSProvider, static_cast(*this), ClangdServerOpts); applyConfiguration(Params.initializationOptions.ConfigSettings); @@ -664,9 +664,10 @@ void ClangdLSPServer::applyConfiguration( tooling::CompileCommand(std::move(Entry.second.workingDirectory), File, std::move(Entry.second.compilationCommand), /*Output=*/""); - if (Old != New) + if (Old != New) { CDB->setCompileCommand(File, std::move(New)); - ShouldReparseOpenFiles = true; + ShouldReparseOpenFiles = true; + } } if (ShouldReparseOpenFiles) reparseOpenedFiles(); diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index 765c342..d8369f3 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -669,6 +669,7 @@ bool fromJSON(const json::Value &Params, InitializationOptions &Opts) { fromJSON(Params, Opts.ConfigSettings); O.map("compilationDatabasePath", Opts.compilationDatabasePath); + O.map("fallbackFlags", Opts.fallbackFlags); return true; } diff --git a/clang-tools-extra/clangd/Protocol.h b/clang-tools-extra/clangd/Protocol.h index bfa7757..b62e57f 100644 --- a/clang-tools-extra/clangd/Protocol.h +++ b/clang-tools-extra/clangd/Protocol.h @@ -368,6 +368,10 @@ struct InitializationOptions { ConfigurationSettings ConfigSettings; llvm::Optional compilationDatabasePath; + // Additional flags to be included in the "fallback command" used when + // the compilation database doesn't describe an opened file. + // The command used will be approximately `clang $FILE $fallbackFlags`. + std::vector fallbackFlags; }; bool fromJSON(const llvm::json::Value &, InitializationOptions &);