From f17668234a5bcd1905775436da9cf0e136bb8150 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 26 Jun 2014 15:29:38 -0300 Subject: api: Refactor write_msg to use separate out/err buffers --- src/nvim/api/vim.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 03b9257d79..9834633813 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -512,23 +512,24 @@ void vim_unsubscribe(uint64_t channel_id, String event) /// `emsg` instead of `msg` to print each line) static void write_msg(String message, bool to_err) { - static int pos = 0; - static char line_buf[LINE_BUFFER_SIZE]; + static int out_pos = 0, err_pos = 0; + static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; + +#define PUSH_CHAR(i, pos, line_buf, msg) \ + if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ + line_buf[pos] = NUL; \ + msg((uint8_t *)line_buf); \ + pos = 0; \ + continue; \ + } \ + \ + line_buf[pos++] = message.data[i]; for (uint32_t i = 0; i < message.size; i++) { - if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { - // Flush line - line_buf[pos] = NUL; - if (to_err) { - emsg((uint8_t *)line_buf); - } else { - msg((uint8_t *)line_buf); - } - - pos = 0; - continue; + if (to_err) { + PUSH_CHAR(i, err_pos, err_line_buf, emsg); + } else { + PUSH_CHAR(i, out_pos, out_line_buf, msg); } - - line_buf[pos++] = message.data[i]; } } -- cgit From 887d32e54672cc3957bd2977df92fc3e9de10a52 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 26 Jun 2014 18:10:05 -0300 Subject: provider: New module used to expose extension points for core services Introducing the concept of providers: co-processes that talk with the editor through the remote API and provide implementation for one or more core services. The `provider_register` function and it's API wrapper can be used by channels that want to self-register as a service provider. Some old builtin vim features will be re-implemented as providers. The `provider_has_feature` function is used to check if a provider implementing a certain feature is available(It will be called by the `has` vimscript function to check for features in a vim-compatible way) This implements the provider module without exposing any extension points, which will be done in future commits. --- src/nvim/api/vim.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/nvim/api/vim.c') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9834633813..6c793cbc54 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -10,6 +10,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/buffer.h" #include "nvim/os/channel.h" +#include "nvim/os/provider.h" #include "nvim/vim.h" #include "nvim/buffer.h" #include "nvim/window.h" @@ -503,6 +504,22 @@ void vim_unsubscribe(uint64_t channel_id, String event) channel_unsubscribe(channel_id, e); } +/// Registers the channel as the provider for `method`. This fails if +/// a provider for `method` is already registered. +/// +/// @param channel_id The channel id +/// @param method The method name +/// @param[out] err Details of an error that may have occurred +void vim_register_provider(uint64_t channel_id, String method, Error *err) +{ + char buf[METHOD_MAXLEN]; + xstrlcpy(buf, method.data, sizeof(buf)); + + if (!provider_register(buf, channel_id)) { + set_api_error("Provider already registered", err); + } +} + /// Writes a message to vim output or error buffer. The string is split /// and flushed after each newline. Incomplete lines are kept for writing /// later. -- cgit