Skip to content

Commit ca3b115

Browse files
committed
为intellij插件做准备
1 parent d71d6ab commit ca3b115

File tree

9 files changed

+61
-40
lines changed

9 files changed

+61
-40
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
1212
add_definitions(-DMSVC)
1313
endif ()
1414

15-
1615
add_subdirectory(LuaParser)
1716
add_subdirectory(CodeService)
1817
add_subdirectory(Util)

CodeFormatServer/src/CodeFormatServer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ using namespace asio::ip;
1818

1919
int main(int argc, char** argv)
2020
{
21+
// std::this_thread::sleep_for(std::chrono::seconds(10));
2122
if(argc > 1)
2223
{
2324
int port = std::stoi(argv[1]);

CodeFormatServer/src/LanguageService.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std::shared_ptr<vscode::InitializeResult> LanguageService::OnInitialize(std::sha
5252
{
5353
LanguageClient::GetInstance().UpdateOptions(configFile.workspace, configFile.path);
5454
}
55+
result->capabilities.codeActionProvider = true;
5556

5657
return result;
5758
}

CodeFormatServer/src/Protocol/ProtocolParser.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "CodeFormatServer/LanguageService.h"
77

88
ProtocolParser::ProtocolParser()
9-
: _id(-1)
9+
: _id(nullptr)
1010
{
1111
}
1212

@@ -17,6 +17,11 @@ void ProtocolParser::Parse(std::string_view msg)
1717
{
1818
_id = jsonMessage["id"].get<int>();
1919
}
20+
else if (jsonMessage["id"].is_string())
21+
{
22+
_id = jsonMessage["id"].get<std::string>();
23+
}
24+
2025
if (jsonMessage["method"].is_string())
2126
{
2227
_method = jsonMessage["method"].get<std::string>();
@@ -40,11 +45,16 @@ std::string_view ProtocolParser::GetMethod()
4045

4146
std::string ProtocolParser::SerializeProtocol(std::shared_ptr<vscode::Serializable> result)
4247
{
43-
4448
nlohmann::json json;
45-
if (_id != -1) {
46-
json["id"] = _id;
49+
if (_id.index() == 0)
50+
{
51+
json["id"] = std::get<int>(_id);
52+
}
53+
else if (_id.index() == 1)
54+
{
55+
json["id"] = std::get<std::string>(_id);
4756
}
57+
4858
json["result"] = result->Serialize();
4959
json["jsonrpc"] = "2.0";
5060
auto dumpResult = json.dump();

CodeFormatServer/src/VSCode.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ std::shared_ptr<vscode::Serializable> vscode::MakeFromRequest(std::string_view m
3535
{
3636
return MakeRequestObject<DidCloseTextDocumentParams>(json);
3737
}
38-
else if (method == "updateEditorConfig")
38+
else if (method == "updateEditorConfig")
3939
{
4040
return MakeRequestObject<EditorConfigUpdateParams>(json);
4141
}
@@ -150,7 +150,7 @@ nlohmann::json vscode::PublishDiagnosticsParams::Serialize()
150150

151151
auto array = nlohmann::json::array();
152152

153-
for(auto& diagnositc: diagnostics)
153+
for (auto& diagnositc : diagnostics)
154154
{
155155
array.push_back(diagnositc.Serialize());
156156
}
@@ -178,54 +178,58 @@ nlohmann::json vscode::TextDocumentSyncOptions::Serialize()
178178

179179
object["openClose"] = openClose;
180180
object["change"] = change;
181+
object["willSave"] = willSave;
182+
object["willSaveWaitUntil"] = willSaveWaitUntil;
181183

182184
return object;
183185
}
184186

185-
void vscode::TextDocumentSyncOptions::Deserialize(nlohmann::json json)
186-
{
187-
openClose = json["openClose"];
188-
change = static_cast<TextDocumentSyncKind>(json["change"].get<int>());
189-
}
190-
191187
nlohmann::json vscode::ServerCapabilities::Serialize()
192188
{
193189
auto object = nlohmann::json::object();
194190
object["textDocumentSync"] = textDocumentSync.Serialize();
195191
object["documentFormattingProvider"] = documentFormattingProvider;
196-
192+
// object["codeActionProvider"] = codeActionProvider;
197193
return object;
198194
}
199195

200-
void vscode::ServerCapabilities::Deserialize(nlohmann::json json)
201-
{
202-
documentFormattingProvider = json["documentFormattingProvider"];
203-
textDocumentSync.Deserialize(json["textDocumentSync"]);
204-
}
205-
206196
void vscode::InitializationOptions::Deserialize(nlohmann::json json)
207197
{
208-
auto configFileArray = json["configFiles"];
209-
210-
for(auto& configSource: configFileArray)
198+
if (json["configFiles"].is_array())
211199
{
212-
auto& source = configFiles.emplace_back();
213-
source.Deserialize(configSource);
214-
}
200+
auto configFileArray = json["configFiles"];
215201

216-
auto workspaceFolderArray = json["workspaceFolders"];
217-
218-
for(auto& workspaceUri: workspaceFolderArray)
202+
for (auto& configSource : configFileArray)
203+
{
204+
auto& source = configFiles.emplace_back();
205+
source.Deserialize(configSource);
206+
}
207+
}
208+
if (json["workspaceFolders"].is_array())
219209
{
220-
workspaceFolders.emplace_back(workspaceUri);
210+
auto workspaceFolderArray = json["workspaceFolders"];
211+
212+
for (auto& workspaceUri : workspaceFolderArray)
213+
{
214+
workspaceFolders.emplace_back(workspaceUri);
215+
}
221216
}
222217
}
223218

224219
void vscode::InitializeParams::Deserialize(nlohmann::json json)
225220
{
226-
rootPath = json["rootPath"];
227-
rootUri = json["rootUri"];
228-
locale = json["locale"];
221+
if (json["rootPath"].is_string())
222+
{
223+
rootPath = json["rootPath"];
224+
}
225+
if (json["rootUri"].is_string())
226+
{
227+
rootUri = json["rootUri"];
228+
}
229+
if (json["locale"].is_string())
230+
{
231+
locale = json["locale"];
232+
}
229233

230234
initializationOptions.Deserialize(json["initializationOptions"]);
231235
}
@@ -290,14 +294,14 @@ void vscode::DocumentFormattingParams::Deserialize(nlohmann::json json)
290294

291295
nlohmann::json vscode::DocumentFormattingResult::Serialize()
292296
{
293-
if(hasError)
297+
if (hasError)
294298
{
295299
return nullptr;
296300
}
297301
else
298302
{
299303
auto array = nlohmann::json::array();
300-
for(auto& edit: edits)
304+
for (auto& edit : edits)
301305
{
302306
array.push_back(edit.Serialize());
303307
}

CodeService/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ project(CodeService)
44

55
add_library(CodeService STATIC)
66

7+
#add_subdirectory(${LuaCodeStyle_SOURCE_DIR}/3rd/JamSpell-0.0.12 jamspell.out)
8+
79
add_dependencies(CodeService LuaParser)
810

911
target_include_directories(CodeService PUBLIC
1012
${LuaCodeStyle_SOURCE_DIR}/include
13+
${LuaCodeStyle_SOURCE_DIR}/3rd/JamSpell-0.0.12/jamspell
1114
src
1215
)
1316

CodeService/src/FormatElement/TextElement.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "CodeService/FormatElement/TextElement.h"
22

3+
34
TextElement::TextElement(std::string_view text, TextRange range)
45
: _text(text),
56
FormatElement(range)

include/CodeFormatServer/Protocol/ProtocolParser.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstdlib>
44
#include <string_view>
55
#include <memory>
6+
#include <variant>
67
#include "CodeFormatServer/VSCode.h"
78

89
class ProtocolParser
@@ -18,7 +19,7 @@ class ProtocolParser
1819

1920
std::string SerializeProtocol(std::shared_ptr<vscode::Serializable> result);
2021
private:
21-
int _id;
22+
std::variant<int, std::string, void*> _id;
2223
std::string _method;
2324
std::shared_ptr<vscode::Serializable> _param;
24-
};
25+
};

include/CodeFormatServer/VSCode.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,20 @@ class TextDocumentSyncOptions : public Serializable
121121
public:
122122
bool openClose = false;
123123
TextDocumentSyncKind change = TextDocumentSyncKind::None;
124+
bool willSave = false;
125+
bool willSaveWaitUntil = false;
124126

125127
nlohmann::json Serialize() override;
126-
void Deserialize(nlohmann::json json) override;
127128
};
128129

129130
class ServerCapabilities : public Serializable
130131
{
131132
public:
132133
TextDocumentSyncOptions textDocumentSync;
133-
bool documentFormattingProvider;
134+
bool documentFormattingProvider = false;
135+
bool codeActionProvider = false;
134136

135137
nlohmann::json Serialize() override;
136-
void Deserialize(nlohmann::json json) override;
137138
};
138139

139140
class EditorConfigSource;

0 commit comments

Comments
 (0)