Debian Codegraph @

CodeLite/LSP/FindReferencesRequest.cpp

raw
1 #include "FindReferencesRequest.hpp"
2
3 #include "JSON.h"
4 #include "LSP/LSPEvent.h"
5 #include "event_notifier.h"
6 #include "file_logger.h"
7
8 LSP::FindReferencesRequest::FindReferencesRequest(const wxString& filename, size_t line, size_t column,
9 bool includeDeclaration)
10 {
11 SetMethod("textDocument/references");
12 m_params.reset(new ReferenceParams(includeDeclaration));
13 m_params->As<ReferenceParams>()->SetTextDocument(TextDocumentIdentifier(filename));
14 m_params->As<ReferenceParams>()->SetPosition(Position(line, column));
15 }
16
17 LSP::FindReferencesRequest::~FindReferencesRequest() {}
18
19 void LSP::FindReferencesRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
20 {
21 wxUnusedVar(owner);
22 JSONItem result = response.Get("result");
23 CHECK_EXPECTED_RETURN(result.isOk(), true);
24
25 // An array of locations
26 int array_size = result.arraySize();
27
28 LSPEvent references_event{ wxEVT_LSP_REFERENCES };
29 std::vector<LSP::Location>& locations = references_event.GetLocations();
30 locations.reserve(array_size);
31
32 for(int i = 0; i < array_size; ++i) {
33 auto d = result[i];
34 LSP::Location loc;
35 loc.FromJSON(d);
36 locations.emplace_back(loc);
37 }
38
39 // fire an event
40 EventNotifier::Get()->AddPendingEvent(references_event);
41 }