forked from eranif/codelite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeActionRequest.cpp
More file actions
44 lines (37 loc) · 1.55 KB
/
CodeActionRequest.cpp
File metadata and controls
44 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "CodeActionRequest.hpp"
#include "LSP/LSPEvent.h"
#include "event_notifier.h"
LSP::CodeActionRequest::CodeActionRequest(const LSP::TextDocumentIdentifier& textDocument, const LSP::Range& range,
const std::vector<LSP::Diagnostic>& diags)
{
SetMethod("textDocument/codeAction");
m_params.reset(new CodeActionParams());
m_params->As<CodeActionParams>()->SetTextDocument(textDocument);
m_params->As<CodeActionParams>()->SetRange(range);
m_params->As<CodeActionParams>()->SetDiagnostics(diags);
LSP_DEBUG() << ToJSON().format(true) << endl;
}
void LSP::CodeActionRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
{
wxUnusedVar(owner);
LSP_DEBUG() << "LSP::CodeActionRequest::OnResponse()" << endl;
LSP_DEBUG() << response.ToString() << endl;
auto result_arr = response.Get("result");
if(!result_arr.isArray()) {
LSP_WARNING() << "CodeAction result is expected to be of type array" << endl;
return;
}
// expected array of commands
size_t count = result_arr.arraySize();
LSPEvent event{ wxEVT_LSP_CODE_ACTIONS };
auto& commands = event.GetCommands();
commands.reserve(count);
for(size_t i = 0; i < count; ++i) {
LSP::Command cmd;
cmd.FromJSON(result_arr[i]);
commands.push_back(cmd);
}
LSP_DEBUG() << "Read" << commands.size() << "code actions" << endl;
event.SetFileName(m_params->As<CodeActionParams>()->GetTextDocument().GetPath());
EventNotifier::Get()->AddPendingEvent(event);
}