summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/examples
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2024-11-13 03:03:42 +0000
committerNorbert Preining <norbert@preining.info>2024-11-13 03:03:42 +0000
commit5037cc8f66c1c2dfc56accf0f29866977fce1f11 (patch)
tree916c5b917a84c268d98a6176a93f0a4c3e63a102 /graphics/asymptote/LspCpp/examples
parentd63a87aba38d505e5b1322a0fd3b93549e7cb203 (diff)
CTAN sync 202411130303
Diffstat (limited to 'graphics/asymptote/LspCpp/examples')
-rw-r--r--graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp219
-rw-r--r--graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp161
-rw-r--r--graphics/asymptote/LspCpp/examples/TcpServerExample.cpp209
-rw-r--r--graphics/asymptote/LspCpp/examples/WebsocketExample.cpp296
4 files changed, 0 insertions, 885 deletions
diff --git a/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp b/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp
deleted file mode 100644
index 13bf9da633..0000000000
--- a/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-
-#include "LibLsp/lsp/ProcessIoService.h"
-
-#include <boost/program_options.hpp>
-#include "LibLsp/lsp/general/exit.h"
-#include "LibLsp/lsp/textDocument/declaration_definition.h"
-
-#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>
-
-#include <thread>
-
-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;
- };
-};
-
-struct boost_process_ipstream : lsp::base_istream< boost::process::ipstream >
-{
- explicit boost_process_ipstream(boost::process::ipstream& _t)
- : base_istream<boost::process::ipstream>(_t)
- {
- }
-
- std::string what() override
- {
- return {};
- }
- void clear() override
- {
-
- }
-};
-struct boost_process_opstream : lsp::base_ostream< boost::process::opstream >
-{
- explicit boost_process_opstream(boost::process::opstream& _t)
- : lsp::base_ostream<boost::process::opstream>(_t)
- {
- }
-
- std::string what() override
- {
- return {};
- }
- void clear() override
- {
-
- }
-};
-class Client
-{
-public:
- Client(std::string& execPath,const std::vector<std::string>& args)
- :point(protocol_json_handler, endpoint, _log)
- {
- std::error_code ec;
- namespace bp = boost::process;
- c = std::make_shared<bp::child>(asio_io.getIOService(), execPath,
- bp::args = args,
- ec,
-
- bp::std_out > read_from_service,
- bp::std_in < write_to_service,
- bp::on_exit([&](int exit_code, const std::error_code& ec_in){
-
- }));
- if (ec)
- {
- // fail
- _log.log(lsp::Log::Level::SEVERE, "Start server failed.");
- }
- else {
- //success
- point.startProcessingMessages(read_from_service_proxy, write_to_service_proxy);
- }
- }
- ~Client()
- {
- point.stop();
- std::this_thread::sleep_for(std::chrono::milliseconds (1000));
- }
-
- lsp::ProcessIoService asio_io;
- std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared< lsp::ProtocolJsonHandler>();
- DummyLog _log;
-
- std::shared_ptr<GenericEndpoint> endpoint = std::make_shared<GenericEndpoint>(_log);
-
- boost::process::opstream write_to_service;
- boost::process::ipstream read_from_service;
-
- std::shared_ptr<lsp::ostream> write_to_service_proxy = std::make_shared<boost_process_opstream>(write_to_service);
- std::shared_ptr<lsp::istream> read_from_service_proxy = std::make_shared< boost_process_ipstream >(read_from_service);
-
- std::shared_ptr<boost::process::child> c;
- RemoteEndPoint point;
-};
-
-int main(int argc, char* argv[])
-{
- using namespace boost::program_options;
- options_description desc("Allowed options");
- desc.add_options()
- ("help,h", "produce help message")
- ("execPath", value<string>(), "LSP server's path");
-
-
-
- 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;
- }
- string execPath;
- if (vm.count("execPath"))
- {
- execPath = vm["execPath"].as<string>();
- }
- else
- {
- execPath = "StdIOServerExample";
- }
-
- Client client(execPath, {});
- {
- td_initialize::request req;
- auto rsp = client.point.waitResponse(req);
- if (rsp)
- {
- std::cerr << rsp->ToJson() << std::endl;
- }
- else
- {
- std::cerr << "get initialze response time out" << std::endl;
- }
- }
- {
- td_definition::request req;
- auto future_rsp = client.point.send(req);
- auto state = future_rsp.wait_for(std::chrono::seconds(4));
- if (lsp::future_status::timeout == state)
- {
- std::cerr << "get textDocument/definition response time out" << std::endl;
- return 0;
- }
- auto rsp = future_rsp.get();
- if (rsp.is_error)
- {
- std::cerr << "get textDocument/definition response error" << std::endl;
-
- }
- else
- {
- std::cerr << rsp.response.ToJson() << std::endl;
- }
- }
- {
- td_initialize::request req;
- auto rsp = client.point.waitResponse(req);
- if (rsp)
- {
- std::cerr << rsp->ToJson() << std::endl;
- }
- else
- {
- std::cerr << "get initialze response time out" << std::endl;
- }
- }
- Notify_Exit::notify notify;
- client.point.send(notify);
- return 0;
-}
-
-
diff --git a/graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp b/graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp
deleted file mode 100644
index 8b2d2b2d29..0000000000
--- a/graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp
+++ /dev/null
@@ -1,161 +0,0 @@
-
-#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>
-#include <thread>
-
-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;
-}
-
-
diff --git a/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp b/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp
deleted file mode 100644
index 37a4266c94..0000000000
--- a/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-
-#include "LibLsp/lsp/general/exit.h"
-#include "LibLsp/lsp/textDocument/declaration_definition.h"
-#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/filesystem.hpp>
-#include <boost/asio.hpp>
-#include <iostream>
-#include <thread>
-
-using namespace boost::asio::ip;
-using namespace std;
-class DummyLog :public lsp::Log
-{
-public:
-
- void log(Level level, std::wstring&& msg)
- {
- std::wcout << msg << std::endl;
- };
- void log(Level level, const std::wstring& msg)
- {
- std::wcout << msg << std::endl;
- };
- void log(Level level, std::string&& msg)
- {
- std::cout << msg << std::endl;
- };
- void log(Level level, const std::string& msg)
- {
- std::cout << msg << std::endl;
- };
-};
-
-std::string _address = "127.0.0.1";
-std::string _port = "9333";
-
-class Server
-{
-public:
-
-
- Server():server(_address,_port,protocol_json_handler, endpoint, _log)
- {
- server.point.registerHandler(
- [&](const td_initialize::request& req)
- ->lsp::ResponseOrError< td_initialize::response >{
-
- td_initialize::response rsp;
- CodeLensOptions code_lens_options;
- code_lens_options.resolveProvider = true;
- rsp.result.capabilities.codeLensProvider = code_lens_options;
-
- return rsp;
- });
- server.point.registerHandler([&](const td_definition::request& req
- ,const CancelMonitor& monitor) -> lsp::ResponseOrError<td_definition::response>
- {
-
- std::this_thread::sleep_for(std::chrono::seconds(8));
-
- if( monitor && monitor() )
- {
- _log.info("textDocument/definition request had been cancel.");
- Rsp_Error rsp;
- rsp.error.code = lsErrorCodes::RequestCancelled;
- rsp.error.message = "textDocument/definition request had been cancel.";
- return rsp;
- }
- else
- {
- td_definition::response rsp;
- rsp.result.first= std::vector<lsLocation>();
- return rsp;
- }
-
- });
-
- server.point.registerHandler([=](Notify_Exit::notify& notify)
- {
- std::cout << notify.ToJson() << std::endl;
- });
- std::thread([&]()
- {
- server.run();
- }).detach();
- }
- ~Server()
- {
- server.stop();
- }
- std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared < lsp::ProtocolJsonHandler >();
- DummyLog _log;
-
- std::shared_ptr < GenericEndpoint > endpoint = std::make_shared<GenericEndpoint>(_log);
- lsp::TcpServer server;
-
-};
-
-class Client
-{
-public:
- struct iostream :public lsp::base_iostream<tcp::iostream>
- {
- explicit iostream(boost::asio::basic_socket_iostream<tcp>& _t)
- : base_iostream<boost::asio::basic_socket_iostream<tcp>>(_t)
- {
- }
-
- std::string what() override
- {
- auto msg = _impl.error().message();
- return msg;
- }
-
- };
- Client() :remote_end_point_(protocol_json_handler, endpoint, _log)
- {
- tcp::endpoint end_point( address::from_string(_address), 9333);
-
- socket_ = std::make_shared<tcp::iostream>();
- socket_->connect(end_point);
- if (!socket_)
- {
- string temp = "Unable to connect: " + socket_->error().message();
- std::cout << temp << std::endl;
- }
-
- vector<string> args;
- socket_proxy = std::make_shared<iostream>(*socket_.get());
-
- remote_end_point_.startProcessingMessages(socket_proxy, socket_proxy);
- }
- ~Client()
- {
- remote_end_point_.stop();
- std::this_thread::sleep_for(std::chrono::milliseconds (1000));
- socket_->close();
- }
-
- std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared< lsp::ProtocolJsonHandler>();
- DummyLog _log;
-
- std::shared_ptr<GenericEndpoint> endpoint = std::make_shared<GenericEndpoint>(_log);
-
- std::shared_ptr < iostream> socket_proxy;
- std::shared_ptr<tcp::iostream> socket_;
- RemoteEndPoint remote_end_point_;
-};
-
-int main()
-{
-
- Server server;
- Client client;
-
- {
- td_initialize::request req;
- auto rsp = client.remote_end_point_.waitResponse(req);
- if (rsp)
- {
- std::cout << rsp->response.ToJson() << std::endl;
- }
- else
- {
- std::cout << "get initialze response time out" << std::endl;
- }
- }
- {
- td_definition::request req;
- auto future_rsp = client.remote_end_point_.send(req);
- client.remote_end_point_.cancelRequest(req.id);
-
- auto state = future_rsp.wait_for(std::chrono::seconds(16));
- if (lsp::future_status::timeout == state)
- {
- std::cout << "get textDocument/definition response time out" << std::endl;
- return 0;
- }
- auto rsp = future_rsp.get();
- if (rsp.is_error)
- {
- std::cout << "get textDocument/definition response error :" << rsp.ToJson() << std::endl;
-
- }
- else
- {
- std::cout << rsp.response.ToJson() << std::endl;
- }
- }
- Notify_Exit::notify notify;
- client.remote_end_point_.send(notify);
- return 0;
-}
-
-
diff --git a/graphics/asymptote/LspCpp/examples/WebsocketExample.cpp b/graphics/asymptote/LspCpp/examples/WebsocketExample.cpp
deleted file mode 100644
index b0474bc288..0000000000
--- a/graphics/asymptote/LspCpp/examples/WebsocketExample.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-
-#include "LibLsp/JsonRpc/WebSocketServer.h"
-#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/filesystem.hpp>
-#include <boost/asio.hpp>
-#include <iostream>
-#include <boost/beast/core.hpp>
-#include <boost/beast/websocket.hpp>
-#include <boost/asio/dispatch.hpp>
-#include <boost/asio/strand.hpp>
-#include <algorithm>
-#include <cstdlib>
-#include <functional>
-#include <iostream>
-#include <memory>
-#include <string>
-#include <thread>
-#include <vector>
-
-#include <boost/beast/version.hpp>
-#include <boost/beast/websocket.hpp>
-#include <boost/asio/dispatch.hpp>
-#include "LibLsp/JsonRpc/Endpoint.h"
-#include "LibLsp/JsonRpc/RemoteEndPoint.h"
-#include "LibLsp/JsonRpc/stream.h"
-#include "LibLsp/lsp/ProtocolJsonHandler.h"
-
-namespace beast = boost::beast; // from <boost/beast.hpp>
-namespace http = beast::http; // from <boost/beast/http.hpp>
-namespace websocket = beast::websocket; // from <boost/beast/websocket.hpp>
-namespace net = boost::asio; // from <boost/asio.hpp>
-using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
-
-//------------------------------------------------------------------------------
-
-std::string _address = "127.0.0.1";
-std::string _port = "9333";
-
-
-
-
-using namespace std;
-class DummyLog :public lsp::Log
-{
-public:
-
- void log(Level level, std::wstring&& msg)
- {
- std::wcout << msg << std::endl;
- };
- void log(Level level, const std::wstring& msg)
- {
- std::wcout << msg << std::endl;
- };
- void log(Level level, std::string&& msg)
- {
- std::cout << msg << std::endl;
- };
- void log(Level level, const std::string& msg)
- {
- std::cout << msg << std::endl;
- };
-};
-
-
-
-// Sends a WebSocket message and prints the response
-class Client : public std::enable_shared_from_this<Client>
-{
- net::io_context ioc;
- tcp::resolver resolver_;
- websocket::stream<beast::tcp_stream> ws_;
- beast::flat_buffer buffer_;
- std::string host_;
- std::string user_agent_;
- std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared< lsp::ProtocolJsonHandler>();
- DummyLog _log;
-
- std::shared_ptr<GenericEndpoint> endpoint = std::make_shared<GenericEndpoint>(_log);
-
- std::shared_ptr<lsp::websocket_stream_wrapper> proxy_;
-public:
- RemoteEndPoint point;
-
-public:
- // Resolver and socket require an io_context
- explicit
- Client()
- : resolver_(net::make_strand(ioc))
- , ws_(net::make_strand(ioc)),point(protocol_json_handler, endpoint, _log)
- {
- proxy_ = std::make_shared<lsp::websocket_stream_wrapper>(ws_);
-
- }
-
- // Start the asynchronous operation
- void
- run(
- char const* host,
- char const* port, char const* user_agent)
- {
- // Save these for later
- host_ = host;
- user_agent_ = user_agent;
- // Look up the domain name
- resolver_.async_resolve(
- host,
- port,
- beast::bind_front_handler(
- &Client::on_resolve,
- shared_from_this()));
- std::thread([&]
- {
- ioc.run();
- }).detach();
- while (!point.isWorking())
- {
- std::this_thread::sleep_for(std::chrono::milliseconds (50));
- }
- }
-
- void
- on_resolve(
- beast::error_code ec,
- tcp::resolver::results_type results)
- {
- if (ec)
- return;
-
- // Set the timeout for the operation
- beast::get_lowest_layer(ws_).expires_after(std::chrono::seconds(30));
-
- // Make the connection on the IP address we get from a lookup
- beast::get_lowest_layer(ws_).async_connect(
- results,
- beast::bind_front_handler(
- &Client::on_connect,
- shared_from_this()));
- }
-
- void
- on_connect(beast::error_code ec, tcp::resolver::results_type::endpoint_type)
- {
- if (ec)
- return;
-
- // Turn off the timeout on the tcp_stream, because
- // the websocket stream has its own timeout system.
- beast::get_lowest_layer(ws_).expires_never();
-
- // Set suggested timeout settings for the websocket
- ws_.set_option(
- websocket::stream_base::timeout::suggested(
- beast::role_type::client));
-
- // Set a decorator to change the User-Agent of the handshake
- ws_.set_option(websocket::stream_base::decorator(
- [=](websocket::request_type& req)
- {
- req.set(http::field::user_agent,
- user_agent_.c_str());
- }));
-
- // Perform the websocket handshake
- ws_.async_handshake(host_, "/",
- beast::bind_front_handler(
- &Client::on_handshake,
- shared_from_this()));
- }
-
- void
- on_handshake(beast::error_code ec)
- {
- if (ec)
- return;
-
- // Send the message
-
-
- point.startProcessingMessages(proxy_, proxy_);
- // Read a message into our buffer
- ws_.async_read(
- buffer_,
- beast::bind_front_handler(
- &Client::on_read,
- shared_from_this()));
- }
-
-
- void
- on_read(
- beast::error_code ec,
- std::size_t bytes_transferred)
- {
- boost::ignore_unused(bytes_transferred);
-
- if (ec)
- return;
-
- char* data = reinterpret_cast<char*>(buffer_.data().data());
- std::vector<char> elements(data, data + bytes_transferred);
- buffer_.clear();
- proxy_->on_request.EnqueueAll(std::move(elements), false);
-
- ws_.async_read(
- buffer_,
- beast::bind_front_handler(
- &Client::on_read,
- shared_from_this()));
- }
-
- void
- on_close(beast::error_code ec)
- {
- if (ec)
- return;
-
- // If we get here then the connection is closed gracefully
-
- // The make_printable() function helps print a ConstBufferSequence
- std::cout << beast::make_printable(buffer_.data()) << std::endl;
- }
-};
-
-class Server
-{
-public:
- Server(const std::string& user_agent) : server(user_agent,_address, _port, protocol_json_handler, endpoint, _log)
- {
- server.point.registerHandler(
- [&](const td_initialize::request& req)
- {
- td_initialize::response rsp;
- CodeLensOptions code_lens_options;
- code_lens_options.resolveProvider = true;
- rsp.result.capabilities.codeLensProvider = code_lens_options;
- return rsp;
- });
- std::thread([&]()
- {
- server.run();
- }).detach();
- }
- ~Server()
- {
- server.stop();
- }
- std::shared_ptr < lsp::ProtocolJsonHandler > protocol_json_handler = std::make_shared < lsp::ProtocolJsonHandler >();
- DummyLog _log;
-
- std::shared_ptr < GenericEndpoint > endpoint = std::make_shared<GenericEndpoint>(_log);
- lsp::WebSocketServer server;
-
-};
-
-int main()
-{
- std::string user_agent = std::string(BOOST_BEAST_VERSION_STRING) +" websocket-server-async";
- Server server(user_agent);
-
- auto client = std::make_shared<Client>();
- user_agent = std::string(BOOST_BEAST_VERSION_STRING) + " websocket-client-async";
- client->run(_address.c_str(), _port.c_str(), user_agent.c_str());
-
- td_initialize::request req;
-
- auto rsp = client->point.waitResponse(req);
- if (rsp)
- {
- std::cout << rsp->ToJson() << std::endl;
- }
- return 0;
-}
-
-
-
-
-
-
-
-
-