mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.2.4063: Vim9: exported function in autoload script not found
Problem: Vim9: exported function in autoload script not found. (Yegappan Lakshmanan) Solution: Use the autoload prefix to search for the function.
This commit is contained in:
@@ -1146,8 +1146,8 @@ def Test_vim9script_autoload()
|
|||||||
return 'test'
|
return 'test'
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
export func GetSome()
|
export func GetMore()
|
||||||
return 'some'
|
return Gettest() .. 'more'
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
export var name = 'name'
|
export var name = 'name'
|
||||||
@@ -1163,7 +1163,7 @@ def Test_vim9script_autoload()
|
|||||||
assert_equal('test', prefixed.Gettest())
|
assert_equal('test', prefixed.Gettest())
|
||||||
assert_equal('yes', g:prefixed_loaded)
|
assert_equal('yes', g:prefixed_loaded)
|
||||||
|
|
||||||
assert_equal('some', prefixed.GetSome())
|
assert_equal('testmore', prefixed.GetMore())
|
||||||
assert_equal('name', prefixed.name)
|
assert_equal('name', prefixed.name)
|
||||||
assert_equal('final', prefixed.fname)
|
assert_equal('final', prefixed.fname)
|
||||||
assert_equal('const', prefixed.cname)
|
assert_equal('const', prefixed.cname)
|
||||||
@@ -1173,7 +1173,7 @@ def Test_vim9script_autoload()
|
|||||||
# can also get the items by autoload name
|
# can also get the items by autoload name
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
call assert_equal('test', prefixed#Gettest())
|
call assert_equal('test', prefixed#Gettest())
|
||||||
call assert_equal('some', prefixed#GetSome())
|
call assert_equal('testmore', prefixed#GetMore())
|
||||||
call assert_equal('name', prefixed#name)
|
call assert_equal('name', prefixed#name)
|
||||||
call assert_equal('final', prefixed#fname)
|
call assert_equal('final', prefixed#fname)
|
||||||
call assert_equal('const', prefixed#cname)
|
call assert_equal('const', prefixed#cname)
|
||||||
|
@@ -1874,6 +1874,10 @@ find_func_with_sid(char_u *name, int sid)
|
|||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
char_u buffer[200];
|
char_u buffer[200];
|
||||||
|
|
||||||
|
if (!SCRIPT_ID_VALID(sid))
|
||||||
|
return NULL; // not in a script
|
||||||
|
|
||||||
|
// A script-local function is stored as "<SNR>99_name".
|
||||||
buffer[0] = K_SPECIAL;
|
buffer[0] = K_SPECIAL;
|
||||||
buffer[1] = KS_EXTRA;
|
buffer[1] = KS_EXTRA;
|
||||||
buffer[2] = (int)KE_SNR;
|
buffer[2] = (int)KE_SNR;
|
||||||
@@ -1882,6 +1886,46 @@ find_func_with_sid(char_u *name, int sid)
|
|||||||
hi = hash_find(&func_hashtab, buffer);
|
hi = hash_find(&func_hashtab, buffer);
|
||||||
if (!HASHITEM_EMPTY(hi))
|
if (!HASHITEM_EMPTY(hi))
|
||||||
return HI2UF(hi);
|
return HI2UF(hi);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find a function "name" in script "sid" prefixing the autoload prefix.
|
||||||
|
*/
|
||||||
|
static ufunc_T *
|
||||||
|
find_func_with_prefix(char_u *name, int sid)
|
||||||
|
{
|
||||||
|
hashitem_T *hi;
|
||||||
|
char_u buffer[200];
|
||||||
|
scriptitem_T *si;
|
||||||
|
|
||||||
|
if (vim_strchr(name, AUTOLOAD_CHAR) != 0)
|
||||||
|
return NULL; // already has the prefix
|
||||||
|
if (!SCRIPT_ID_VALID(sid))
|
||||||
|
return NULL; // not in a script
|
||||||
|
si = SCRIPT_ITEM(sid);
|
||||||
|
if (si->sn_autoload_prefix != NULL)
|
||||||
|
{
|
||||||
|
size_t len = STRLEN(si->sn_autoload_prefix) + STRLEN(name) + 1;
|
||||||
|
char_u *auto_name;
|
||||||
|
|
||||||
|
// An exported function in an autoload script is stored as
|
||||||
|
// "dir#path#name".
|
||||||
|
if (len < sizeof(buffer))
|
||||||
|
auto_name = buffer;
|
||||||
|
else
|
||||||
|
auto_name = alloc(len);
|
||||||
|
if (auto_name != NULL)
|
||||||
|
{
|
||||||
|
vim_snprintf((char *)auto_name, len, "%s%s",
|
||||||
|
si->sn_autoload_prefix, name);
|
||||||
|
hi = hash_find(&func_hashtab, auto_name);
|
||||||
|
if (auto_name != buffer)
|
||||||
|
vim_free(auto_name);
|
||||||
|
if (!HASHITEM_EMPTY(hi))
|
||||||
|
return HI2UF(hi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1917,7 +1961,9 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx UNUSED)
|
|||||||
if (!HASHITEM_EMPTY(hi))
|
if (!HASHITEM_EMPTY(hi))
|
||||||
return HI2UF(hi);
|
return HI2UF(hi);
|
||||||
|
|
||||||
return NULL;
|
// Find autoload function if this is an autoload script.
|
||||||
|
return find_func_with_prefix(name[0] == 's' && name[1] == ':'
|
||||||
|
? name + 2 : name, current_sctx.sc_sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4063,
|
||||||
/**/
|
/**/
|
||||||
4062,
|
4062,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user