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();
|
||||
|
||||
7
include/Support/Filesystem.h
Normal file
7
include/Support/Filesystem.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
namespace clice {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
}
|
||||
@@ -123,40 +123,31 @@ constexpr auto collcet_members(Object&& object) {
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u};
|
||||
} else if constexpr(count == 22) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k,
|
||||
&l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v};
|
||||
} else if constexpr(count == 23) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l,
|
||||
&m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w};
|
||||
} else if constexpr(count == 24) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l,
|
||||
&m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x};
|
||||
} else if constexpr(count == 25) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m,
|
||||
&n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y};
|
||||
} else if constexpr(count == 26) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m,
|
||||
&n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z};
|
||||
} else if constexpr(count == 27) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
|
||||
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0};
|
||||
} else if constexpr(count == 28) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
|
||||
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1};
|
||||
} else if constexpr(count == 29) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1, _2] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
|
||||
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2};
|
||||
} else if constexpr(count == 30) {
|
||||
auto&& [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, _0, _1, _2, _3] = object;
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n,
|
||||
&o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2, &_3};
|
||||
return std::tuple{&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &k, &l, &m, &n, &o, &p, &q, &r, &s, &t, &u, &v, &w, &x, &y, &z, &_0, &_1, &_2, &_3};
|
||||
} else {
|
||||
static_assert(count <= 30, "Not supported member count");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "Reflection.h"
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace clice {
|
||||
#include <Support/Reflection.h>
|
||||
|
||||
namespace clice::impl {
|
||||
|
||||
template <typename T>
|
||||
constexpr inline bool is_optional_v = false;
|
||||
@@ -19,36 +19,36 @@ constexpr inline bool is_vector_like_v<std::array<T, N>> = true;
|
||||
template <typename T>
|
||||
constexpr inline bool is_vector_like_v<std::vector<T>> = true;
|
||||
|
||||
} // namespace clice::impl
|
||||
|
||||
namespace clice {
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
template <typename Object>
|
||||
void print(Object&& object) {
|
||||
using T = std::decay_t<Object>;
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
std::cout << (object ? "true" : "false") << std::endl;
|
||||
} else if constexpr(std::is_integral_v<T> || std::is_floating_point_v<T> ||
|
||||
std::is_same_v<T, std::string> || std::is_same_v<T, std::string_view>) {
|
||||
std::cout << object << std::endl;
|
||||
} else if constexpr(std::is_enum_v<T>) {
|
||||
std::cout << static_cast<std::underlying_type_t<T>>(object) << std::endl;
|
||||
} else if constexpr(is_optional_v<T>) {
|
||||
if(object.has_value()) {
|
||||
print(object.value());
|
||||
} else {
|
||||
std::cout << "null" << std::endl;
|
||||
}
|
||||
} else if constexpr(is_vector_like_v<T>) {
|
||||
std::cout << "[" << std::endl;
|
||||
for(auto&& value: object) {
|
||||
print(value);
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
auto serialize(const Object& object) {
|
||||
if constexpr(std::is_fundamental_v<Object> || std::is_same_v<Object, std::string_view> ||
|
||||
std::is_same_v<Object, std::string>) {
|
||||
return json(object);
|
||||
} else if constexpr(impl::is_vector_like_v<Object>) {
|
||||
return json(object);
|
||||
} else if constexpr(std::is_enum_v<Object>) {
|
||||
return static_cast<std::underlying_type_t<Object>>(object);
|
||||
} else {
|
||||
std::cout << "{" << std::endl;
|
||||
for_each(object, [&](auto&& name, auto&& value) {
|
||||
std::cout << name << ": ";
|
||||
print(value);
|
||||
json json;
|
||||
for_each(object, [&json](std::string_view name, auto& member) {
|
||||
using Member = std::remove_cvref_t<decltype(member)>;
|
||||
if constexpr(impl::is_optional_v<Member>) {
|
||||
if(member.has_value()) {
|
||||
json.emplace(name, serialize(member.value()));
|
||||
}
|
||||
} else {
|
||||
json.emplace(name, serialize(member));
|
||||
}
|
||||
});
|
||||
std::cout << "}" << std::endl;
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace clice
|
||||
|
||||
|
||||
Reference in New Issue
Block a user