Skip to content

Commit a138d07

Browse files
committed
Update to neovim api 4
Signed-off-by: Squareys <squareys@googlemail.com>
1 parent 14011d1 commit a138d07

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ add_custom_target(generate ALL
3838
-t ${CMAKE_SOURCE_DIR}/template
3939
-o ${CMAKE_CURRENT_BINARY_DIR}
4040
)
41-
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/neovimapi2.cpp PROPERTIES GENERATED TRUE)
41+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/neovimapi4.cpp PROPERTIES GENERATED TRUE)
4242

4343
# Compile generated sources to a static lib
44-
add_library(NeovimApi STATIC ${CMAKE_CURRENT_BINARY_DIR}/neovimapi2.cpp)
44+
add_library(NeovimApi STATIC ${CMAKE_CURRENT_BINARY_DIR}/neovimapi4.cpp)
4545
target_link_libraries(NeovimApi Magnum::Magnum CorradeNet Corrade::Containers mpack)
4646
target_compile_features(NeovimApi PRIVATE cxx_std_17)
4747
add_dependencies(NeovimApi generate)

src/Test/NeoVimApiTest.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include "Corrade/Net/Socket.h"
3232

33-
#include "neovimapi2.h"
33+
#include "neovimapi4.h"
3434

3535
namespace NeovimApi {
3636

@@ -39,6 +39,7 @@ using namespace Magnum;
3939

4040
struct Test: TestSuite::Tester {
4141
explicit Test();
42+
~Test();
4243

4344
void test();
4445

@@ -50,11 +51,16 @@ Test::Test() {
5051
&Test::test,
5152
&Test::testGenerated
5253
});
54+
55+
// TODO find neovim executable
56+
//std::system("nvim.exe --headless -c \"call serverstart('127.0.0.1:6666')\" &");
5357
}
5458

55-
void Test::test() {
56-
// ./nvim.exe --headless -c "call serverstart('127.0.0.1:6666')"
59+
Test::~Test() {
60+
//std::system("killall nvim.exe");
61+
}
5762

63+
void Test::test() {
5864
char* buffer = nullptr;
5965
size_t size = 0;
6066
mpack_writer_t writer;
@@ -107,7 +113,7 @@ void Test::test() {
107113
}
108114

109115
void Test::testGenerated() {
110-
NeovimApi::NeovimApi2 nvim{6666};
116+
NeovimApi::NeovimApi4 nvim{6666};
111117
Object o = nvim.nvim_eval("'hello' . 'world!\n'");
112118
CORRADE_COMPARE("helloworld!\n", o.s);
113119

template/neovimapi.cpp

+6-11
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ void mpack_write(mpack_writer_t* writer, const std::unordered_map<std::string, O
4242
mpack_finish_map(writer);
4343
}
4444

45-
template<typename T>
46-
void mpack_write(mpack_writer_t*) {
47-
mpack_start_array(writer, data.size());
48-
for(const auto& e : data) {
49-
mpack_write(writer, e);
50-
}
51-
mpack_finish_array(writer);
52-
}
53-
5445
Object mpack_read_object(mpack_reader_t* reader) {
5546
Object result{};
5647
const mpack_tag_t tag = mpack_peek_tag(reader);
@@ -150,6 +141,10 @@ template<>
150141
Containers::Array<std::string> mpack_read<Containers::Array<std::string>>(mpack_reader_t* reader) {
151142
return mpack_read_array<std::string>(reader);
152143
}
144+
template<>
145+
Containers::Array<std::unordered_map<std::string, Object>> mpack_read<Containers::Array<std::unordered_map<std::string, Object>>>(mpack_reader_t* reader) {
146+
return mpack_read_array<std::unordered_map<std::string, Object>>(reader);
147+
}
153148

154149
NeovimApi{{api_level}}::NeovimApi{{api_level}}(int port, int receiveBufferSize):
155150
NeovimApi{{api_level}}{"127.0.0.1", port, receiveBufferSize}
@@ -186,7 +181,7 @@ Int NeovimApi{{api_level}}::dispatch(const std::string& func, Args... args) {
186181
return msgId;
187182
}
188183

189-
std::unique_ptr<Notification> NeovimApi2::waitForNotification(Int timeout) {
184+
std::unique_ptr<Notification> NeovimApi{{api_level}}::waitForNotification(Int timeout) {
190185
if(!_notifications.empty()) {
191186
/* Move notification to heap */
192187
auto n = std::move(_notifications.front());
@@ -203,7 +198,7 @@ std::unique_ptr<Notification> NeovimApi2::waitForNotification(Int timeout) {
203198
return std::make_unique<Notification>(Containers::Array<char>(nullptr));
204199
}
205200
if(response.size() == _receiveBuffer.size()) {
206-
Warning() << "NeovimApi2::waitForResponse(): Receive buffer was full";
201+
Warning() << "NeovimApi{{api_level}}::waitForResponse(): Receive buffer was full";
207202
// TODO: Handle requests over multiple buffers
208203
}
209204

0 commit comments

Comments
 (0)