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