Debian Codegraph @

CodeLite/LSP/GotoDeclarationRequest.cpp

raw
1 #include "GotoDeclarationRequest.h"
2
3 #include "LSP/LSPEvent.h"
4 #include "event_notifier.h"
5 #include "file_logger.h"
6
7 LSP::GotoDeclarationRequest::GotoDeclarationRequest(const wxString& filename, size_t line, size_t column,
8 bool for_add_missing_header)
9 : m_filename(filename)
10 , m_line(line)
11 , m_column(column)
12 , m_for_add_missing_header(for_add_missing_header)
13 {
14 SetMethod("textDocument/declaration");
15 m_params.reset(new TextDocumentPositionParams());
16 m_params->As<TextDocumentPositionParams>()->SetTextDocument(TextDocumentIdentifier(filename));
17 m_params->As<TextDocumentPositionParams>()->SetPosition(Position(line, column));
18 }
19
20 LSP::GotoDeclarationRequest::~GotoDeclarationRequest() {}
21
22 void LSP::GotoDeclarationRequest::OnResponse(const LSP::ResponseMessage& response, wxEvtHandler* owner)
23 {
24 LOG_IF_TRACE { clDEBUG1() << "GotoDeclarationRequest::OnResponse() is called" << endl; }
25 JSONItem result = response.Get("result");
26 if(!result.isOk()) {
27 return;
28 }
29
30 LSP::Location loc;
31 if(result.isArray()) {
32 loc.FromJSON(result.arrayItem(0));
33 } else {
34 loc.FromJSON(result);
35 }
36
37 LOG_IF_TRACE { clDEBUG1() << result.format() << endl; }
38
39 if(!loc.GetPath().IsEmpty()) {
40 if(m_for_add_missing_header) {
41 LSPEvent event{ wxEVT_LSP_SYMBOL_DECLARATION_FOUND };
42 event.SetLocation(loc);
43 event.SetFileName(m_filename);
44 EventNotifier::Get()->AddPendingEvent(event);
45 } else {
46 // We send the same event for declaraion as we do for definition
47 LSPEvent event{ wxEVT_LSP_DEFINITION };
48 event.SetLocation(loc);
49 event.SetFileName(m_filename);
50 owner->AddPendingEvent(event);
51 }
52 }
53 }
54
55 bool LSP::GotoDeclarationRequest::IsValidAt(const wxString& filename, size_t line, size_t col) const
56 {
57 return (m_filename == filename) && (m_line == line) && (m_column == col);
58 }