Debian Codegraph @

CodeLite/LSP/GotoImplementationRequest.cpp

raw
1 #include "GotoImplementationRequest.h"
2 #include "LSP/LSPEvent.h"
3 #include "LSP/json_rpc_params.h"
4
5 LSP::GotoImplementationRequest::GotoImplementationRequest(const wxString& filename, size_t line, size_t column)
6 {
7 SetMethod("textDocument/implementation");
8 m_params.reset(new TextDocumentPositionParams());
9 m_params->As<TextDocumentPositionParams>()->SetTextDocument(TextDocumentIdentifier(filename));
10 m_params->As<TextDocumentPositionParams>()->SetPosition(Position(line, column));
11 }
12
13 LSP::GotoImplementationRequest::~GotoImplementationRequest() {}
14
15 void LSP::GotoImplementationRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
16 {
17 JSONItem result = response.Get("result");
18 if(!result.isOk()) {
19 return;
20 }
21 LSP::Location loc;
22 if(result.isArray()) {
23 loc.FromJSON(result.arrayItem(0));
24 } else {
25 loc.FromJSON(result);
26 }
27
28 // We send the same event for declaraion as we do for definition
29 if(!loc.GetPath().IsEmpty()) {
30 LSPEvent definitionEvent(wxEVT_LSP_DEFINITION);
31 definitionEvent.SetLocation(loc);
32 owner->AddPendingEvent(definitionEvent);
33 }
34 }
35
36 bool LSP::GotoImplementationRequest::IsValidAt(const wxString& filename, size_t line, size_t col) const
37 {
38 return (m_filename == filename) && (m_line == line) && (m_column == col);
39 }