| 1 |
#include "InitializeRequest.h" |
| 2 |
#include <wx/filesys.h> |
| 3 |
|
| 4 |
LSP::InitializeRequest::InitializeRequest(const wxString& rootUri) |
| 5 |
{ |
| 6 |
SetMethod("initialize"); |
| 7 |
m_processId = ::wxGetProcessId(); |
| 8 |
m_rootUri = rootUri; |
| 9 |
} |
| 10 |
|
| 11 |
LSP::InitializeRequest::~InitializeRequest() {} |
| 12 |
|
| 13 |
JSONItem LSP::InitializeRequest::ToJSON(const wxString& name) const |
| 14 |
{ |
| 15 |
JSONItem json = Request::ToJSON(name); |
| 16 |
|
| 17 |
// add the 'params' |
| 18 |
JSONItem params = JSONItem::createObject("params"); |
| 19 |
json.append(params); |
| 20 |
params.addProperty("processId", GetProcessId()); |
| 21 |
if(GetRootUri().IsEmpty()) { |
| 22 |
JSON nullItem(cJSON_NULL); |
| 23 |
JSONItem nullObj = nullItem.toElement(); |
| 24 |
params.append(nullObj); |
| 25 |
(void)nullItem.release(); // dont delete it on destruction, it is now owned by 'params' |
| 26 |
} else { |
| 27 |
params.addProperty("rootUri", wxFileSystem::FileNameToURL(GetRootUri())); |
| 28 |
} |
| 29 |
if(!m_initOptions.empty()) { |
| 30 |
// Parse the JSON string and set it as the 'initializationOptions |
| 31 |
JSON initializationOptions(m_initOptions); |
| 32 |
if(initializationOptions.isOk()) { |
| 33 |
cJSON* pjson = initializationOptions.release(); |
| 34 |
json.addProperty(wxString("initializationOptions"), (cJSON*)pjson); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
auto textDocumentCapabilities = params.AddObject("capabilities").AddObject("textDocument"); |
| 39 |
auto docFormat = |
| 40 |
textDocumentCapabilities.AddObject("completion").AddObject("completionItem").AddArray("documentationFormat"); |
| 41 |
docFormat.arrayAppend("plaintext"); |
| 42 |
auto hoverFormat = textDocumentCapabilities.AddObject("hover").AddArray("contentFormat"); |
| 43 |
hoverFormat.arrayAppend("markdown"); |
| 44 |
hoverFormat.arrayAppend("plaintext"); |
| 45 |
return json; |
| 46 |
} |
| 47 |
|
| 48 |
void LSP::InitializeRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner) |
| 49 |
{ |
| 50 |
wxUnusedVar(response); |
| 51 |
wxUnusedVar(owner); |
| 52 |
} |