summaryrefslogtreecommitdiff
path: root/graphics/asymptote/LspCpp/examples
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/LspCpp/examples')
-rw-r--r--graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp326
-rw-r--r--graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp218
-rw-r--r--graphics/asymptote/LspCpp/examples/TcpServerExample.cpp306
-rw-r--r--graphics/asymptote/LspCpp/examples/WebsocketExample.cpp22
4 files changed, 440 insertions, 432 deletions
diff --git a/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp b/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp
index 2ce67d1862..1c75974912 100644
--- a/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp
+++ b/graphics/asymptote/LspCpp/examples/StdIOClientExample.cpp
@@ -29,190 +29,190 @@ 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;
- };
+ 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
- {
-
- }
+ 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
- {
-
- }
+ 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();
+ 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;
+ 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);
+ std::shared_ptr<GenericEndpoint> endpoint = std::make_shared<GenericEndpoint>(_log);
- boost::process::opstream write_to_service;
- boost::process::ipstream read_from_service;
+ 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<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;
+ 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 = "STDIO_SERVER_EXAMPLE.exe";
- }
-
- 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 (std::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;
+ 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 = "STDIO_SERVER_EXAMPLE.exe";
+ }
+
+ 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
index 1fccf2a859..028283ab8d 100644
--- a/graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp
+++ b/graphics/asymptote/LspCpp/examples/StdIOServerExample.cpp
@@ -26,100 +26,100 @@ 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;
- };
+ 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;
+
+ 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;
};
@@ -127,33 +127,33 @@ public:
int main(int argc, char* argv[])
{
- using namespace boost::program_options;
- options_description desc("Allowed options");
- desc.add_options()
- ("help,h", "produce help message");
+ 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);
+ 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();
+ if (vm.count("help"))
+ {
+ cout << desc << endl;
+ return 1;
+ }
+ StdIOServer server;
+ server.esc_event.wait();
- return 0;
+ return 0;
}
diff --git a/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp b/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp
index 80f77b5eb9..42ed73407e 100644
--- a/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp
+++ b/graphics/asymptote/LspCpp/examples/TcpServerExample.cpp
@@ -25,22 +25,22 @@ 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;
- };
+ 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";
@@ -51,149 +51,157 @@ 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)
- {
- td_definition::response rsp;
- rsp.result.first= std::vector<lsLocation>();
- std::this_thread::sleep_for(std::chrono::seconds(8));
- if(monitor && monitor())
- {
- _log.info("textDocument/definition request had been cancel.");
- }
- 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;
+ 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_;
+ 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()
+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);
- Notify_Cancellation::notify cancel_notify;
- cancel_notify.params.id = req.id;
- client.remote_end_point_.send(cancel_notify);
-
- auto state = future_rsp.wait_for(std::chrono::seconds(16));
- if (std::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" << std::endl;
-
- }
- else
- {
- std::cout << rsp.response.ToJson() << std::endl;
- }
- }
- Notify_Exit::notify notify;
- client.remote_end_point_.send(notify);
- return 0;
+ 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
index 40d920ac00..b0474bc288 100644
--- a/graphics/asymptote/LspCpp/examples/WebsocketExample.cpp
+++ b/graphics/asymptote/LspCpp/examples/WebsocketExample.cpp
@@ -89,9 +89,9 @@ class Client : public std::enable_shared_from_this<Client>
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;
@@ -104,7 +104,7 @@ public:
, ws_(net::make_strand(ioc)),point(protocol_json_handler, endpoint, _log)
{
proxy_ = std::make_shared<lsp::websocket_stream_wrapper>(ws_);
-
+
}
// Start the asynchronous operation
@@ -127,12 +127,12 @@ public:
{
ioc.run();
}).detach();
- while (!point.IsWorking())
+ while (!point.isWorking())
{
std::this_thread::sleep_for(std::chrono::milliseconds (50));
}
}
-
+
void
on_resolve(
beast::error_code ec,
@@ -189,7 +189,7 @@ public:
return;
// Send the message
-
+
point.startProcessingMessages(proxy_, proxy_);
// Read a message into our buffer
@@ -215,7 +215,7 @@ public:
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(
@@ -249,7 +249,7 @@ public:
code_lens_options.resolveProvider = true;
rsp.result.capabilities.codeLensProvider = code_lens_options;
return rsp;
- });
+ });
std::thread([&]()
{
server.run();
@@ -261,7 +261,7 @@ public:
}
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;
@@ -271,11 +271,11 @@ 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);