some update.
This commit is contained in:
37
include/LSP/MessageBuffer.h
Normal file
37
include/LSP/MessageBuffer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
|
||||
namespace clice {
|
||||
|
||||
class MessageBuffer {
|
||||
std::vector<char> buffer;
|
||||
std::size_t max = 0;
|
||||
|
||||
public:
|
||||
void write(std::string_view message) { buffer.insert(buffer.end(), message.begin(), message.end()); }
|
||||
|
||||
std::string_view read() {
|
||||
std::string_view view = std::string_view(buffer.data(), buffer.size());
|
||||
auto start = view.find("Content-Length: ") + 16;
|
||||
auto end = view.find("\r\n\r\n");
|
||||
|
||||
if(start != std::string_view::npos || end != std::string_view::npos) {
|
||||
std::size_t length = std::stoul(std::string(view.substr(start, end - start)));
|
||||
if(view.size() >= length + end + 4) {
|
||||
this->max = length + end + 4;
|
||||
return view.substr(end + 4, length);
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if(max != 0) {
|
||||
buffer.erase(buffer.begin(), buffer.begin() + max);
|
||||
max = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace clice
|
||||
@@ -481,7 +481,7 @@ struct ServerCapabilities {
|
||||
/// If omitted it defaults to 'utf-16'.
|
||||
///
|
||||
/// possible values: ['utf-8', 'utf-16', 'utf-32'] in PositionEncodingKind
|
||||
std::string_view positionEncoding = PositionEncodingKind::UTF8;
|
||||
std::string_view positionEncoding = PositionEncodingKind::UTF16;
|
||||
|
||||
/// Defines how text documents are synced. Is either a detailed structure
|
||||
/// defining each notification or for backwards compatibility the
|
||||
|
||||
@@ -10,6 +10,7 @@ extern class Server server;
|
||||
class Server {
|
||||
uv_loop_t* loop;
|
||||
uv_pipe_t stdin_pipe;
|
||||
uv_pipe_t stdout_pipe;
|
||||
|
||||
public:
|
||||
int start();
|
||||
|
||||
Reference in New Issue
Block a user