diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 240b7cb..0169986 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -22,5 +22,5 @@ jobs: run: cmake --build "$BUILD_DIR" --config $CMAKE_BUILD_TYPE - name: Test - working-directory: ${{github.workspace}}/build + working-directory: ${{env.BUILD_DIR}} run: ctest --config $CMAKE_BUILD_TYPE --output-on-failure diff --git a/cmake/nlohmann.cmake b/cmake/nlohmann.cmake index ab38701..7254a7e 100644 --- a/cmake/nlohmann.cmake +++ b/cmake/nlohmann.cmake @@ -4,4 +4,10 @@ FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz DOWNLOAD_EXTRACT_TIMESTAMP ON ) -FetchContent_MakeAvailable(json) + +# Manually make available so we can mark library as SYSTEM headers thus disabling warnings +FetchContent_GetProperties(json) +if(NOT json_POPULATED) + FetchContent_Populate(json) + add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} SYSTEM) +endif() \ No newline at end of file diff --git a/include/uls/server.h b/include/uls/server.h index 78f2653..f7efe57 100644 --- a/include/uls/server.h +++ b/include/uls/server.h @@ -29,6 +29,7 @@ class Server bool is_running{false}; void send(const std::string& message_type, const nlohmann::json& message); + void send_error(const nlohmann::json& message); public: Server(IOStream io): io(std::move(io)) {} @@ -58,7 +59,7 @@ class Server void send_notification(const std::string& type, Data&& element) { auto message = Serializer>::serialize(std::forward(element)); - send(type, message); + send("notif/" + type, message); } void start(); diff --git a/src/highlight.cpp b/src/highlight.cpp index 0fbbd1f..aac68e9 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -50,11 +50,11 @@ void Highlight::configure(Server& server) repository.add_on_document_update([this, &server](UTAP::Document& doc) { auto keywords = keywords_for_path(doc, repository.get_current_xpath()); - server.send_notification("notif/keywords", keywords); + server.send_notification("keywords", keywords); }); repository.add_on_current_node_changed([this, &server](const std::string& xpath) { auto keywords = keywords_for_path(repository.get_document(), xpath); - server.send_notification("notif/keywords", keywords); + server.send_notification("keywords", keywords); }); } \ No newline at end of file diff --git a/src/server.cpp b/src/server.cpp index b09d984..794028b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -9,8 +9,8 @@ namespace views = std::ranges::views; using namespace std::chrono_literals; using json = nlohmann::json; -nlohmann::json OK_RESPONSE = {{"res", "OK"}}; -nlohmann::json FAIL_RESPONSE = {{"res", "FAIL"}}; +nlohmann::json OK_RESPONSE = {"OK"}; +nlohmann::json FAIL_RESPONSE = {"FAIL"}; std::vector::const_iterator find_command(const std::vector& commands, const std::string& name) { @@ -34,10 +34,10 @@ void Server::start() auto response = cmd->callback(message["args"]); send("response/" + cmd->name, response); } catch (nlohmann::json::parse_error& e) { - send("error", e.what()); + send_error(e.what()); stop(); } catch (std::exception& e) { - send("error", e.what()); + send_error(e.what()); } } } @@ -53,7 +53,12 @@ Server& Server::add_close_command(std::string name) void Server::send(const std::string& message_type, const nlohmann::json& message) { - io.out << json{{"type", message_type}, {"msg", message}} << std::endl; + io.out << json{{"res", message_type}, {"info", message}} << std::endl; +} + +void Server::send_error(const nlohmann::json& message) +{ + send("err", message); } void Server::stop() { is_running = false; } diff --git a/test/server_mock.h b/test/server_mock.h index 8291458..7b22400 100644 --- a/test/server_mock.h +++ b/test/server_mock.h @@ -26,14 +26,14 @@ struct MockIO : IOStream { nlohmann::json message; out_buf >> message; - return message["msg"]; + return message["info"]; } bool expect_error() { nlohmann::json message; out_buf >> message; - return message["type"] == "error"; + return message["type"] == "err"; } bool out_eof() { return out_buf.eof(); }