Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AutoSave/AutoSaveSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void AutoSaveSettings::FromJSON(const JSONItem& json)

JSONItem AutoSaveSettings::ToJSON() const
{
JSONItem json = JSONItem::createObject(GetName());
JSONItem json = JSONItem::createObject();
json.addProperty("m_flags", m_flags);
json.addProperty("m_checkInterval", m_checkInterval);
return json;
Expand Down
2 changes: 1 addition & 1 deletion CodeFormatter/SourceFormatterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void SourceFormatterBase::FromJSON(const JSONItem& json)

JSONItem SourceFormatterBase::ToJSON() const
{
JSONItem ele = JSONItem::createObject(GetName());
JSONItem ele = JSONItem::createObject();
ele.addProperty("languages", m_languages);
ele.addProperty("flags", m_flags);
ele.addProperty("config_file", m_configFile);
Expand Down
90 changes: 8 additions & 82 deletions CodeLite/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ cJSON* JSON::release()
JSONItem::JSONItem(cJSON* json)
: m_json(json)
{
if (m_json) {
m_propertyName = m_json->string ? m_json->string : "";
m_type = m_json->type;
}
}

JSONItem JSONItem::operator[](int index) const
Expand Down Expand Up @@ -244,42 +240,6 @@ bool JSONItem::isString() const
return m_json->type == cJSON_String;
}

void JSONItem::append(const JSONItem& element)
{
if (!m_json) {
return;
}

switch (element.getType()) {
case cJSON_False:
cJSON_AddFalseToObject(m_json, element.GetPropertyName().mb_str(wxConvUTF8).data());
break;

case cJSON_True:
cJSON_AddTrueToObject(m_json, element.GetPropertyName().mb_str(wxConvUTF8).data());
break;

case cJSON_NULL:
cJSON_AddNullToObject(m_json, element.GetPropertyName().mb_str(wxConvUTF8).data());
break;

case cJSON_Number:
cJSON_AddNumberToObject(m_json, element.GetPropertyName().mb_str(wxConvUTF8).data(), element.m_valueNumer);
break;

case cJSON_String:
cJSON_AddStringToObject(m_json,
element.GetPropertyName().mb_str(wxConvUTF8).data(),
element.m_valueString.mb_str(wxConvUTF8).data());
break;

case cJSON_Array:
case cJSON_Object:
cJSON_AddItemToObject(m_json, element.GetPropertyName().mb_str(wxConvUTF8).data(), element.m_json);
break;
}
}

void JSONItem::arrayAppend(const char* value)
{
if (!m_json) {
Expand All @@ -304,55 +264,25 @@ void JSONItem::arrayAppend(int number) { arrayAppend((double)number); }

void JSONItem::arrayAppend(const wxString& value) { arrayAppend((const char*)value.mb_str(wxConvUTF8).data()); }

void JSONItem::arrayAppend(const JSONItem& element)
void JSONItem::arrayAppend(JSONItem&& element)
{
if (!m_json) {
return;
}

cJSON* p = NULL;
switch (element.getType()) {
case cJSON_False:
p = cJSON_CreateFalse();
break;

case cJSON_True:
p = cJSON_CreateTrue();
break;

case cJSON_NULL:
p = cJSON_CreateNull();
break;

case cJSON_Number:
p = cJSON_CreateNumber(element.m_valueNumer);
break;

case cJSON_String:
p = cJSON_CreateString(element.m_valueString.mb_str(wxConvUTF8).data());
break;
case cJSON_Array:
case cJSON_Object:
p = element.m_json;
break;
}
if (p) {
cJSON_AddItemToArray(m_json, p);
if (element.m_json) {
cJSON_AddItemToArray(m_json, element.m_json);
}
}

JSONItem JSONItem::createArray()
{
JSONItem arr(cJSON_CreateArray());
arr.setType(cJSON_Array);
return arr;
}

JSONItem JSONItem::createObject(const wxString& name)
JSONItem JSONItem::createObject()
{
JSONItem obj(cJSON_CreateObject());
obj.SetPropertyName(name);
obj.setType(cJSON_Object);
return obj;
}

Expand Down Expand Up @@ -598,7 +528,7 @@ JSONItem& JSONItem::addProperty(const wxString& name, const wxStringMap_t& strin
JSONItem obj = JSONItem::createObject();
obj.addProperty("key", key);
obj.addProperty("value", value);
arr.arrayAppend(obj);
arr.arrayAppend(std::move(obj));
}
addProperty(name, arr);
return *this;
Expand Down Expand Up @@ -691,8 +621,8 @@ JSONItem JSONItem::AddArray(const wxString& name)

JSONItem JSONItem::AddObject(const wxString& name)
{
JSONItem json = createObject(name);
append(json);
JSONItem json = createObject();
addProperty(name, json);
return json;
}

Expand Down Expand Up @@ -757,11 +687,7 @@ std::vector<int> JSONItem::toIntArray(const std::vector<int>& defaultValue) cons

JSONItem& JSONItem::addProperty(const wxString& name, const std::vector<int>& arr_int)
{
if (!m_json) {
return *this;
}

if (m_type != cJSON_Object) {
if (!m_json || !isObject()) {
return *this;
}

Expand Down
28 changes: 6 additions & 22 deletions CodeLite/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class JSON;
class WXDLLIMPEXP_CL JSONItem
{
friend JSON;

public:
explicit JSONItem(cJSON* json);
JSONItem() = default;
Expand Down Expand Up @@ -144,10 +145,10 @@ class WXDLLIMPEXP_CL JSONItem
// Writers
////////////////////////////////////////////////
/**
* @brief create new named object and append it to this json element
* @brief create new object
* @return the newly created object
*/
static JSONItem createObject(const wxString& name = wxT(""));
static JSONItem createObject();
/**
* @brief create new array
* @return the newly created array
Expand All @@ -164,11 +165,6 @@ class WXDLLIMPEXP_CL JSONItem
*/
JSONItem AddObject(const wxString& name);

/**
* @brief append new element to this json element
*/
void append(const JSONItem& element);

JSONItem& addProperty(const wxString& name, const wxString& value);
JSONItem& addProperty(const wxString& name, const std::string& value);
JSONItem& addProperty(const wxString& name, const wxChar* value);
Expand Down Expand Up @@ -209,7 +205,7 @@ class WXDLLIMPEXP_CL JSONItem
* @brief append new number
* @return the newly added property
*/
void arrayAppend(const JSONItem& element);
void arrayAppend(JSONItem&& element);
void arrayAppend(const wxString& value);
void arrayAppend(const char* value);
void arrayAppend(const std::string& value);
Expand All @@ -219,12 +215,6 @@ class WXDLLIMPEXP_CL JSONItem
bool isOk() const { return m_json != NULL; }

private:

const wxString& GetPropertyName() const { return m_propertyName; }
void SetPropertyName(const wxString& name) { m_propertyName = name; }
int getType() const { return m_type; }
void setType(int m_type) { this->m_type = m_type; }

/**
* @brief release the internal pointer
*/
Expand All @@ -234,20 +224,14 @@ class WXDLLIMPEXP_CL JSONItem
m_json = nullptr;
return temp;
}

private:
cJSON* m_json = nullptr;
wxString m_propertyName;
int m_type = wxNOT_FOUND;

// Values
wxString m_valueString;
double m_valueNumer = 0;
};

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
enum class JsonType
{
enum class JsonType {
Array,
Null,
Object,
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/CodeActionRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LSP::CodeActionRequest::CodeActionRequest(const LSP::TextDocumentIdentifier& tex
m_params->As<CodeActionParams>()->SetTextDocument(textDocument);
m_params->As<CodeActionParams>()->SetRange(range);
m_params->As<CodeActionParams>()->SetDiagnostics(diags);
LSP_DEBUG() << ToJSON(wxEmptyString).format(true) << endl;
LSP_DEBUG() << ToJSON().format(true) << endl;
}

void LSP::CodeActionRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/CompletionItem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "CompletionItem.h"

JSONItem LSP::CompletionItem::ToJSON(const wxString& name) const { return JSONItem(NULL); }
JSONItem LSP::CompletionItem::ToJSON() const { return JSONItem(NULL); }

void LSP::CompletionItem::FromJSON(const JSONItem& json)
{
Expand Down
6 changes: 3 additions & 3 deletions CodeLite/LSP/CompletionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class WXDLLIMPEXP_CL CompletionItem : public Serializable

public:
CompletionItem() = default;
virtual ~CompletionItem() = default;
virtual JSONItem ToJSON(const wxString& name) const;
virtual void FromJSON(const JSONItem& json);
~CompletionItem() override = default;
JSONItem ToJSON() const override;
void FromJSON(const JSONItem& json) override;
void SetDetail(const wxString& detail) { this->m_detail = detail; }
void SetDocumentation(const MarkupContent& documentation) { this->m_documentation = documentation; }
void SetFilterText(const wxString& filterText) { this->m_filterText = filterText; }
Expand Down
4 changes: 2 additions & 2 deletions CodeLite/LSP/InitializeRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ LSP::InitializeRequest::InitializeRequest(bool withTokenTypes, const wxString& r
m_rootUri = rootUri;
}

JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
JSONItem LSP::InitializeRequest::ToJSON() const
{
JSONItem json = Request::ToJSON(name);
JSONItem json = Request::ToJSON();

// add the 'params'
JSONItem params = JSONItem::createObject();
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/InitializeRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class WXDLLIMPEXP_CL InitializeRequest : public LSP::Request
}
int GetProcessId() const { return m_processId; }
const wxString& GetRootUri() const { return m_rootUri; }
JSONItem ToJSON(const wxString& name) const override;
JSONItem ToJSON() const override;
void OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner) override;
bool IsPositionDependentRequest() const override { return false; }
void SetInitOptions(const wxString& initOptions) { this->m_initOptions = initOptions; }
Expand Down
5 changes: 2 additions & 3 deletions CodeLite/LSP/InitializedNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace LSP
{
struct InitializedParams : public Params {
JSONItem ToJSON(const wxString& name) const override
JSONItem ToJSON() const override
{
wxUnusedVar(name);
return JSONItem::createObject(name);
return JSONItem::createObject();
}

void FromJSON(const JSONItem& json) override { wxUnusedVar(json); };
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/JSONObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WXDLLIMPEXP_CL Serializable
public:
Serializable() = default;
virtual ~Serializable() = default;
virtual JSONItem ToJSON(const wxString& name) const = 0;
virtual JSONItem ToJSON() const = 0;
virtual void FromJSON(const JSONItem& json) = 0;

bool operator==(const Serializable&) const = default;
Expand Down
4 changes: 2 additions & 2 deletions CodeLite/LSP/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ int ReadHeaders(const std::string& message, std::unordered_map<std::string, std:

} // namespace

JSONItem LSP::Message::ToJSON(const wxString& name) const
JSONItem LSP::Message::ToJSON() const
{
JSONItem json = JSONItem::createObject(name);
JSONItem json = JSONItem::createObject();
json.addProperty("jsonrpc", m_jsonrpc);
return json;
}
Expand Down
6 changes: 3 additions & 3 deletions CodeLite/LSP/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class WXDLLIMPEXP_CL Message : public LSP::Serializable

public:
Message() = default;
virtual ~Message() = default;
virtual JSONItem ToJSON(const wxString& name) const;
virtual void FromJSON(const JSONItem& json);
~Message() override = default;
JSONItem ToJSON() const override;
void FromJSON(const JSONItem& json) override;

/**
* @brief serialize this message into string
Expand Down
8 changes: 4 additions & 4 deletions CodeLite/LSP/MessageWithParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <sstream>
#include <wx/string.h>

JSONItem LSP::MessageWithParams::ToJSON(const wxString& name) const
JSONItem LSP::MessageWithParams::ToJSON() const
{
JSONItem json = Message::ToJSON(name);
JSONItem json = Message::ToJSON();
json.addProperty("method", GetMethod());
if (m_params) {
json.addProperty("params", m_params->ToJSON("params"));
json.addProperty("params", m_params->ToJSON());
}
return json;
}
Expand All @@ -24,7 +24,7 @@ void LSP::MessageWithParams::FromJSON(const JSONItem& json)
std::string LSP::MessageWithParams::ToString() const
{
// Serialize the object and construct a JSON-RPC message
JSONItem json = ToJSON("");
JSONItem json = ToJSON();
char* data = json.FormatRawString(false);

std::string s;
Expand Down
8 changes: 4 additions & 4 deletions CodeLite/LSP/MessageWithParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class WXDLLIMPEXP_CL MessageWithParams : public LSP::Message

public:
MessageWithParams() = default;
virtual ~MessageWithParams() = default;
virtual JSONItem ToJSON(const wxString& name) const;
virtual void FromJSON(const JSONItem& json);
virtual std::string ToString() const;
~MessageWithParams() override = default;
JSONItem ToJSON() const override;
void FromJSON(const JSONItem& json) override;
std::string ToString() const override;

void SetMethod(const wxString& method) { this->m_method = method; }
const wxString& GetMethod() const { return m_method; }
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/RenameRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void LSP::RenameRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtH
for(const auto& [filepath, changes] : modifications) {
LSP_DEBUG() << " " << filepath << modifications.size() << "changes:" << endl;
for(const auto& change : changes) {
LSP_DEBUG() << " " << change.ToJSON(wxEmptyString).format(false) << endl;
LSP_DEBUG() << " " << change.ToJSON().format(false) << endl;
}
}
}
Expand Down
Loading
Loading