summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/TUScheduler.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2018-08-09 09:05:45 +0000
committerEric Liu <ioeric@google.com>2018-08-09 09:05:45 +0000
commitf40819ea2d4c6ee471846126e9aa60477c5bcf6d (patch)
treec50f3464914bf1277f73daed84625688323670f7 /clang-tools-extra/clangd/TUScheduler.cpp
parent5df524f81d5ddf72162b621b29e28f7235b9dc40 (diff)
downloadbcm5719-llvm-f40819ea2d4c6ee471846126e9aa60477c5bcf6d.tar.gz
bcm5719-llvm-f40819ea2d4c6ee471846126e9aa60477c5bcf6d.zip
[clangd] Record the file being processed in a TUScheduler thread in context.
Summary: This allows implementations like different symbol indexes to know what the current active file is. For example, some customized index implementation might decide to only return results for some files. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D50446 llvm-svn: 339320
Diffstat (limited to 'clang-tools-extra/clangd/TUScheduler.cpp')
-rw-r--r--clang-tools-extra/clangd/TUScheduler.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 81a75bbc21a..cae4b0911fe 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -63,6 +63,14 @@ namespace {
class ASTWorker;
}
+static const clang::clangd::Key<std::string> kFileBeingProcessed;
+
+llvm::Optional<llvm::StringRef> TUScheduler::getFileBeingProcessedInContext() {
+ if (auto *File = Context::current().get(kFileBeingProcessed))
+ return StringRef(*File);
+ return llvm::None;
+}
+
/// An LRU cache of idle ASTs.
/// Because we want to limit the overall number of these we retain, the cache
/// owns ASTs (and may evict them) while their workers are idle.
@@ -491,8 +499,9 @@ void ASTWorker::startTask(llvm::StringRef Name,
{
std::lock_guard<std::mutex> Lock(Mutex);
assert(!Done && "running a task after stop()");
- Requests.push_back({std::move(Task), Name, steady_clock::now(),
- Context::current().clone(), UpdateType});
+ Requests.push_back(
+ {std::move(Task), Name, steady_clock::now(),
+ Context::current().derive(kFileBeingProcessed, FileName), UpdateType});
}
RequestsCV.notify_all();
}
@@ -734,10 +743,12 @@ void TUScheduler::runWithPreamble(
Action(InputsAndPreamble{Contents, Command, Preamble.get()});
};
- PreambleTasks->runAsync("task:" + llvm::sys::path::filename(File),
- Bind(Task, std::string(Name), std::string(File),
- It->second->Contents, It->second->Command,
- Context::current().clone(), std::move(Action)));
+ PreambleTasks->runAsync(
+ "task:" + llvm::sys::path::filename(File),
+ Bind(Task, std::string(Name), std::string(File), It->second->Contents,
+ It->second->Command,
+ Context::current().derive(kFileBeingProcessed, File),
+ std::move(Action)));
}
std::vector<std::pair<Path, std::size_t>>
OpenPOWER on IntegriCloud