feat(daemon): add bounded long-poll watch request for editor extensions
This commit is contained in:
1 parent
c7a6bad3c0
commit
64116f6e0d
9 files changed
+129
-3
No files matched your search
@@ -58,6 +58,8 @@ constexpr std::size_t kMaxDescribeTargetNames = 128U;
|
||||
constexpr std::size_t kMaxDescribeTargetNameBytes = 200U;
|
||||
constexpr std::size_t kMaxBuildTargets = 64U;
|
||||
constexpr std::size_t kMaxPendingChanges = 4096U;
|
||||
constexpr std::int64_t kMaxWatchWaitMs = 5000;
|
||||
constexpr std::int64_t kDefaultWatchWaitMs = 2000;
|
||||
|
||||
Void::Result::Error make_error(Void::Result::ErrorKind kind, std::string message,
|
||||
int system_errno = 0) {
|
||||
@@ -901,6 +903,44 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
object.emplace("rescan_required", JsonValue{batch->rescan_required});
|
||||
return {serialize_response(JsonValue{std::move(object)}), false};
|
||||
}
|
||||
if (*name == "watch_wait") {
|
||||
std::int64_t timeout_ms = kDefaultWatchWaitMs;
|
||||
if (const auto entry = object->find("timeout_ms"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::int64_t>(&entry->second.value);
|
||||
if (value == nullptr || *value < 0 || *value > kMaxWatchWaitMs) {
|
||||
return {error_response(std::format("\"timeout_ms\" must be an integer in [0, {}]",
|
||||
kMaxWatchWaitMs)),
|
||||
false};
|
||||
}
|
||||
timeout_ms = *value;
|
||||
}
|
||||
|
||||
bool timed_out = false;
|
||||
if (pending_changes.empty() && timeout_ms > 0) {
|
||||
auto batch = watcher.poll_events(std::chrono::milliseconds{timeout_ms},
|
||||
std::chrono::milliseconds{0});
|
||||
if (!batch) {
|
||||
return {error_response(std::format("watch_wait: {}", batch.error().format())),
|
||||
false};
|
||||
}
|
||||
timed_out =
|
||||
batch->changed_paths.empty() && !batch->overflowed && !batch->rescan_required;
|
||||
record_watch_batch(*batch);
|
||||
}
|
||||
JsonValue::Array changed;
|
||||
for (const auto &path : pending_changes) {
|
||||
changed.emplace_back(path.string());
|
||||
}
|
||||
pending_changes.clear();
|
||||
JsonValue::Object object;
|
||||
object.emplace("ok", JsonValue{true});
|
||||
object.emplace("op", JsonValue{std::string{"watch_wait"}});
|
||||
object.emplace("sequence", JsonValue{static_cast<std::int64_t>(sequence)});
|
||||
object.emplace("watch_events", JsonValue{static_cast<std::int64_t>(watch_events)});
|
||||
object.emplace("changed", JsonValue{std::move(changed)});
|
||||
object.emplace("timed_out", JsonValue{timed_out});
|
||||
return {serialize_response(JsonValue{std::move(object)}), false};
|
||||
}
|
||||
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
|
||||
*name == "ide_generate" || *name == "compdb_export") {
|
||||
std::string profile_name{"debug"};
|
||||
|
||||
Reference in new issue
Block a user