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
15 changes: 7 additions & 8 deletions CodeLite/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,9 @@ void JSONItem::arrayAppend(const JSONItem& element)
}
}

JSONItem JSONItem::createArray(const wxString& name)
JSONItem JSONItem::createArray()
{
JSONItem arr(cJSON_CreateArray());
arr.SetPropertyName(name);
arr.setType(cJSON_Array);
return arr;
}
Expand Down Expand Up @@ -501,11 +500,11 @@ JSONItem& JSONItem::addProperty(const wxString& name, long value)

JSONItem& JSONItem::addProperty(const wxString& name, const wxArrayString& arr)
{
JSONItem arrEle = JSONItem::createArray(name);
JSONItem arrEle = JSONItem::createArray();
for (const auto& s : arr) {
arrEle.arrayAppend(s);
}
append(arrEle);
addProperty(name, arrEle);
return *this;
}

Expand Down Expand Up @@ -621,14 +620,14 @@ JSONItem& JSONItem::addProperty(const wxString& name, const wxStringMap_t& strin
if (!m_json)
return *this;

JSONItem arr = JSONItem::createArray(name);
JSONItem arr = JSONItem::createArray();
for (const auto& [key, value] : stringMap) {
JSONItem obj = JSONItem::createObject();
obj.addProperty("key", key);
obj.addProperty("value", value);
arr.arrayAppend(obj);
}
append(arr);
addProperty(name, arr);
return *this;
}
#endif
Expand Down Expand Up @@ -753,8 +752,8 @@ JSONItem& JSONItem::addProperty(const wxString& name, const wxFileName& filename

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

Expand Down
4 changes: 2 additions & 2 deletions CodeLite/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ class WXDLLIMPEXP_CL JSONItem
*/
static JSONItem createObject(const wxString& name = wxT(""));
/**
* @brief create new named array and append it to this json element
* @brief create new array
* @return the newly created array
*/
static JSONItem createArray(const wxString& name = wxT(""));
static JSONItem createArray();

/**
* @brief add array to this json and return a reference to the newly added array
Expand Down
5 changes: 3 additions & 2 deletions CodeLite/LSP/InitializeRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
JSONItem json = Request::ToJSON(name);

// add the 'params'
JSONItem params = JSONItem::createObject("params");
json.append(params);
JSONItem params = JSONItem::createObject();
params.addProperty("processId", GetProcessId());
if (GetRootUri().IsEmpty()) {
JSON nullItem(JsonType::Null);
Expand Down Expand Up @@ -79,6 +78,8 @@ JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const
tokenModifiers.arrayAppend("documentation");
tokenModifiers.arrayAppend("defaultLibrary");
}

json.addProperty("params", params);
return json;
}

Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/MessageWithParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ JSONItem LSP::MessageWithParams::ToJSON(const wxString& name) const
JSONItem json = Message::ToJSON(name);
json.addProperty("method", GetMethod());
if (m_params) {
json.append(m_params->ToJSON("params"));
json.addProperty("params", m_params->ToJSON("params"));
}
return json;
}
Expand Down
26 changes: 13 additions & 13 deletions CodeLite/LSP/basic_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ JSONItem TextDocumentContentChangeEvent::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
if(m_range.IsOk()) {
json.append(m_range.ToJSON("range"));
json.addProperty("range", m_range.ToJSON("range"));
}
json.addProperty("text", m_text);
return json;
Expand All @@ -133,8 +133,8 @@ void Range::FromJSON(const JSONItem& json)
JSONItem Range::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_start.ToJSON("start"));
json.append(m_end.ToJSON("end"));
json.addProperty("start", m_start.ToJSON("start"));
json.addProperty("end", m_end.ToJSON("end"));
return json;
}

Expand All @@ -150,7 +150,7 @@ JSONItem Location::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.addProperty("uri", GetPathAsURI());
json.append(m_range.ToJSON("range"));
json.addProperty("range", m_range.ToJSON("range"));
json.addProperty("pattern", m_pattern);
json.addProperty("name", m_name);
return json;
Expand All @@ -166,7 +166,7 @@ JSONItem TextEdit::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.addProperty("newText", m_newText);
json.append(m_range.ToJSON("range"));
json.addProperty("range", m_range.ToJSON("range"));
return json;
}

Expand Down Expand Up @@ -209,11 +209,11 @@ JSONItem SignatureInformation::ToJSON(const wxString& name) const
json.addProperty("label", m_label);
json.addProperty("documentation", m_documentation);
if(!m_parameters.empty()) {
JSONItem params = JSONItem::createArray("parameters");
json.append(params);
JSONItem params = JSONItem::createArray();
for (const auto& paramInfo : m_parameters) {
params.append(paramInfo.ToJSON(""));
}
json.addProperty("parameters", params);
}
return json;
}
Expand All @@ -237,11 +237,11 @@ void SignatureHelp::FromJSON(const JSONItem& json)
JSONItem SignatureHelp::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
JSONItem signatures = JSONItem::createArray("signatures");
json.append(signatures);
JSONItem signatures = JSONItem::createArray();
for(const SignatureInformation& si : m_signatures) {
signatures.arrayAppend(si.ToJSON(""));
}
json.addProperty("signatures", signatures);
json.addProperty("activeSignature", m_activeSignature);
json.addProperty("activeParameter", m_activeParameter);
return json;
Expand Down Expand Up @@ -270,8 +270,8 @@ void Hover::FromJSON(const JSONItem& json)
JSONItem Hover::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_contents.ToJSON("contents"));
json.append(m_range.ToJSON("range"));
json.addProperty("contents", m_contents.ToJSON("contents"));
json.addProperty("range", m_range.ToJSON("range"));
return json;
}

Expand All @@ -288,7 +288,7 @@ void Diagnostic::FromJSON(const JSONItem& json)
JSONItem Diagnostic::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_range.ToJSON("range"));
json.addProperty("range", m_range.ToJSON("range"));
json.addProperty("message", GetMessage());
json.addProperty("severity", (int)m_severity);
return json;
Expand Down Expand Up @@ -361,7 +361,7 @@ JSONItem SymbolInformation::ToJSON(const wxString& name) const
JSONItem json = JSONItem::createObject(name);
json.addProperty("kind", (int)kind);
json.addProperty("containerName", containerName);
json.append(location.ToJSON("location"));
json.addProperty("location", location.ToJSON("location"));
json.addProperty("name", this->name);
return json;
}
Expand Down
24 changes: 12 additions & 12 deletions CodeLite/LSP/json_rpc_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void TextDocumentPositionParams::FromJSON(const JSONItem& json)
JSONItem TextDocumentPositionParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.append(m_position.ToJSON("position"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
json.addProperty("position", m_position.ToJSON("position"));
return json;
}

Expand All @@ -29,7 +29,7 @@ void SemanticTokensParams::FromJSON(const JSONItem& json) { m_textDocument.FromJ
JSONItem SemanticTokensParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
return json;
}

Expand All @@ -42,7 +42,7 @@ void DidOpenTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument.
JSONItem DidOpenTextDocumentParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
return json;
}

Expand All @@ -55,7 +55,7 @@ void DidCloseTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument
JSONItem DidCloseTextDocumentParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
return json;
}

Expand All @@ -81,12 +81,12 @@ void DidChangeTextDocumentParams::FromJSON(const JSONItem& json)
JSONItem DidChangeTextDocumentParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
JSONItem arr = JSONItem::createArray("contentChanges");
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
JSONItem arr = JSONItem::createArray();
for (const auto& contentChange : m_contentChanges) {
arr.arrayAppend(contentChange.ToJSON(""));
}
json.append(arr);
json.addProperty("contentChanges", arr);
return json;
}

Expand All @@ -103,7 +103,7 @@ void DidSaveTextDocumentParams::FromJSON(const JSONItem& json)
JSONItem DidSaveTextDocumentParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
json.addProperty("text", m_text);
return json;
}
Expand Down Expand Up @@ -153,8 +153,8 @@ void CodeActionParams::FromJSON(const JSONItem& json) { wxUnusedVar(json); }
JSONItem CodeActionParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.append(m_range.ToJSON("range"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
json.addProperty("range", m_range.ToJSON("range"));

// add empty context
auto context = json.AddObject("context");
Expand All @@ -174,7 +174,7 @@ void DocumentSymbolParams::FromJSON(const JSONItem& json) { m_textDocument.FromJ
JSONItem DocumentSymbolParams::ToJSON(const wxString& name) const
{
JSONItem json = JSONItem::createObject(name);
json.append(m_textDocument.ToJSON("textDocument"));
json.addProperty("textDocument", m_textDocument.ToJSON("textDocument"));
return json;
}

Expand Down
44 changes: 18 additions & 26 deletions CodeLite/cl_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
#include <wx/filefn.h>
#include <wx/filename.h>

#define ADD_OBJ_IF_NOT_EXISTS(parent, objName) \
if (!parent.hasNamedObject(objName)) { \
JSONItem obj = JSONItem::createObject(objName); \
parent.append(obj); \
#define ADD_OBJ_IF_NOT_EXISTS(parent, objName) \
if (!(parent).hasNamedObject((objName))) { \
JSONItem obj = JSONItem::createObject(); \
(parent).addProperty((objName), obj); \
}

#define ADD_ARR_IF_NOT_EXISTS(parent, arrName) \
if (!parent.hasNamedObject(arrName)) { \
JSONItem arr = JSONItem::createArray(arrName); \
parent.append(arr); \
#define ADD_ARR_IF_NOT_EXISTS(parent, arrName) \
if (!(parent).hasNamedObject((arrName))) { \
JSONItem arr = JSONItem::createArray(); \
(parent).addProperty((arrName), arr); \
}

namespace
Expand Down Expand Up @@ -115,10 +115,10 @@ void clConfig::SetOutputTabOrder(const wxArrayString& tabs, int selected)
DoDeleteProperty("outputTabOrder");

// first time
JSONItem e = JSONItem::createObject("outputTabOrder");
JSONItem e = JSONItem::createObject();
e.addProperty("tabs", tabs);
e.addProperty("selected", selected);
m_root->toElement().append(e);
m_root->toElement().addProperty("outputTabOrder", e);
m_root->save(m_filename);
}

Expand All @@ -138,10 +138,10 @@ void clConfig::SetWorkspaceTabOrder(const wxArrayString& tabs, int selected)
DoDeleteProperty("workspaceTabOrder");

// first time
JSONItem e = JSONItem::createObject("workspaceTabOrder");
JSONItem e = JSONItem::createObject();
e.addProperty("tabs", tabs);
e.addProperty("selected", selected);
m_root->toElement().append(e);
m_root->toElement().addProperty("workspaceTabOrder", e);

m_root->save(m_filename);
}
Expand Down Expand Up @@ -173,8 +173,7 @@ bool clConfig::Write(const wxString& name, std::function<JSONItem()> serialiser_
} else {
// add it to the global configuration file
DoDeleteProperty(name);
item.SetPropertyName(name);
m_root->toElement().append(item);
m_root->toElement().addProperty(name, item);
return true;
}
}
Expand Down Expand Up @@ -263,10 +262,7 @@ void clConfig::Save(const wxFileName& fn)

JSONItem clConfig::GetGeneralSetting()
{
if (!m_root->toElement().hasNamedObject("General")) {
JSONItem general = JSONItem::createObject("General");
m_root->toElement().append(general);
}
ADD_OBJ_IF_NOT_EXISTS(m_root->toElement(), "General")
return m_root->toElement().namedObject("General");
}

Expand Down Expand Up @@ -342,10 +338,7 @@ int clConfig::GetAnnoyingDlgAnswer(const wxString& name, int defaultValue)

void clConfig::SetAnnoyingDlgAnswer(const wxString& name, int value)
{
if (!m_root->toElement().hasNamedObject("AnnoyingDialogsAnswers")) {
JSONItem element = JSONItem::createObject("AnnoyingDialogsAnswers");
m_root->toElement().append(element);
}
ADD_OBJ_IF_NOT_EXISTS(m_root->toElement(), "AnnoyingDialogsAnswers")

JSONItem element = m_root->toElement().namedObject("AnnoyingDialogsAnswers");
if (element.hasNamedObject(name)) {
Expand Down Expand Up @@ -524,14 +517,13 @@ wxFont clConfig::Read(const wxString& name, const wxFont& defaultValue)

void clConfig::Write(const wxString& name, const wxFont& value)
{
JSONItem font = JSONItem::createObject(name);
font.addProperty("fontDesc", FontUtils::GetFontInfo(value));

JSONItem general = GetGeneralSetting();
if (general.hasNamedObject(name)) {
general.removeProperty(name);
}
general.append(font);
JSONItem font = JSONItem::createObject();
font.addProperty("fontDesc", FontUtils::GetFontInfo(value));
general.addProperty(name, font);
Save();
}

Expand Down
4 changes: 2 additions & 2 deletions DatabaseExplorer/db_explorer_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ JSONItem DbExplorerSettings::ToJSON() const
element.addProperty("m_sqlHistory", m_sqlHistory);

// add the connections array
JSONItem arrConnections = JSONItem::createArray("connections");
element.append(arrConnections);
JSONItem arrConnections = JSONItem::createArray();
for (const auto& connection : m_connections) {
arrConnections.arrayAppend(connection.ToJSON());
}
element.addProperty("connections", arrConnections);
return element;
}

Expand Down
Loading
Loading