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
@@ -1365,6 +1365,7 @@ struct DaemonCmdOptions {
|
||||
std::vector<std::string> targets;
|
||||
std::string jobs_arg{"0"};
|
||||
std::string editor_arg{"all"};
|
||||
std::string timeout_ms_arg{"2000"};
|
||||
bool force{false};
|
||||
std::string max_bytes_arg{"0"};
|
||||
std::string max_requests_arg{"0"};
|
||||
@@ -1447,6 +1448,18 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg));
|
||||
} else if (sub == "watch_poll") {
|
||||
request_json = R"({"op":"watch_poll"})";
|
||||
} else if (sub == "watch_wait") {
|
||||
std::int64_t timeout_ms = 0;
|
||||
const auto [ptr, ec] =
|
||||
std::from_chars(opts.timeout_ms_arg.data(),
|
||||
opts.timeout_ms_arg.data() + opts.timeout_ms_arg.size(), timeout_ms);
|
||||
if (ec != std::errc{} || ptr != opts.timeout_ms_arg.data() + opts.timeout_ms_arg.size() ||
|
||||
timeout_ms < 0 || timeout_ms > 5000) {
|
||||
std::cerr << "vbs daemon ide wait: invalid --timeout-ms value '" << opts.timeout_ms_arg
|
||||
<< "' (0..5000)\n";
|
||||
return 2;
|
||||
}
|
||||
request_json = std::format(R"({{"op":"watch_wait","timeout_ms":{}}})", timeout_ms);
|
||||
} else if (sub == "ide_generate") {
|
||||
if (opts.profile_arg.empty()) {
|
||||
std::cerr << "vbs daemon ide generate: --profile must not be empty\n";
|
||||
@@ -1496,6 +1509,7 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
const auto request_timeout =
|
||||
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
|
||||
: sub == "watch_poll" ? std::chrono::milliseconds{5000}
|
||||
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
|
||||
: sub == "describe" ? std::chrono::milliseconds{15000}
|
||||
: (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export")
|
||||
? std::chrono::milliseconds{30000}
|
||||
@@ -2459,6 +2473,11 @@ int main(int argc, char **argv) {
|
||||
auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand(
|
||||
"poll", "Poll pending project file changes (editor extension protocol)");
|
||||
configure_daemon_common(daemon_ide_poll_cmd);
|
||||
auto &daemon_ide_wait_cmd = daemon_ide_cmd.subcommand(
|
||||
"wait", "Long-poll for project file changes (bounded, editor extension protocol)");
|
||||
configure_daemon_common(daemon_ide_wait_cmd);
|
||||
daemon_ide_wait_cmd.option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)",
|
||||
daemon_opts.timeout_ms_arg, "2000");
|
||||
auto &daemon_ide_generate_cmd =
|
||||
daemon_ide_cmd.subcommand("generate", "Write editor configuration files");
|
||||
configure_daemon_common(daemon_ide_generate_cmd);
|
||||
@@ -2569,6 +2588,9 @@ int main(int argc, char **argv) {
|
||||
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "poll") {
|
||||
daemon_sub = "watch_poll";
|
||||
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "wait") {
|
||||
daemon_sub = "watch_wait";
|
||||
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
||||
parsed.matched_command_path[2] == "export") {
|
||||
daemon_sub = "compdb_export";
|
||||
|
||||
Reference in new issue
Block a user