@@ -50,11 +50,11 @@ class JSONTransportInput {
50
50
: style(style) {}
51
51
virtual ~JSONTransportInput () = default ;
52
52
53
- virtual bool getError () const = 0;
53
+ virtual bool hasError () const = 0;
54
54
virtual bool isEndOfInput () const = 0;
55
55
56
56
// / Read in a message from the input stream.
57
- virtual LogicalResult readMessage (std::string &json) {
57
+ LogicalResult readMessage (std::string &json) {
58
58
return style == JSONStreamStyle::Delimited ? readDelimitedMessage (json)
59
59
: readStandardMessage (json);
60
60
}
@@ -66,23 +66,14 @@ class JSONTransportInput {
66
66
JSONStreamStyle style;
67
67
};
68
68
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
-
78
69
// / Concrete implementation of the JSONTransportInput that reads from a file.
79
70
class JSONTransportInputOverFile : public JSONTransportInput {
80
71
public:
81
72
explicit JSONTransportInputOverFile (
82
73
std::FILE *in, JSONStreamStyle style = JSONStreamStyle::Standard)
83
74
: JSONTransportInput(style), in(in) {}
84
75
85
- bool getError () const final { return ferror (in); }
76
+ bool hasError () const final { return ferror (in); }
86
77
bool isEndOfInput () const final { return feof (in); }
87
78
88
79
LogicalResult readDelimitedMessage (std::string &json) final ;
@@ -92,37 +83,19 @@ class JSONTransportInputOverFile : public JSONTransportInput {
92
83
std::FILE *in;
93
84
};
94
85
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
-
112
86
// / A transport class that performs the JSON-RPC communication with the LSP
113
87
// / client.
114
88
class JSONTransport {
115
89
public:
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 ) {}
119
93
120
94
JSONTransport (std::FILE *in, raw_ostream &out,
121
95
JSONStreamStyle style = JSONStreamStyle::Standard,
122
96
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) {}
126
99
127
100
// / The following methods are used to send a message to the LSP client.
128
101
void notify (StringRef method, llvm::json::Value params);
@@ -132,15 +105,20 @@ class JSONTransport {
132
105
// / Start executing the JSON-RPC transport.
133
106
llvm::Error run (MessageHandler &handler);
134
107
108
+ private:
135
109
// / Dispatches the given incoming json message to the message handler.
136
110
bool handleMessage (llvm::json::Value msg, MessageHandler &handler);
111
+ // / Writes the given message to the output stream.
112
+ void sendMessage (llvm::json::Value msg);
137
113
138
114
private:
139
115
// / The input to read a message from.
140
116
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;
144
122
};
145
123
146
124
// ===----------------------------------------------------------------------===//
0 commit comments