summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/GlobalCompilationDatabase.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/GlobalCompilationDatabase.h')
-rw-r--r--clang-tools-extra/clangd/GlobalCompilationDatabase.h19
1 files changed, 14 insertions, 5 deletions
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index 8297db1eaf4..84b17422db5 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -10,6 +10,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
+#include "Function.h"
#include "Path.h"
#include "llvm/ADT/StringMap.h"
#include <memory>
@@ -41,8 +42,15 @@ public:
/// Clangd should treat the results as unreliable.
virtual tooling::CompileCommand getFallbackCommand(PathRef File) const;
- /// FIXME(ibiryukov): add facilities to track changes to compilation flags of
- /// existing targets.
+ using CommandChanged = Event<std::vector<std::string>>;
+ /// The callback is notified when files may have new compile commands.
+ /// The argument is a list of full file paths.
+ CommandChanged::Subscription watch(CommandChanged::Listener L) const {
+ return OnCommandChanged.observe(std::move(L));
+ }
+
+protected:
+ mutable CommandChanged OnCommandChanged;
};
/// Gets compile args from tooling::CompilationDatabases built for parent
@@ -61,7 +69,8 @@ public:
private:
tooling::CompilationDatabase *getCDBForFile(PathRef File) const;
- tooling::CompilationDatabase *getCDBInDirLocked(PathRef File) const;
+ std::pair<tooling::CompilationDatabase *, /*Cached*/ bool>
+ getCDBInDirLocked(PathRef File) const;
mutable std::mutex Mutex;
/// Caches compilation databases loaded from directories(keys are
@@ -81,8 +90,7 @@ public:
// Base may be null, in which case no entries are inherited.
// FallbackFlags are added to the fallback compile command.
OverlayCDB(const GlobalCompilationDatabase *Base,
- std::vector<std::string> FallbackFlags = {})
- : Base(Base), FallbackFlags(std::move(FallbackFlags)) {}
+ std::vector<std::string> FallbackFlags = {});
llvm::Optional<tooling::CompileCommand>
getCompileCommand(PathRef File) const override;
@@ -98,6 +106,7 @@ private:
llvm::StringMap<tooling::CompileCommand> Commands; /* GUARDED_BY(Mut) */
const GlobalCompilationDatabase *Base;
std::vector<std::string> FallbackFlags;
+ CommandChanged::Subscription BaseChanged;
};
} // namespace clangd
OpenPOWER on IntegriCloud