#ifndef ANGELSCRIPTDEBUGGER_EVENTS_HPP #define ANGELSCRIPTDEBUGGER_EVENTS_HPP #include "BaseProtocol.hpp" #include "Types.hpp" #include "Utils.hpp" namespace DebugAdapterProtocol { #define EventDefinition(name, jsonName, ...) \ static const char __c##name[] = jsonName; \ struct name##EventBody : public EventBody __VA_ARGS__; \ using name##Event = Event EventDefinition(Breakpoint, "breakpoint", { std::string reason; Breakpoint breakpoint; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["reason"] = reason; o["breakpoint"] = breakpoint.ToJson(); return o; } }); EventDefinition(Continued, "continued", { size_t threadId; std::optional allThreadsContinued; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["threadId"] = threadId; JsonSerializeOptional(o, allThreadsContinued); return o; } }); EventDefinition(Exited, "exited", { int64_t exitCode; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["exitCode"] = exitCode; return o; } }); EventDefinition(Initialized, "initialized", {}); EventDefinition(Invalidated, "invalidated", { std::optional> invalidatedAreas; std::optional threadId; std::optional stackFrameId; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); JsonSerializeOptional(o, invalidatedAreas); JsonSerializeOptional(o, threadId); JsonSerializeOptional(o, stackFrameId); return o; } }); EventDefinition(LoadedSource, "loadedSource", { std::string reason; Source source; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["reason"] = reason; o["source"] = source.ToJson(); return o; } }); EventDefinition(Memory, "memory", { std::string memoryReference; size_t offset; size_t count; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["memoryReference"] = memoryReference; o["offset"] = offset; o["count"] = count; return o; } }); EventDefinition(Module, "module", { std::string reason; Module module; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["reason"] = reason; o["module"] = module.ToJson(); return o; } }); EventDefinition(Output, "output", { std::optional category; std::string output; std::optional group; std::optional variablesReference; std::optional source; std::optional line; std::optional column; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); JsonSerializeOptional(o, category); o["output"] = output; JsonSerializeOptional(o, group); JsonSerializeOptional(o, variablesReference); if (source.has_value()) { o["source"] = source.value().ToJson(); } JsonSerializeOptional(o, line); JsonSerializeOptional(o, column); return o; } }); EventDefinition(Process, "process", { std::string name; std::optional systemProcessId; std::optional isLocalProcess; std::optional startMethod; std::optional pointerSize; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["name"] = name; JsonSerializeOptional(o, systemProcessId); JsonSerializeOptional(o, isLocalProcess); JsonSerializeOptional(o, startMethod); JsonSerializeOptional(o, pointerSize); return o; } }); EventDefinition(ProgressEnd, "progressEnd", { std::string progressId; std::optional message; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["progressId"] = progressId; JsonSerializeOptional(o, message); return o; } }); EventDefinition(ProgressStart, "progressStart", { std::string progressId; std::string title; std::optional requestId; std::optional cancellable; std::optional message; std::optional percentage; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["progressId"] = progressId; o["title"] = title; JsonSerializeOptional(o, requestId); JsonSerializeOptional(o, cancellable); JsonSerializeOptional(o, message); JsonSerializeOptional(o, percentage); return o; } }); EventDefinition(ProgressUpdate, "progressUpdate", { std::string progressId; std::optional message; std::optional percentage; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["progressId"] = progressId; JsonSerializeOptional(o, message); JsonSerializeOptional(o, percentage); return o; } }); EventDefinition(Stopped, "stopped", { std::string reason; std::optional description; std::optional threadId = 0; std::optional preserveFocusHint = false; std::optional text; std::optional allThreadsStopped = true; std::optional> hitBreakpointIds; explicit StoppedEventBody(std::string reason, size_t breakpoint) : reason(std::move(reason)), hitBreakpointIds(std::vector({breakpoint})) {} explicit StoppedEventBody(std::string reason, std::string description, std::string text) : reason(std::move(reason)), description(std::move(description)), text(std::move(text)) {} nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["reason"] = reason; JsonSerializeOptional(o, description); JsonSerializeOptional(o, threadId); JsonSerializeOptional(o, preserveFocusHint); JsonSerializeOptional(o, text); JsonSerializeOptional(o, allThreadsStopped); JsonSerializeOptional(o, hitBreakpointIds); return o; } }); EventDefinition(terminated, "terminated", {}); EventDefinition(Thread, "thread", { std::string reason; std::optional threadId; nlohmann::json ToJson() const override { auto o = EventBody::ToJson(); o["reason"] = reason; JsonSerializeOptional(o, threadId); return o; } }); } #endif // ANGELSCRIPTDEBUGGER_EVENTS_HPP