sammccall created this revision. sammccall added a reviewer: ilya-biryukov. Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, ioeric.
This allows customizing the flags used when no compile database is available. It addresses some uses of the old extraFlags extension. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D53688 Files: clangd/ClangdLSPServer.cpp clangd/Protocol.cpp clangd/Protocol.h Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -367,6 +367,10 @@ ClangdConfigurationParamsChange ParamsChange; llvm::Optional<std::string> 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<std::string> fallbackFlags; }; bool fromJSON(const llvm::json::Value &, ClangdInitializationOptions &); Index: clangd/Protocol.cpp =================================================================== --- clangd/Protocol.cpp +++ clangd/Protocol.cpp @@ -667,7 +667,10 @@ } json::ObjectMapper O(Params); - return O && O.map("compilationDatabasePath", Opts.compilationDatabasePath); + if (!O && !O.map("compilationDatabasePath", Opts.compilationDatabasePath)) + return false; + O.map("fallbackFlags", Opts.fallbackFlags); + return true; } bool fromJSON(const json::Value &Params, ReferenceParams &R) { Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -303,12 +303,15 @@ if (Server) return Reply(make_error<LSPError>("server already initialized", ErrorCode::InvalidRequest)); - if (Params.initializationOptions) + std::vector<std::string> FallbackFlags; + if (Params.initializationOptions) { CompileCommandsDir = Params.initializationOptions->compilationDatabasePath; + FallbackFlags = Params.initializationOptions->fallbackFlags; + } if (UseDirBasedCDB) BaseCDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>( CompileCommandsDir); - CDB.emplace(BaseCDB.get()); + CDB.emplace(BaseCDB.get(), std::move(FallbackFlags)); Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this), ClangdServerOpts); if (Params.initializationOptions)
Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -367,6 +367,10 @@ ClangdConfigurationParamsChange ParamsChange; llvm::Optional<std::string> 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<std::string> fallbackFlags; }; bool fromJSON(const llvm::json::Value &, ClangdInitializationOptions &); Index: clangd/Protocol.cpp =================================================================== --- clangd/Protocol.cpp +++ clangd/Protocol.cpp @@ -667,7 +667,10 @@ } json::ObjectMapper O(Params); - return O && O.map("compilationDatabasePath", Opts.compilationDatabasePath); + if (!O && !O.map("compilationDatabasePath", Opts.compilationDatabasePath)) + return false; + O.map("fallbackFlags", Opts.fallbackFlags); + return true; } bool fromJSON(const json::Value &Params, ReferenceParams &R) { Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -303,12 +303,15 @@ if (Server) return Reply(make_error<LSPError>("server already initialized", ErrorCode::InvalidRequest)); - if (Params.initializationOptions) + std::vector<std::string> FallbackFlags; + if (Params.initializationOptions) { CompileCommandsDir = Params.initializationOptions->compilationDatabasePath; + FallbackFlags = Params.initializationOptions->fallbackFlags; + } if (UseDirBasedCDB) BaseCDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>( CompileCommandsDir); - CDB.emplace(BaseCDB.get()); + CDB.emplace(BaseCDB.get(), std::move(FallbackFlags)); Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this), ClangdServerOpts); if (Params.initializationOptions)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits