feat(daemon): generate editor configuration files over the Unix socket
This commit is contained in:
1 parent
72f4237af2
commit
e15e2cb2b4
9 files changed
+189
-9
No files matched your search
@@ -51,6 +51,7 @@ check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --he
|
||||
check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemon build --help)
|
||||
check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query --help)
|
||||
check_process(0 "Usage: vbs daemon compdb export .*--profile" "" daemon compdb export --help)
|
||||
check_process(0 "Usage: vbs daemon ide generate .*--profile.*--editor.*--force" "" daemon ide generate --help)
|
||||
check_process(2 "" "missing subcommand for 'vbs daemon'" daemon)
|
||||
|
||||
# Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over
|
||||
|
||||
@@ -541,6 +541,61 @@ void build(Void::Build::Project &project) {
|
||||
Void::Testing::expect(std::filesystem::exists(compdb));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, ide_generate_writes_editor_configs) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
const auto options = make_options(temp->path());
|
||||
|
||||
{
|
||||
std::ofstream descriptor{options.project_root / "build.cpp"};
|
||||
descriptor << R"cpp(#include <Void/Build.hpp>
|
||||
|
||||
void build(Void::Build::Project &project) {
|
||||
auto app = project.executable("app");
|
||||
app.sources({"main.cpp"});
|
||||
}
|
||||
)cpp";
|
||||
Void::Testing::require(descriptor.good());
|
||||
}
|
||||
{
|
||||
std::ofstream source{options.project_root / "main.cpp"};
|
||||
source << "int main() { return 0; }\n";
|
||||
Void::Testing::require(source.good());
|
||||
}
|
||||
|
||||
auto server = Void::Build::Daemon::DaemonServer::create(options);
|
||||
Void::Testing::require(server.has_value());
|
||||
const auto socket = server->socket_path();
|
||||
|
||||
Void::Result::Result<void, Void::Result::Error> run_result;
|
||||
std::jthread worker{[&] { run_result = server->run(); }};
|
||||
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
|
||||
|
||||
auto invalid = request_object(socket, R"({"op":"ide_generate","editor":"bogus"})",
|
||||
std::chrono::seconds{120});
|
||||
Void::Testing::require(invalid.has_value());
|
||||
Void::Testing::expect(!bool_field(*invalid, "ok", true));
|
||||
|
||||
auto raw = Void::Build::Daemon::request(
|
||||
socket, R"({"op":"ide_generate","editor":"clangd","force":true})",
|
||||
std::chrono::seconds{120});
|
||||
auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})");
|
||||
Void::Testing::expect(shutdown.has_value());
|
||||
worker.join();
|
||||
Void::Testing::expect(run_result.has_value());
|
||||
|
||||
Void::Testing::require(raw.has_value());
|
||||
const auto parsed = parse_json(*raw);
|
||||
Void::Testing::require(parsed.has_value());
|
||||
const auto *object = as_object(*parsed);
|
||||
Void::Testing::require(object != nullptr);
|
||||
Void::Testing::expect(bool_field(*object, "ok"));
|
||||
Void::Testing::expect_eq(str_field(*object, "op"), std::string{"ide_generate"});
|
||||
Void::Testing::expect_eq(str_field(*object, "editor"), std::string{"clangd"});
|
||||
Void::Testing::expect(!string_array_field(*object, "written").empty());
|
||||
Void::Testing::expect(std::filesystem::exists(options.project_root / ".clangd"));
|
||||
}
|
||||
|
||||
VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) {
|
||||
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
|
||||
Void::Testing::require(temp.has_value());
|
||||
|
||||
Reference in new issue
Block a user