mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
provider: Add support functions for calling external interpreters
This uses the provider module infrastructure to implement common code for vimscript commands/functions that need to communicate with external interpreters, eg: pydo, rubydo, pyfile, rubyfile, etc.
This commit is contained in:
@@ -83,6 +83,7 @@
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/os/channel.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/os/msgpack_rpc_helpers.h"
|
||||
#include "nvim/os/dl.h"
|
||||
#include "nvim/os/provider.h"
|
||||
@@ -19125,3 +19126,20 @@ static void apply_job_autocmds(Job *job, char *name, char *type, char *str)
|
||||
apply_autocmds(EVENT_JOBACTIVITY, (uint8_t *)name, NULL, TRUE, NULL);
|
||||
}
|
||||
|
||||
static void script_host_eval(char *method, typval_T *argvars, typval_T *rettv)
|
||||
{
|
||||
Object result = provider_call(method, vim_to_object(argvars));
|
||||
|
||||
if (result.type == kObjectTypeNil) {
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = {.set = false};
|
||||
object_to_vim(result, rettv, &err);
|
||||
msgpack_rpc_free_object(result);
|
||||
|
||||
if (err.set) {
|
||||
EMSG("Error converting value back to vim");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -54,6 +54,10 @@
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/shell.h"
|
||||
#include "nvim/os/fs_defs.h"
|
||||
#include "nvim/os/provider.h"
|
||||
#include "nvim/os/msgpack_rpc_helpers.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
#include "nvim/api/private/defs.h"
|
||||
|
||||
|
||||
/* Growarray to store info about already sourced scripts.
|
||||
@@ -3219,3 +3223,40 @@ char_u *get_locales(expand_T *xp, int idx)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static void script_host_execute(char *method, exarg_T *eap)
|
||||
{
|
||||
char *script = (char *)script_get(eap, eap->arg);
|
||||
|
||||
if (!eap->skip) {
|
||||
String str = cstr_to_string(script ? script : (char *)eap->arg);
|
||||
Object result = provider_call(method, STRING_OBJ(str));
|
||||
// We don't care about the result, so free it just in case a bad provider
|
||||
// returned something
|
||||
msgpack_rpc_free_object(result);
|
||||
}
|
||||
|
||||
free(script);
|
||||
}
|
||||
|
||||
static void script_host_execute_file(char *method, exarg_T *eap)
|
||||
{
|
||||
char buffer[MAXPATHL];
|
||||
vim_FullName(eap->arg, (uint8_t *)buffer, sizeof(buffer), false);
|
||||
|
||||
String file = cstr_to_string(buffer);
|
||||
Object result = provider_call(method, STRING_OBJ(file));
|
||||
msgpack_rpc_free_object(result);
|
||||
}
|
||||
|
||||
static void script_host_do_range(char *method, exarg_T *eap)
|
||||
{
|
||||
Array arg = {0, 0, 0};
|
||||
ADD(arg, INTEGER_OBJ(eap->line1));
|
||||
ADD(arg, INTEGER_OBJ(eap->line2));
|
||||
ADD(arg, STRING_OBJ(cstr_to_string((char *)eap->arg)));
|
||||
Object result = provider_call(method, ARRAY_OBJ(arg));
|
||||
msgpack_rpc_free_object(result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user