diff options
Diffstat (limited to 'graphics/asymptote/LspCpp/include')
4 files changed, 75 insertions, 22 deletions
diff --git a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/GCThreadContext.h b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/GCThreadContext.h index a0f7db288d..6c9f9c1cbb 100644 --- a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/GCThreadContext.h +++ b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/GCThreadContext.h @@ -1,6 +1,6 @@ #pragma once -#if defined(USEGC) +#if defined(LSPCPP_USEGC) #define GC_THREADS #include <gc.h> #endif @@ -12,7 +12,7 @@ public: ~GCThreadContext(); private: -#if defined(USEGC) +#if defined(LSPCPP_USEGC) GC_stack_base gsb; #endif diff --git a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/MessageProducer.h b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/MessageProducer.h index 2affe3b3ff..4f3799555a 100644 --- a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/MessageProducer.h +++ b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/MessageProducer.h @@ -2,11 +2,18 @@ #include <string> #include <functional> +namespace lsp { + /// The encoding style of the JSON-RPC messages (both input and output). + enum JSONStreamStyle { + /// Encoding per the LSP specification, with mandatory Content-Length header. + Standard, + /// Messages are delimited by a '// -----' line. Comment lines start with //. + Delimited + }; +} class MessageProducer { public: - - typedef std::function< void(std::string&&) > MessageConsumer; virtual ~MessageProducer() = default; virtual void listen(MessageConsumer) = 0; diff --git a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/RemoteEndPoint.h b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/RemoteEndPoint.h index 4045098f1b..8d013bd889 100644 --- a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/RemoteEndPoint.h +++ b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/RemoteEndPoint.h @@ -13,6 +13,7 @@ #include "LibLsp/JsonRpc/MessageJsonHandler.h" #include "Endpoint.h" #include "future.h" +#include "MessageProducer.h" class MessageJsonHandler; @@ -125,7 +126,9 @@ public: RemoteEndPoint(const std::shared_ptr <MessageJsonHandler>& json_handler, const std::shared_ptr < Endpoint >& localEndPoint, - lsp::Log& _log, uint8_t max_workers = 2); + lsp::Log& _log, + lsp::JSONStreamStyle style = lsp::JSONStreamStyle::Standard, + uint8_t max_workers = 2); ~RemoteEndPoint() override; template <typename F, typename RequestType = ParamType<F, 0>, typename ResponseType = typename RequestType::Response> diff --git a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h index e039891f5f..9cd6aef37f 100644 --- a/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h +++ b/graphics/asymptote/LspCpp/include/LibLsp/JsonRpc/StreamMessageProducer.h @@ -13,36 +13,79 @@ namespace lsp { class StreamMessageProducer : public MessageProducer { public: - struct Headers - { - int contentLength = -1; - std::string charset; - void clear() - { - contentLength = -1; - charset.clear(); - } - }; - bool handleMessage(Headers& headers, MessageConsumer callBack); - StreamMessageProducer( + + StreamMessageProducer( MessageIssueHandler& message_issue_handler, std::shared_ptr < lsp::istream> _input) : issueHandler(message_issue_handler), input(_input) { } - StreamMessageProducer( + StreamMessageProducer( MessageIssueHandler& message_issue_handler) : issueHandler(message_issue_handler) { } bool keepRunning = false; - void listen(MessageConsumer) override; - void bind(std::shared_ptr < lsp::istream>); - void parseHeader(std::string& line, Headers& headers); -private: + + virtual void bind(std::shared_ptr<lsp::istream>) = 0 ; + +protected: MessageIssueHandler& issueHandler; std::shared_ptr < lsp::istream> input; + +}; + +class LSPStreamMessageProducer : public StreamMessageProducer +{ +public: + struct Headers + { + int contentLength = -1; + std::string charset; + void clear() + { + contentLength = -1; + charset.clear(); + } + }; + bool handleMessage(Headers& headers, MessageConsumer callBack); + + LSPStreamMessageProducer( + MessageIssueHandler& message_issue_handler, std::shared_ptr < lsp::istream> _input) + : StreamMessageProducer(message_issue_handler,_input) + { + } + LSPStreamMessageProducer( + MessageIssueHandler& message_issue_handler) + : StreamMessageProducer(message_issue_handler) + { + } + + + void listen(MessageConsumer) override; + void bind(std::shared_ptr<lsp::istream>) override; + void parseHeader(std::string& line, Headers& headers); }; +class DelimitedStreamMessageProducer : public StreamMessageProducer +{ +public: + + DelimitedStreamMessageProducer( + MessageIssueHandler& message_issue_handler, std::shared_ptr <lsp::istream> _input) + : StreamMessageProducer(message_issue_handler,_input) + { + } + DelimitedStreamMessageProducer( + MessageIssueHandler& message_issue_handler) + : StreamMessageProducer(message_issue_handler) + { + } + + + void listen(MessageConsumer) override; + void bind(std::shared_ptr < lsp::istream>) override; + +};
\ No newline at end of file |