diff options
Diffstat (limited to 'clang-tools-extra/clangd/GlobalCompilationDatabase.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/GlobalCompilationDatabase.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp index acfd5953a16..d02e5e9ff61 100644 --- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -80,22 +80,32 @@ DirectoryBasedGlobalCompilationDatabase::getCDBForFile(PathRef File) const { } Optional<tooling::CompileCommand> -InMemoryCompilationDb::getCompileCommand(PathRef File) const { +OverlayCDB::getCompileCommand(PathRef File) const { + { + std::lock_guard<std::mutex> Lock(Mutex); + auto It = Commands.find(File); + if (It != Commands.end()) + return It->second; + } + return Base ? Base->getCompileCommand(File) : None; +} + +tooling::CompileCommand OverlayCDB::getFallbackCommand(PathRef File) const { + auto Cmd = Base ? Base->getFallbackCommand(File) + : GlobalCompilationDatabase::getFallbackCommand(File); std::lock_guard<std::mutex> Lock(Mutex); - auto It = Commands.find(File); - if (It == Commands.end()) - return None; - return It->second; + Cmd.CommandLine.insert(Cmd.CommandLine.end(), FallbackFlags.begin(), + FallbackFlags.end()); + return Cmd; } -bool InMemoryCompilationDb::setCompilationCommandForFile( - PathRef File, tooling::CompileCommand CompilationCommand) { +void OverlayCDB::setCompileCommand( + PathRef File, llvm::Optional<tooling::CompileCommand> Cmd) { std::unique_lock<std::mutex> Lock(Mutex); - auto ItInserted = Commands.insert(std::make_pair(File, CompilationCommand)); - if (ItInserted.second) - return true; - ItInserted.first->setValue(std::move(CompilationCommand)); - return false; + if (Cmd) + Commands[File] = std::move(*Cmd); + else + Commands.erase(File); } } // namespace clangd |

