mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 15:08:35 +00:00
Remove os/provider.{c,h} and all of its references
This commit is contained in:
@@ -7,7 +7,6 @@
|
|||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/handle.h"
|
#include "nvim/api/private/handle.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
@@ -548,7 +547,6 @@ Dictionary api_metadata(void)
|
|||||||
msgpack_rpc_init_function_metadata(&metadata);
|
msgpack_rpc_init_function_metadata(&metadata);
|
||||||
init_error_type_metadata(&metadata);
|
init_error_type_metadata(&metadata);
|
||||||
init_type_metadata(&metadata);
|
init_type_metadata(&metadata);
|
||||||
provider_init_feature_metadata(&metadata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary;
|
return copy_object(DICTIONARY_OBJ(metadata)).data.dictionary;
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/buffer.h"
|
#include "nvim/api/buffer.h"
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
@@ -538,22 +537,6 @@ void vim_unsubscribe(uint64_t channel_id, String event)
|
|||||||
channel_unsubscribe(channel_id, e);
|
channel_unsubscribe(channel_id, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers the channel as the provider for `feature`. This fails if
|
|
||||||
/// a provider for `feature` is already provided by another channel.
|
|
||||||
///
|
|
||||||
/// @param channel_id The channel id
|
|
||||||
/// @param feature The feature name
|
|
||||||
/// @param[out] err Details of an error that may have occurred
|
|
||||||
void vim_register_provider(uint64_t channel_id, String feature, Error *err)
|
|
||||||
{
|
|
||||||
char buf[METHOD_MAXLEN];
|
|
||||||
xstrlcpy(buf, feature.data, sizeof(buf));
|
|
||||||
|
|
||||||
if (!provider_register(buf, channel_id)) {
|
|
||||||
api_set_error(err, Validation, _("Feature doesn't exist"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Array vim_get_api_info(uint64_t channel_id)
|
Array vim_get_api_info(uint64_t channel_id)
|
||||||
{
|
{
|
||||||
Array rv = ARRAY_DICT_INIT;
|
Array rv = ARRAY_DICT_INIT;
|
||||||
|
@@ -89,7 +89,6 @@
|
|||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/vim.h"
|
#include "nvim/api/vim.h"
|
||||||
#include "nvim/os/dl.h"
|
#include "nvim/os/dl.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/os/event.h"
|
#include "nvim/os/event.h"
|
||||||
|
|
||||||
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
|
#define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
|
||||||
|
@@ -55,7 +55,6 @@
|
|||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
#include "nvim/os/shell.h"
|
#include "nvim/os/shell.h"
|
||||||
#include "nvim/os/fs_defs.h"
|
#include "nvim/os/fs_defs.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
|
|
||||||
|
@@ -48,7 +48,6 @@
|
|||||||
#include "nvim/ui.h"
|
#include "nvim/ui.h"
|
||||||
#include "nvim/undo.h"
|
#include "nvim/undo.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
#include "nvim/msgpack_rpc/channel.h"
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
#include "nvim/msgpack_rpc/server.h"
|
#include "nvim/msgpack_rpc/server.h"
|
||||||
#include "nvim/msgpack_rpc/helpers.h"
|
#include "nvim/msgpack_rpc/helpers.h"
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/os/signal.h"
|
#include "nvim/os/signal.h"
|
||||||
#include "nvim/os/rstream.h"
|
#include "nvim/os/rstream.h"
|
||||||
#include "nvim/os/wstream.h"
|
#include "nvim/os/wstream.h"
|
||||||
@@ -62,8 +61,6 @@ void event_init(void)
|
|||||||
// finish mspgack-rpc initialization
|
// finish mspgack-rpc initialization
|
||||||
channel_init();
|
channel_init();
|
||||||
server_init();
|
server_init();
|
||||||
// Providers
|
|
||||||
provider_init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_teardown(void)
|
void event_teardown(void)
|
||||||
|
@@ -1,152 +0,0 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "nvim/os/provider.h"
|
|
||||||
#include "nvim/memory.h"
|
|
||||||
#include "nvim/api/vim.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
|
||||||
#include "nvim/api/private/defs.h"
|
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
|
||||||
#include "nvim/os/shell.h"
|
|
||||||
#include "nvim/os/os.h"
|
|
||||||
#include "nvim/log.h"
|
|
||||||
#include "nvim/map.h"
|
|
||||||
#include "nvim/message.h"
|
|
||||||
|
|
||||||
#define FEATURE_COUNT (sizeof(features) / sizeof(features[0]))
|
|
||||||
|
|
||||||
#define FEATURE(feature_name, ...) { \
|
|
||||||
.name = feature_name, \
|
|
||||||
.channel_id = 0, \
|
|
||||||
.methods = (char *[]){__VA_ARGS__, NULL} \
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char *name, **methods;
|
|
||||||
size_t name_length;
|
|
||||||
uint64_t channel_id;
|
|
||||||
} Feature;
|
|
||||||
|
|
||||||
static Feature features[] = {
|
|
||||||
FEATURE("python",
|
|
||||||
"python_execute",
|
|
||||||
"python_execute_file",
|
|
||||||
"python_do_range",
|
|
||||||
"python_eval"),
|
|
||||||
|
|
||||||
FEATURE("clipboard",
|
|
||||||
"clipboard_get",
|
|
||||||
"clipboard_set")
|
|
||||||
};
|
|
||||||
|
|
||||||
static PMap(cstr_t) *registered_providers = NULL;
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
|
||||||
# include "os/provider.c.generated.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void provider_init(void)
|
|
||||||
{
|
|
||||||
registered_providers = pmap_new(cstr_t)();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool provider_has_feature(char *name)
|
|
||||||
{
|
|
||||||
Feature *f = find_feature(name);
|
|
||||||
return f != NULL && channel_exists(f->channel_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool provider_register(char *name, uint64_t channel_id)
|
|
||||||
{
|
|
||||||
Feature *f = find_feature(name);
|
|
||||||
|
|
||||||
if (!f) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f->channel_id && channel_exists(f->channel_id)) {
|
|
||||||
ILOG("Feature \"%s\" is already provided by another channel"
|
|
||||||
"(will be replaced)", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG("Registering provider for \"%s\"", name);
|
|
||||||
f->channel_id = channel_id;
|
|
||||||
|
|
||||||
// Associate all method names with the feature struct
|
|
||||||
size_t i;
|
|
||||||
char *method;
|
|
||||||
for (method = f->methods[i = 0]; method; method = f->methods[++i]) {
|
|
||||||
pmap_put(cstr_t)(registered_providers, method, f);
|
|
||||||
DLOG("Channel \"%" PRIu64 "\" will be sent requests for \"%s\"",
|
|
||||||
channel_id,
|
|
||||||
method);
|
|
||||||
}
|
|
||||||
|
|
||||||
ILOG("Registered channel %" PRIu64 " as the provider for the \"%s\" feature",
|
|
||||||
channel_id,
|
|
||||||
name);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object provider_call(char *method, Array args)
|
|
||||||
{
|
|
||||||
Feature *f = pmap_get(cstr_t)(registered_providers, method);
|
|
||||||
|
|
||||||
if (!f || !channel_exists(f->channel_id)) {
|
|
||||||
char buf[256];
|
|
||||||
snprintf(buf,
|
|
||||||
sizeof(buf),
|
|
||||||
"Provider for method \"%s\" is not available",
|
|
||||||
method);
|
|
||||||
vim_report_error(cstr_as_string(buf));
|
|
||||||
api_free_array(args);
|
|
||||||
return NIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Error err = ERROR_INIT;
|
|
||||||
Object result = NIL = channel_send_call(f->channel_id, method, args, &err);
|
|
||||||
|
|
||||||
if (err.set) {
|
|
||||||
vim_report_error(cstr_as_string(err.msg));
|
|
||||||
api_free_object(result);
|
|
||||||
return NIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void provider_init_feature_metadata(Dictionary *metadata)
|
|
||||||
{
|
|
||||||
Dictionary md = ARRAY_DICT_INIT;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < FEATURE_COUNT; i++) {
|
|
||||||
Array methods = ARRAY_DICT_INIT;
|
|
||||||
Feature *f = &features[i];
|
|
||||||
|
|
||||||
size_t j;
|
|
||||||
char *method;
|
|
||||||
for (method = f->methods[j = 0]; method; method = f->methods[++j]) {
|
|
||||||
ADD(methods, STRING_OBJ(cstr_to_string(method)));
|
|
||||||
}
|
|
||||||
|
|
||||||
PUT(md, f->name, ARRAY_OBJ(methods));
|
|
||||||
}
|
|
||||||
|
|
||||||
PUT(*metadata, "features", DICTIONARY_OBJ(md));
|
|
||||||
}
|
|
||||||
|
|
||||||
static Feature * find_feature(char *name)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < FEATURE_COUNT; i++) {
|
|
||||||
Feature *f = &features[i];
|
|
||||||
if (!STRICMP(name, f->name)) {
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
#ifndef NVIM_OS_PROVIDER_H
|
|
||||||
#define NVIM_OS_PROVIDER_H
|
|
||||||
|
|
||||||
#include "nvim/api/private/defs.h"
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
|
||||||
# include "os/provider.h.generated.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // NVIM_OS_PROVIDER_H
|
|
||||||
|
|
Reference in New Issue
Block a user