feat(startup): Source runtime/plugin/**/*.lua at startup

For opt plugins these files are sourced on `:packadd`

* `:runtime` Now can exexute lua files
This commit is contained in:
shadmansaleh
2021-05-31 17:35:13 +06:00
parent 1df8a34a7b
commit 687eb0b39f
7 changed files with 103 additions and 21 deletions

View File

@@ -15,6 +15,7 @@
#include "nvim/misc1.h"
#include "nvim/os/os.h"
#include "nvim/runtime.h"
#include "nvim/lua/executor.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "runtime.c.generated.h"
@@ -49,7 +50,11 @@ void ex_runtime(exarg_T *eap)
static void source_callback(char_u *fname, void *cookie)
{
(void)do_source(fname, false, DOSO_NONE);
if (path_with_extension((const char *)fname, "lua")) {
nlua_exec_file((const char *)fname);
} else {
(void)do_source(fname, false, DOSO_NONE);
}
}
/// Find the file "name" in all directories in "path" and invoke
@@ -245,7 +250,8 @@ int source_in_path(char_u *path, char_u *name, int flags)
return do_in_path_and_pp(path, name, flags, source_callback, NULL);
}
// Expand wildcards in "pat" and invoke do_source() for each match.
// Expand wildcards in "pat" and invoke do_source()/nlua_exec_file()
// for each match.
static void source_all_matches(char_u *pat)
{
int num_files;
@@ -253,7 +259,11 @@ static void source_all_matches(char_u *pat)
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) {
for (int i = 0; i < num_files; i++) {
(void)do_source(files[i], false, DOSO_NONE);
if (path_with_extension((const char *)files[i], "lua")) {
nlua_exec_file((const char *)files[i]);
} else {
(void)do_source(files[i], false, DOSO_NONE);
}
}
FreeWild(num_files, files);
}
@@ -405,17 +415,15 @@ theend:
/// Load scripts in "plugin" and "ftdetect" directories of the package.
static int load_pack_plugin(char_u *fname)
{
static const char *plugpat = "%s/plugin/**/*.vim"; // NOLINT
static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT
int retval = FAIL;
char *const ffname = fix_fname((char *)fname);
size_t len = strlen(ffname) + STRLEN(ftpat);
char_u *pat = try_malloc(len + 1);
if (pat == NULL) {
goto theend;
}
vim_snprintf((char *)pat, len, plugpat, ffname);
char_u *pat = xmallocz(len);
vim_snprintf((char *)pat, len, "%s/plugin/**/*.vim", ffname);
source_all_matches(pat);
vim_snprintf((char *)pat, len, "%s/plugin/**/*.lua", ffname);
source_all_matches(pat);
char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes");
@@ -430,12 +438,9 @@ static int load_pack_plugin(char_u *fname)
}
xfree(cmd);
xfree(pat);
retval = OK;
theend:
xfree(ffname);
return retval;
return OK;
}
// used for "cookie" of add_pack_plugin()