Mercurial > vim
diff src/vim9compile.c @ 27043:15f40772e10a v8.2.4050
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Commit: https://github.com/vim/vim/commit/dc4451df61a6aa12a0661817b7094fb32f09e11d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 9 21:36:37 2022 +0000
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Problem: Vim9: need to prefix every item in an autoload script.
Solution: First step in supporting "vim9script autoload" and "import
autoload".
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Jan 2022 22:45:04 +0100 |
parents | 18cafa092e8d |
children | f17bdc9cda64 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -268,7 +268,7 @@ variable_exists(char_u *name, size_t len && (lookup_local(name, len, NULL, cctx) == OK || arg_exists(name, len, NULL, NULL, NULL, cctx) == OK)) || script_var_exists(name, len, cctx) == OK - || find_imported(name, len, cctx) != NULL; + || find_imported(name, len, FALSE, cctx) != NULL; } /* @@ -331,7 +331,7 @@ check_defined(char_u *p, size_t len, cct if ((cctx != NULL && (lookup_local(p, len, NULL, cctx) == OK || arg_exists(p, len, NULL, NULL, NULL, cctx) == OK)) - || find_imported(p, len, cctx) != NULL + || find_imported(p, len, FALSE, cctx) != NULL || (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL) { // A local or script-local function can shadow a global function. @@ -581,11 +581,13 @@ find_imported_in_script(char_u *name, si /* * Find "name" in imported items of the current script or in "cctx" if not * NULL. + * If "load" is TRUE and the script was not loaded yet, load it now. */ imported_T * -find_imported(char_u *name, size_t len, cctx_T *cctx) +find_imported(char_u *name, size_t len, int load, cctx_T *cctx) { int idx; + imported_T *ret = NULL; if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) return NULL; @@ -598,10 +600,23 @@ find_imported(char_u *name, size_t len, if (len == 0 ? STRCMP(name, import->imp_name) == 0 : STRLEN(import->imp_name) == len && STRNCMP(name, import->imp_name, len) == 0) - return import; + { + ret = import; + break; + } } - return find_imported_in_script(name, len, current_sctx.sc_sid); + if (ret == NULL) + ret = find_imported_in_script(name, len, current_sctx.sc_sid); + + if (ret != NULL && load && ret->imp_flags == IMP_FLAGS_AUTOLOAD) + { + // script found before but not loaded yet + ret->imp_flags = 0; + (void)do_source(SCRIPT_ITEM(ret->imp_sid)->sn_name, FALSE, + DOSO_NONE, NULL); + } + return ret; } /* @@ -1326,7 +1341,7 @@ compile_lhs( : script_var_exists(var_start, lhs->lhs_varlen, cctx)) == OK; imported_T *import = - find_imported(var_start, lhs->lhs_varlen, cctx); + find_imported(var_start, lhs->lhs_varlen, FALSE, cctx); if (script_namespace || script_var || import != NULL) {