Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -303,12 +303,15 @@ if (Server) return Reply(make_error("server already initialized", ErrorCode::InvalidRequest)); - if (Params.initializationOptions) + std::vector FallbackFlags; + if (Params.initializationOptions) { CompileCommandsDir = Params.initializationOptions->compilationDatabasePath; + FallbackFlags = Params.initializationOptions->fallbackFlags; + } if (UseDirBasedCDB) BaseCDB = llvm::make_unique( CompileCommandsDir); - CDB.emplace(BaseCDB.get()); + CDB.emplace(BaseCDB.get(), std::move(FallbackFlags)); Server.emplace(*CDB, FSProvider, static_cast(*this), ClangdServerOpts); if (Params.initializationOptions) Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -367,6 +367,10 @@ ClangdConfigurationParamsChange ParamsChange; 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 &, 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) {