Skip to content
Open
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 CodeLite/LSP/CodeActionRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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().format(true) << endl;
LSP_DEBUG() << wxString::FromUTF8(ToJSON().dump(2)) << endl;
}

std::optional<LSPEvent> 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 { return JSONItem(nullptr); }
nlohmann::json LSP::CompletionItem::ToJSON() const { return nullptr; }

void LSP::CompletionItem::FromJSON(const JSONItem& json)
{
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/CompletionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WXDLLIMPEXP_CL CompletionItem : public Serializable
public:
CompletionItem() = default;
~CompletionItem() override = default;
JSONItem ToJSON() const override;
nlohmann::json 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; }
Expand Down
83 changes: 29 additions & 54 deletions CodeLite/LSP/InitializeRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,51 @@ LSP::InitializeRequest::InitializeRequest(bool withTokenTypes, const wxString& r
m_rootUri = rootUri;
}

JSONItem LSP::InitializeRequest::ToJSON() const
nlohmann::json LSP::InitializeRequest::ToJSON() const
{
JSONItem json = Request::ToJSON();
auto json = Request::ToJSON();

// add the 'params'
JSONItem params = JSONItem::createObject();
params.addProperty("processId", GetProcessId());
nlohmann::json params = nlohmann::json::object();
params["processId"] = GetProcessId();
if (!GetRootUri().IsEmpty()) {
params.addProperty("rootUri", LSP::FileNameToURI(GetRootUri()));
params["rootUri"] = LSP::FileNameToURI(GetRootUri()).ToStdString(wxConvUTF8);
}

if (!m_initOptions.empty()) {
// Parse the JSON string and set it as the 'initializationOptions
JSON initializationOptions(m_initOptions);
if (initializationOptions.isOk()) {
params.addProperty(wxString("initializationOptions"), std::move(initializationOptions));
auto initializationOptions =
nlohmann::ordered_json::parse(m_initOptions.mb_str(wxConvUTF8).data(), nullptr, false);
if (!initializationOptions.is_discarded()) {
params["initializationOptions"] = std::move(initializationOptions);
}
}

auto capabilities = params.AddObject("capabilities");
auto windowCapabilities = capabilities.AddObject("window");
windowCapabilities.addProperty("workDoneProgress", true);
auto& capabilities = params["capabilities"] = nlohmann::json::object();
capabilities["window"] = nlohmann::json{{"workDoneProgress", true}};

auto textDocumentCapabilities = capabilities.AddObject("textDocument");
auto docFormat =
textDocumentCapabilities.AddObject("completion").AddObject("completionItem").AddArray("documentationFormat");
docFormat.arrayAppend("plaintext");
auto hoverFormat = textDocumentCapabilities.AddObject("hover").AddArray("contentFormat");
hoverFormat.arrayAppend("markdown");
hoverFormat.arrayAppend("plaintext");
auto& textDocumentCapabilities = capabilities["textDocument"];
textDocumentCapabilities["completion"]["completionItem"]["documentationFormat"] = std::array{"plaintext"};
textDocumentCapabilities["hover"]["contentFormat"] = {"markdown", "plaintext"};

if (m_withTokenTypes) {
auto sematicTokens = textDocumentCapabilities.AddObject("semanticTokens");
auto tokenTypes = sematicTokens.AddArray("tokenTypes");
tokenTypes.arrayAppend("type");
tokenTypes.arrayAppend("class");
tokenTypes.arrayAppend("enum");
tokenTypes.arrayAppend("interface");
tokenTypes.arrayAppend("struct");
tokenTypes.arrayAppend("typeParameter");
tokenTypes.arrayAppend("parameter");
tokenTypes.arrayAppend("variable");
tokenTypes.arrayAppend("property");
tokenTypes.arrayAppend("enumMember");
tokenTypes.arrayAppend("event");
tokenTypes.arrayAppend("function");
tokenTypes.arrayAppend("method");
tokenTypes.arrayAppend("macro");
tokenTypes.arrayAppend("keyword");
tokenTypes.arrayAppend("modifier");
tokenTypes.arrayAppend("comment");
tokenTypes.arrayAppend("string");
tokenTypes.arrayAppend("number");
tokenTypes.arrayAppend("regexp");
tokenTypes.arrayAppend("operator");

auto tokenModifiers = sematicTokens.AddArray("tokenModifiers");
tokenModifiers.arrayAppend("declaration");
tokenModifiers.arrayAppend("definition");
tokenModifiers.arrayAppend("readonly");
tokenModifiers.arrayAppend("static");
tokenModifiers.arrayAppend("deprecated");
tokenModifiers.arrayAppend("abstract");
tokenModifiers.arrayAppend("async");
tokenModifiers.arrayAppend("modification");
tokenModifiers.arrayAppend("documentation");
tokenModifiers.arrayAppend("defaultLibrary");
textDocumentCapabilities["semanticTokens"]["tokenTypes"] = {
"type", "class", "enum", "interface", "struct", "typeParameter", "parameter",
"variable", "property", "enumMember", "event", "function", "method", "macro",
"keyword", "modifier", "comment", "string", "number", "regexp", "operator"};
textDocumentCapabilities["semanticTokens"]["tokenModifiers"] = {"declaration",
"definition",
"readonly",
"static",
"deprecated",
"abstract",
"async",
"modification",
"documentation",
"defaultLibrary"};
}

json.addProperty("params", params);
json["params"] = std::move(params);
return json;
}

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 override;
nlohmann::json ToJSON() const override;
std::optional<LSPEvent> 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
2 changes: 1 addition & 1 deletion CodeLite/LSP/InitializedNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace LSP
{
struct InitializedParams : public Params {
JSONItem ToJSON() const override { return nlohmann::json::object(); }
nlohmann::json ToJSON() const override { return nlohmann::json::object(); }

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 = 0;
virtual nlohmann::json ToJSON() const = 0;
virtual void FromJSON(const JSONItem& json) = 0;

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

} // namespace

JSONItem LSP::Message::ToJSON() const { return nlohmann::json{{"jsonrpc", m_jsonrpc.ToStdString(wxConvUTF8)}}; }
nlohmann::json LSP::Message::ToJSON() const { return nlohmann::json{{"jsonrpc", m_jsonrpc.ToStdString(wxConvUTF8)}}; }

void LSP::Message::FromJSON(const JSONItem& json) { m_jsonrpc = json.namedObject("jsonrpc").toString(); }

Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WXDLLIMPEXP_CL Message : public LSP::Serializable
public:
Message() = default;
~Message() override = default;
JSONItem ToJSON() const override;
nlohmann::json ToJSON() const override;
void FromJSON(const JSONItem& json) override;

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

JSONItem LSP::MessageWithParams::ToJSON() const
nlohmann::json LSP::MessageWithParams::ToJSON() const
{
JSONItem json = Message::ToJSON();
json.addProperty("method", GetMethod());
auto json = Message::ToJSON();
json["method"] = GetMethod().ToStdString(wxConvUTF8);
if (m_params) {
json.addProperty("params", m_params->ToJSON());
json["params"] = m_params->ToJSON();
}
return json;
}
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/MessageWithParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WXDLLIMPEXP_CL MessageWithParams : public LSP::Message
public:
MessageWithParams() = default;
~MessageWithParams() override = default;
JSONItem ToJSON() const override;
nlohmann::json ToJSON() const override;
void FromJSON(const JSONItem& json) override;
std::string ToString() const override;

Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/RenameRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::optional<LSPEvent> LSP::RenameRequest::OnResponse(const LSP::ResponseMessag
for (const auto& [filepath, changes] : modifications) {
LSP_DEBUG() << " " << filepath << modifications.size() << "changes:" << endl;
for (const auto& change : changes) {
LSP_DEBUG() << " " << change.ToJSON().format(false) << endl;
LSP_DEBUG() << " " << wxString::FromUTF8(change.ToJSON().dump(0)) << endl;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions CodeLite/LSP/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LSP::Request::Request()
{
}

JSONItem LSP::Request::ToJSON() const
nlohmann::json LSP::Request::ToJSON() const
{
JSONItem json = MessageWithParams::ToJSON();
json.addProperty("id", GetId());
auto json = MessageWithParams::ToJSON();
json["id"] = GetId();
return json;
}

Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WXDLLIMPEXP_CL Request : public LSP::MessageWithParams
void SetId(int id) { this->m_id = id; }
int GetId() const { return m_id; }

JSONItem ToJSON() const override;
nlohmann::json ToJSON() const override;
void FromJSON(const JSONItem& json) override;

/**
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/ResponseError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ void LSP::ResponseError::FromJSON(const JSONItem& json)

std::string LSP::ResponseError::ToString() const { return ""; }

JSONItem LSP::ResponseError::ToJSON() const { return JSONItem(nullptr); }
nlohmann::json LSP::ResponseError::ToJSON() const { return nullptr; }
2 changes: 1 addition & 1 deletion CodeLite/LSP/ResponseError.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WXDLLIMPEXP_CL ResponseError : public Message
ResponseError() = default;
~ResponseError() override = default;
void FromJSON(const JSONItem& json) override;
JSONItem ToJSON() const override;
nlohmann::json ToJSON() const override;
std::string ToString() const override;
void SetErrorCode(int errorCode) { this->m_errorCode = errorCode; }
void SetMessage(const wxString& message) { this->m_message = message; }
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/ResponseMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std::string LSP::ResponseMessage::ToString() const
}

// we don't really serialise response messages
JSONItem LSP::ResponseMessage::ToJSON() const { return JSONItem(nullptr); }
nlohmann::json LSP::ResponseMessage::ToJSON() const { return nullptr; }

void LSP::ResponseMessage::FromJSON(const JSONItem& json)
{
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/ResponseMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class WXDLLIMPEXP_CL ResponseMessage : public LSP::Message
public:
ResponseMessage(std::unique_ptr<JSON>&& json);
~ResponseMessage() override = default;
JSONItem ToJSON() const override;
nlohmann::json ToJSON() const override;
void FromJSON(const JSONItem& json) override;

std::string ToString() const override;
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/WorkspaceExecuteCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WorkspaceExecuteCommand::WorkspaceExecuteCommand(const wxString& filepath, const
{
SetMethod("workspace/executeCommand");
m_params.reset(new ExecuteCommandParams(command.GetCommand(), command.GetArguments()));
LSP_DEBUG() << ToJSON().format(true) << endl;
LSP_DEBUG() << wxString::FromUTF8(ToJSON().dump(2)) << endl;
}

std::optional<LSPEvent> WorkspaceExecuteCommand::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
Expand Down
2 changes: 1 addition & 1 deletion CodeLite/LSP/WorkspaceSymbolRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WorkspaceSymbolParams : public Params

void FromJSON(const JSONItem& json) override { m_query = json["query"].toString(); }

JSONItem ToJSON() const override { return nlohmann::json{{"query", m_query.ToStdString(wxConvUTF8)}}; }
nlohmann::json ToJSON() const override { return nlohmann::json{{"query", m_query.ToStdString(wxConvUTF8)}}; }

void SetQuery(const wxString& query) { this->m_query = query; }
const wxString& GetQuery() const { return this->m_query; }
Expand Down
Loading
Loading