#ifndef ANGELSCRIPTDEBUGGER_TYPES_HPP #define ANGELSCRIPTDEBUGGER_TYPES_HPP #include #include #include "Utils.hpp" namespace DebugAdapterProtocol { struct Source { std::optional name; std::optional path; std::optional sourceReference; Source() {} Source(std::string path) : path(path) {} explicit Source(nlohmann::json& j) { JsonDeserializeOptional(j, name); JsonDeserializeOptional(j, path); JsonDeserializeOptional(j, sourceReference); } [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o = nlohmann::json::object(); JsonSerializeOptional(o, name); JsonSerializeOptional(o, path); JsonSerializeOptional(o, sourceReference); return o; } }; struct Breakpoint { std::optional id; bool verified; std::optional message; std::optional source; std::optional line; std::optional column; std::optional endLine; std::optional endColumn; std::optional instructionReference; std::optional offset; Breakpoint(size_t id, Source& s, size_t line) : id(id), verified(true), source(s), line(line) {} [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; JsonSerializeOptional(o, id); o["verified"] = verified; JsonSerializeOptional(o, message); if (source.has_value()) { o["source"] = source.value().ToJson(); } JsonSerializeOptional(o, line); JsonSerializeOptional(o, column); JsonSerializeOptional(o, endLine); JsonSerializeOptional(o, endColumn); JsonSerializeOptional(o, instructionReference); JsonSerializeOptional(o, offset); return o; } }; struct BreakpointLocation { size_t line; std::optional column; std::optional endLine; std::optional endColumn; }; struct SourceBreakpoint { size_t line; std::optional column; std::optional condition; std::optional hitCondition; std::optional logMessage; SourceBreakpoint(nlohmann::json j) { line = j["line"]; JsonDeserializeOptional(j, column); JsonDeserializeOptional(j, condition); JsonDeserializeOptional(j, hitCondition); JsonDeserializeOptional(j, logMessage); } [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["line"] = line; JsonSerializeOptional(o, column); JsonSerializeOptional(o, condition); JsonSerializeOptional(o, hitCondition); JsonSerializeOptional(o, logMessage); return o; } }; struct Module { std::string id; std::string name; std::optional path; std::optional isOptimized; std::optional isUserCode; std::optional version; std::optional symbolStatus; std::optional symbolFilePath; std::optional dateTimeStamp; std::optional addressRange; [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["id"] = id; o["name"] = name; JsonSerializeOptional(o, path); JsonSerializeOptional(o, isOptimized); JsonSerializeOptional(o, isUserCode); JsonSerializeOptional(o, version); JsonSerializeOptional(o, symbolStatus); JsonSerializeOptional(o, symbolFilePath); JsonSerializeOptional(o, dateTimeStamp); JsonSerializeOptional(o, addressRange); return o; } }; struct Thread { size_t id; std::string name; Thread(size_t id, std::string name) : id(id), name(name) {} [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["id"] = id; o["name"] = name; return o; } }; struct StackFrame { size_t id; std::string name; std::optional source; size_t line; size_t column; std::optional endLine; std::optional endColumn; std::optional canRestart = false; std::optional instructionPointerReference; StackFrame(){}; StackFrame(size_t id, std::string name, Source source, size_t line, size_t column) : id(id), name(name), source(source), line(line), column(column) {} [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["id"] = id; o["name"] = name; if (source.has_value()) { o["source"] = source.value().ToJson(); } o["line"] = line; o["column"] = column; JsonSerializeOptional(o, endLine); JsonSerializeOptional(o, endColumn); JsonSerializeOptional(o, canRestart); JsonSerializeOptional(o, instructionPointerReference); return o; } }; struct Scope { std::string name; std::optional presentationHint; size_t variablesReference; size_t namedVariables; size_t indexedVariables = 0; bool expensive = false; std::optional source; std::optional line; std::optional column; std::optional endLine; std::optional endColumn; Scope(std::string name, size_t reference, std::string presentationHint, size_t namedVariables) : name(std::move(name)), presentationHint(std::move(presentationHint)), variablesReference(reference), namedVariables(namedVariables) {} [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["name"] = name; JsonSerializeOptional(o, presentationHint); o["variablesReference"] = variablesReference; o["namedVariables"] = namedVariables; o["indexedVariables"] = indexedVariables; o["expensive"] = expensive; if (source.has_value()) { o["source"] = source.value().ToJson(); } JsonSerializeOptional(o, line); JsonSerializeOptional(o, column); JsonSerializeOptional(o, endLine); JsonSerializeOptional(o, endColumn); return o; } }; struct VariablePresentationHint { std::optional kind; std::optional> attributes; std::optional visibility; [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; JsonSerializeOptional(o, kind); JsonSerializeOptional(o, attributes); JsonSerializeOptional(o, visibility); return o; } }; struct Variable { std::string name; std::string value; std::optional type; std::optional presentationHint; std::optional evaluateName; std::optional variablesReference = 0; std::optional namedVariables = 0; std::optional indexedVariables = 0; std::optional memoryReference; [[nodiscard]] nlohmann::json ToJson() const { nlohmann::json o; o["name"] = name; o["value"] = value; JsonSerializeOptional(o, type); if (presentationHint.has_value()) { o["presentationHint"] = presentationHint.value().ToJson(); } JsonSerializeOptional(o, evaluateName); JsonSerializeOptional(o, variablesReference); JsonSerializeOptional(o, namedVariables); JsonSerializeOptional(o, indexedVariables); JsonSerializeOptional(o, memoryReference); return o; } Variable(std::string name, std::string value, std::string type, std::optional presentationHint = {}) : name(std::move(name)), value(std::move(value)), type(std::move(type)), presentationHint(presentationHint) {} static Variable FromString(std::string name, std::string value) { return Variable(name, value, "string", VariablePresentationHint{ .kind = "data", .attributes = std::vector{"rawString"}, .visibility = {}}); } static Variable FromNull(std::string name, std::string type) { return Variable( name, "null", type, VariablePresentationHint{.kind = "data", .attributes = std::vector{}, .visibility = {}}); } static Variable FromPointer(std::string name, std::string type, std::string display, size_t variableReference) { auto v = Variable(std::move(name), std::move(display), type, VariablePresentationHint{ .kind = "class", .attributes = std::vector{"hasObjectId"}, .visibility = {}}); v.variablesReference = variableReference; return v; } }; } #endif // ANGELSCRIPTDEBUGGER_TYPES_HPP