| 1 |
|
| 2 |
#include "LibLsp/JsonRpc/Condition.h" |
| 3 |
#include "LibLsp/lsp/general/exit.h" |
| 4 |
#include "LibLsp/lsp/textDocument/declaration_definition.h" |
| 5 |
#include <boost/program_options.hpp> |
| 6 |
#include "LibLsp/lsp/textDocument/signature_help.h" |
| 7 |
#include "LibLsp/lsp/general/initialize.h" |
| 8 |
#include "LibLsp/lsp/ProtocolJsonHandler.h" |
| 9 |
#include "LibLsp/lsp/textDocument/typeHierarchy.h" |
| 10 |
#include "LibLsp/lsp/AbsolutePath.h" |
| 11 |
#include "LibLsp/lsp/textDocument/resolveCompletionItem.h" |
| 12 |
#include <network/uri.hpp> |
| 13 |
|
| 14 |
#include "LibLsp/JsonRpc/Endpoint.h" |
| 15 |
#include "LibLsp/JsonRpc/stream.h" |
| 16 |
#include "LibLsp/JsonRpc/TcpServer.h" |
| 17 |
#include "LibLsp/lsp/textDocument/document_symbol.h" |
| 18 |
#include "LibLsp/lsp/workspace/execute_command.h" |
| 19 |
#include <boost/process.hpp> |
| 20 |
#include <boost/filesystem.hpp> |
| 21 |
#include <boost/asio.hpp> |
| 22 |
#include <iostream> |
| 23 |
#include <thread> |
| 24 |
|
| 25 |
using namespace boost::asio::ip; |
| 26 |
using namespace std; |
| 27 |
class DummyLog :public lsp::Log |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
void log(Level level, std::wstring&& msg) |
| 32 |
{ |
| 33 |
|
| 34 |
std::wcerr << msg << std::endl; |
| 35 |
}; |
| 36 |
void log(Level level, const std::wstring& msg) |
| 37 |
{ |
| 38 |
std::wcerr << msg << std::endl; |
| 39 |
}; |
| 40 |
void log(Level level, std::string&& msg) |
| 41 |
{ |
| 42 |
std::cerr << msg << std::endl; |
| 43 |
}; |
| 44 |
void log(Level level, const std::string& msg) |
| 45 |
{ |
| 46 |
std::cerr << msg << std::endl; |
| 47 |
}; |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
class StdIOServer |
| 52 |
{ |
| 53 |
public: |
| 54 |
|
| 55 |
StdIOServer() : remote_end_point_(protocol_json_handler, endpoint, _log) |
| 56 |
{ |
| 57 |
remote_end_point_.registerHandler([&](const td_initialize::request& req) |
| 58 |
{ |
| 59 |
td_initialize::response rsp; |
| 60 |
rsp.id = req.id; |
| 61 |
CodeLensOptions code_lens_options; |
| 62 |
code_lens_options.resolveProvider = true; |
| 63 |
rsp.result.capabilities.codeLensProvider = code_lens_options; |
| 64 |
return rsp; |
| 65 |
}); |
| 66 |
|
| 67 |
remote_end_point_.registerHandler([&](Notify_Exit::notify& notify) |
| 68 |
{ |
| 69 |
remote_end_point_.stop(); |
| 70 |
esc_event.notify(std::make_unique<bool>(true)); |
| 71 |
}); |
| 72 |
remote_end_point_.registerHandler([&](const td_definition::request& req, |
| 73 |
const CancelMonitor& monitor) |
| 74 |
{ |
| 75 |
td_definition::response rsp; |
| 76 |
rsp.result.first = std::vector<lsLocation>(); |
| 77 |
if (monitor && monitor()) |
| 78 |
{ |
| 79 |
_log.info("textDocument/definition request had been cancel."); |
| 80 |
} |
| 81 |
return rsp; |
| 82 |
}); |
| 83 |
|
| 84 |
remote_end_point_.startProcessingMessages(input, output); |
| 85 |
} |
| 86 |
~StdIOServer() |
| 87 |
{ |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
struct ostream : lsp::base_ostream<std::ostream> |
| 92 |
{ |
| 93 |
explicit ostream(std::ostream& _t) |
| 94 |
: base_ostream<std::ostream>(_t) |
| 95 |
{ |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
std::string what() override |
| 100 |
{ |
| 101 |
return {}; |
| 102 |
} |
| 103 |
}; |
| 104 |
struct istream :lsp::base_istream<std::istream> |
| 105 |
{ |
| 106 |
explicit istream(std::istream& _t) |
| 107 |
: base_istream<std::istream>(_t) |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
std::string what() override |
| 112 |
{ |
| 113 |
return {}; |
| 114 |
} |
| 115 |
}; |
| 116 |
std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared < lsp::ProtocolJsonHandler >(); |
| 117 |
DummyLog _log; |
| 118 |
|
| 119 |
std::shared_ptr<ostream> output = std::make_shared<ostream>(std::cout); |
| 120 |
std::shared_ptr<istream> input = std::make_shared<istream>(std::cin); |
| 121 |
|
| 122 |
std::shared_ptr < GenericEndpoint > endpoint = std::make_shared<GenericEndpoint>(_log); |
| 123 |
RemoteEndPoint remote_end_point_; |
| 124 |
Condition<bool> esc_event; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
int main(int argc, char* argv[]) |
| 131 |
{ |
| 132 |
using namespace boost::program_options; |
| 133 |
options_description desc("Allowed options"); |
| 134 |
desc.add_options() |
| 135 |
("help,h", "produce help message"); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
variables_map vm; |
| 140 |
try { |
| 141 |
store(parse_command_line(argc, argv, desc), vm); |
| 142 |
} |
| 143 |
catch (std::exception& e) { |
| 144 |
std::cout << "Undefined input.Reason:" << e.what() << std::endl; |
| 145 |
return 0; |
| 146 |
} |
| 147 |
notify(vm); |
| 148 |
|
| 149 |
|
| 150 |
if (vm.count("help")) |
| 151 |
{ |
| 152 |
cout << desc << endl; |
| 153 |
return 1; |
| 154 |
} |
| 155 |
StdIOServer server; |
| 156 |
server.esc_event.wait(); |
| 157 |
|
| 158 |
return 0; |
| 159 |
} |
| 160 |
|
| 161 |
|