mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 03:46:31 +00:00
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.
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user