@@ -50,11 +50,11 @@ class JSONTransportInput {
5050 : style(style) {}
5151 virtual ~JSONTransportInput () = default ;
5252
53- virtual bool getError () const = 0;
53+ virtual bool hasError () const = 0;
5454 virtual bool isEndOfInput () const = 0;
5555
5656 // / Read in a message from the input stream.
57- virtual LogicalResult readMessage (std::string &json) {
57+ LogicalResult readMessage (std::string &json) {
5858 return style == JSONStreamStyle::Delimited ? readDelimitedMessage (json)
5959 : readStandardMessage (json);
6060 }
@@ -66,23 +66,14 @@ class JSONTransportInput {
6666 JSONStreamStyle style;
6767};
6868
69- // / An abstract class used by the JSONTransport to write JSON messages.
70- class JSONTransportOutput {
71- public:
72- explicit JSONTransportOutput () = default;
73- virtual ~JSONTransportOutput () = default ;
74-
75- virtual void sendMessage (const llvm::json::Value &msg) = 0;
76- };
77-
7869// / Concrete implementation of the JSONTransportInput that reads from a file.
7970class JSONTransportInputOverFile : public JSONTransportInput {
8071public:
8172 explicit JSONTransportInputOverFile (
8273 std::FILE *in, JSONStreamStyle style = JSONStreamStyle::Standard)
8374 : JSONTransportInput(style), in(in) {}
8475
85- bool getError () const final { return ferror (in); }
76+ bool hasError () const final { return ferror (in); }
8677 bool isEndOfInput () const final { return feof (in); }
8778
8879 LogicalResult readDelimitedMessage (std::string &json) final ;
@@ -92,37 +83,19 @@ class JSONTransportInputOverFile : public JSONTransportInput {
9283 std::FILE *in;
9384};
9485
95- // / Concrete implementation of the JSONTransportOutput that writes to a stream.
96- class JSONTransportOutputOverStream : public JSONTransportOutput {
97- public:
98- explicit JSONTransportOutputOverStream (raw_ostream &out,
99- bool prettyOutput = false )
100- : JSONTransportOutput(), out(out), prettyOutput(prettyOutput) {}
101-
102- // / Writes the given message to the output stream.
103- void sendMessage (const llvm::json::Value &msg) final ;
104-
105- private:
106- SmallVector<char , 0 > outputBuffer;
107- raw_ostream &out;
108- // / If the output JSON should be formatted for easier readability.
109- bool prettyOutput;
110- };
111-
11286// / A transport class that performs the JSON-RPC communication with the LSP
11387// / client.
11488class JSONTransport {
11589public:
116- JSONTransport (std::unique_ptr<JSONTransportInput> in,
117- std::unique_ptr<JSONTransportOutput> out )
118- : in(std::move(in)), out(std::move( out)) {}
90+ JSONTransport (std::unique_ptr<JSONTransportInput> in, raw_ostream &out,
91+ bool prettyOutput = false )
92+ : in(std::move(in)), out(out), prettyOutput(prettyOutput ) {}
11993
12094 JSONTransport (std::FILE *in, raw_ostream &out,
12195 JSONStreamStyle style = JSONStreamStyle::Standard,
12296 bool prettyOutput = false )
123- : in(std::make_unique<JSONTransportInputOverFile>(in, style)),
124- out (std::make_unique<JSONTransportOutputOverStream>(out,
125- prettyOutput)) {}
97+ : in(std::make_unique<JSONTransportInputOverFile>(in, style)), out(out),
98+ prettyOutput (prettyOutput) {}
12699
127100 // / The following methods are used to send a message to the LSP client.
128101 void notify (StringRef method, llvm::json::Value params);
@@ -132,15 +105,20 @@ class JSONTransport {
132105 // / Start executing the JSON-RPC transport.
133106 llvm::Error run (MessageHandler &handler);
134107
108+ private:
135109 // / Dispatches the given incoming json message to the message handler.
136110 bool handleMessage (llvm::json::Value msg, MessageHandler &handler);
111+ // / Writes the given message to the output stream.
112+ void sendMessage (llvm::json::Value msg);
137113
138114private:
139115 // / The input to read a message from.
140116 std::unique_ptr<JSONTransportInput> in;
141-
142- // / The output to send a messages to.
143- std::unique_ptr<JSONTransportOutput> out;
117+ SmallVector<char , 0 > outputBuffer;
118+ // / The output file stream.
119+ raw_ostream &out;
120+ // / If the output JSON should be formatted for easier readability.
121+ bool prettyOutput;
144122};
145123
146124// ===----------------------------------------------------------------------===//
0 commit comments