Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -308,7 +308,7 @@ 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 @@ 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(); Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -368,6 +368,10 @@ 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 &); Index: clangd/Protocol.cpp =================================================================== --- clangd/Protocol.cpp +++ clangd/Protocol.cpp @@ -669,6 +669,7 @@ fromJSON(Params, Opts.ConfigSettings); O.map("compilationDatabasePath", Opts.compilationDatabasePath); + O.map("fallbackFlags", Opts.fallbackFlags); return true; }