| 1 |
#include "LSP/json_rpc_params.h" |
| 2 |
|
| 3 |
//===---------------------------------------------------------------------------------- |
| 4 |
// TextDocumentPositionParams |
| 5 |
//===---------------------------------------------------------------------------------- |
| 6 |
namespace LSP |
| 7 |
{ |
| 8 |
TextDocumentPositionParams::TextDocumentPositionParams() {} |
| 9 |
|
| 10 |
void TextDocumentPositionParams::FromJSON(const JSONItem& json) |
| 11 |
{ |
| 12 |
m_textDocument.FromJSON(json["textDocument"]); |
| 13 |
m_position.FromJSON(json["position"]); |
| 14 |
} |
| 15 |
|
| 16 |
JSONItem TextDocumentPositionParams::ToJSON(const wxString& name) const |
| 17 |
{ |
| 18 |
JSONItem json = JSONItem::createObject(name); |
| 19 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 20 |
json.append(m_position.ToJSON("position")); |
| 21 |
return json; |
| 22 |
} |
| 23 |
//===---------------------------------------------- |
| 24 |
// SemanticTokensParams |
| 25 |
//===---------------------------------------------- |
| 26 |
SemanticTokensParams::SemanticTokensParams() {} |
| 27 |
|
| 28 |
void SemanticTokensParams::FromJSON(const JSONItem& json) { m_textDocument.FromJSON(json["textDocument"]); } |
| 29 |
|
| 30 |
JSONItem SemanticTokensParams::ToJSON(const wxString& name) const |
| 31 |
{ |
| 32 |
JSONItem json = JSONItem::createObject(name); |
| 33 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 34 |
return json; |
| 35 |
} |
| 36 |
|
| 37 |
//===---------------------------------------------------------------------------------- |
| 38 |
// DidOpenTextDocumentParams |
| 39 |
//===---------------------------------------------------------------------------------- |
| 40 |
DidOpenTextDocumentParams::DidOpenTextDocumentParams() {} |
| 41 |
|
| 42 |
void DidOpenTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument.FromJSON(json["textDocument"]); } |
| 43 |
|
| 44 |
JSONItem DidOpenTextDocumentParams::ToJSON(const wxString& name) const |
| 45 |
{ |
| 46 |
JSONItem json = JSONItem::createObject(name); |
| 47 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 48 |
return json; |
| 49 |
} |
| 50 |
|
| 51 |
//===---------------------------------------------------------------------------------- |
| 52 |
// DidCloseTextDocumentParams |
| 53 |
//===---------------------------------------------------------------------------------- |
| 54 |
DidCloseTextDocumentParams::DidCloseTextDocumentParams() {} |
| 55 |
|
| 56 |
void DidCloseTextDocumentParams::FromJSON(const JSONItem& json) { m_textDocument.FromJSON(json["textDocument"]); } |
| 57 |
|
| 58 |
JSONItem DidCloseTextDocumentParams::ToJSON(const wxString& name) const |
| 59 |
{ |
| 60 |
JSONItem json = JSONItem::createObject(name); |
| 61 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 62 |
return json; |
| 63 |
} |
| 64 |
|
| 65 |
//===---------------------------------------------------------------------------------- |
| 66 |
// DidChangeTextDocumentParams |
| 67 |
//===---------------------------------------------------------------------------------- |
| 68 |
DidChangeTextDocumentParams::DidChangeTextDocumentParams() {} |
| 69 |
|
| 70 |
void DidChangeTextDocumentParams::FromJSON(const JSONItem& json) |
| 71 |
{ |
| 72 |
m_textDocument.FromJSON(json["textDocument"]); |
| 73 |
m_contentChanges.clear(); |
| 74 |
if(json.hasNamedObject("contentChanges")) { |
| 75 |
JSONItem arr = json.namedObject("contentChanges"); |
| 76 |
int count = arr.arraySize(); |
| 77 |
for(int i = 0; i < count; ++i) { |
| 78 |
TextDocumentContentChangeEvent c; |
| 79 |
c.FromJSON(arr.arrayItem(i)); |
| 80 |
m_contentChanges.push_back(c); |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
JSONItem DidChangeTextDocumentParams::ToJSON(const wxString& name) const |
| 86 |
{ |
| 87 |
JSONItem json = JSONItem::createObject(name); |
| 88 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 89 |
JSONItem arr = JSONItem::createArray("contentChanges"); |
| 90 |
for(size_t i = 0; i < m_contentChanges.size(); ++i) { |
| 91 |
arr.arrayAppend(m_contentChanges[i].ToJSON("")); |
| 92 |
} |
| 93 |
json.append(arr); |
| 94 |
return json; |
| 95 |
} |
| 96 |
|
| 97 |
//===---------------------------------------------------------------------------------- |
| 98 |
// DidSaveTextDocumentParams |
| 99 |
//===---------------------------------------------------------------------------------- |
| 100 |
DidSaveTextDocumentParams::DidSaveTextDocumentParams() {} |
| 101 |
|
| 102 |
void DidSaveTextDocumentParams::FromJSON(const JSONItem& json) |
| 103 |
{ |
| 104 |
m_textDocument.FromJSON(json["textDocument"]); |
| 105 |
m_text = json["text"].toString(); |
| 106 |
} |
| 107 |
|
| 108 |
JSONItem DidSaveTextDocumentParams::ToJSON(const wxString& name) const |
| 109 |
{ |
| 110 |
JSONItem json = JSONItem::createObject(name); |
| 111 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 112 |
json.addProperty("text", m_text); |
| 113 |
return json; |
| 114 |
} |
| 115 |
|
| 116 |
//===---------------------------------------------------------------------------------- |
| 117 |
// CompletionParams |
| 118 |
//===---------------------------------------------------------------------------------- |
| 119 |
CompletionParams::CompletionParams() {} |
| 120 |
|
| 121 |
void CompletionParams::FromJSON(const JSONItem& json) { TextDocumentPositionParams::FromJSON(json); } |
| 122 |
|
| 123 |
JSONItem CompletionParams::ToJSON(const wxString& name) const |
| 124 |
{ |
| 125 |
JSONItem json = TextDocumentPositionParams::ToJSON(name); |
| 126 |
return json; |
| 127 |
} |
| 128 |
|
| 129 |
//===---------------------------------------------------------------------------------- |
| 130 |
// DocumentSymbolParams |
| 131 |
//===---------------------------------------------------------------------------------- |
| 132 |
DocumentSymbolParams::DocumentSymbolParams() {} |
| 133 |
|
| 134 |
void DocumentSymbolParams::FromJSON(const JSONItem& json) { m_textDocument.FromJSON(json["textDocument"]); } |
| 135 |
|
| 136 |
JSONItem DocumentSymbolParams::ToJSON(const wxString& name) const |
| 137 |
{ |
| 138 |
JSONItem json = JSONItem::createObject(name); |
| 139 |
json.append(m_textDocument.ToJSON("textDocument")); |
| 140 |
return json; |
| 141 |
} |
| 142 |
|
| 143 |
ReferenceParams::ReferenceParams(bool includeDeclaration) |
| 144 |
: m_includeDeclaration(includeDeclaration) |
| 145 |
{ |
| 146 |
} |
| 147 |
|
| 148 |
void ReferenceParams::FromJSON(const JSONItem& json) |
| 149 |
{ |
| 150 |
TextDocumentPositionParams::FromJSON(json); |
| 151 |
m_includeDeclaration = json["context"]["includeDeclaration"].toBool(m_includeDeclaration); |
| 152 |
} |
| 153 |
|
| 154 |
JSONItem ReferenceParams::ToJSON(const wxString& name) const |
| 155 |
{ |
| 156 |
JSONItem json = TextDocumentPositionParams::ToJSON(name); |
| 157 |
auto context = json.AddObject("context"); |
| 158 |
context.addProperty("includeDeclaration", m_includeDeclaration); |
| 159 |
return json; |
| 160 |
} |
| 161 |
}; // namespace LSP |