|
6 | 6 | #include "clModuleLogger.hpp" |
7 | 7 | #include "codelite_exports.h" |
8 | 8 |
|
| 9 | +#include <optional> |
9 | 10 | #include <vector> |
10 | 11 |
|
11 | 12 | // Helper macros to be used outside of this library |
@@ -657,6 +658,53 @@ class WXDLLIMPEXP_CL SymbolInformation : public Serializable |
657 | 658 | const wxString& container_name = wxEmptyString); |
658 | 659 | }; |
659 | 660 |
|
| 661 | +enum class ProgressKind { |
| 662 | + begin, |
| 663 | + report, |
| 664 | + end, |
| 665 | +}; |
| 666 | + |
| 667 | +struct WXDLLIMPEXP_CL Progress { |
| 668 | + wxString m_token; |
| 669 | + wxString m_message; |
| 670 | + ProgressKind m_kind{ProgressKind::begin}; |
| 671 | + double m_percentage{0.0}; |
| 672 | + /** |
| 673 | + * @brief Creates a Progress object from a JSON representation. |
| 674 | + * |
| 675 | + * @details Parses the expected "params.value" structure from the given JSON object and |
| 676 | + * returns a populated Progress instance when the required fields are present and the |
| 677 | + * "kind" value is one of the supported progress kinds. If any required field is missing |
| 678 | + * or the kind is unrecognized, the function returns std::nullopt. |
| 679 | + * |
| 680 | + * @param json const JSONItem& The JSON object to parse, expected to contain "params", |
| 681 | + * "params.value", "params.value.kind", "params.value.message", |
| 682 | + * "params.value.percentage", and "params.token" fields. |
| 683 | + * |
| 684 | + * @return std::optional<Progress> A populated Progress object on success, or std::nullopt |
| 685 | + * if the JSON does not match the expected format. |
| 686 | + */ |
| 687 | + static std::optional<Progress> FromJSON(const JSONItem& json); |
| 688 | + /** |
| 689 | + * @brief Formats the progress state into a human-readable message string. |
| 690 | + * |
| 691 | + * Builds a message from the current token and message text, and appends the |
| 692 | + * percentage when this progress entry represents a report. This method does not |
| 693 | + * modify the object state. |
| 694 | + * |
| 695 | + * @return wxString The formatted message string. |
| 696 | + */ |
| 697 | + inline wxString GetMessage() const |
| 698 | + { |
| 699 | + wxString message; |
| 700 | + message << "(" << m_token << ") " << m_message; |
| 701 | + if (m_kind == LSP::ProgressKind::report) { |
| 702 | + message << ". Progress: " << m_percentage << "%"; |
| 703 | + } |
| 704 | + return message; |
| 705 | + } |
| 706 | +}; |
| 707 | + |
660 | 708 | /// Initialise the library |
661 | 709 | WXDLLIMPEXP_CL void Initialise(); |
662 | 710 |
|
|
0 commit comments