Debian Codegraph @

CodeLite/LSP/GotoDefinitionRequest.cpp

raw
1 #include "GotoDefinitionRequest.h"
2
3 #include "LSP/LSPEvent.h"
4 #include "file_logger.h"
5
6 LSP::GotoDefinitionRequest::GotoDefinitionRequest(const wxString& filename, size_t line, size_t column)
7 : m_filename(filename)
8 , m_line(line)
9 , m_column(column)
10 {
11 SetMethod("textDocument/definition");
12 m_params.reset(new TextDocumentPositionParams());
13 m_params->As<TextDocumentPositionParams>()->SetTextDocument(TextDocumentIdentifier(filename));
14 m_params->As<TextDocumentPositionParams>()->SetPosition(Position(line, column));
15 }
16
17 LSP::GotoDefinitionRequest::~GotoDefinitionRequest() {}
18
19 void LSP::GotoDefinitionRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
20 {
21 JSONItem result = response.Get("result");
22 if(!result.isOk()) {
23 return;
24 }
25
26 std::vector<LSP::Location> locations;
27 if(result.isArray()) {
28 int count = result.arraySize();
29 locations.reserve(count);
30 for(int i = 0; i < count; ++i) {
31 LSP::Location loc;
32 loc.FromJSON(result.arrayItem(i));
33 locations.emplace_back(loc);
34 }
35 } else {
36 LSP::Location loc;
37 loc.FromJSON(result);
38 locations.push_back(loc);
39 }
40
41 if(locations.empty()) {
42 return;
43 }
44
45 // Fire an event with the matching location
46 LSPEvent definitionEvent(wxEVT_LSP_DEFINITION);
47 definitionEvent.SetLocations(locations);
48 owner->AddPendingEvent(definitionEvent);
49 }
50
51 bool LSP::GotoDefinitionRequest::IsValidAt(const wxString& filename, size_t line, size_t col) const
52 {
53 return (m_filename == filename) && (m_line == line) && (m_column == col);
54 }