some update.

This commit is contained in:
ykiko
2024-07-06 23:30:58 +08:00
parent 851e3a0d44
commit 1e64c6eb78
10 changed files with 142 additions and 149 deletions

View 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

View File

@@ -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

View File

@@ -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();