Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd9480dc

Browse files
committed
feat(lua): print locations of lua callbacks
1 parentdb6e93c commitd9480dc

File tree

7 files changed

+54
-18
lines changed

7 files changed

+54
-18
lines changed

‎src/nvim/api/command.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,14 +1105,16 @@ void create_user_command(String name, Object command, Dict(user_command) *opts,
11051105
gotoerr;
11061106
}
11071107

1108+
boolrep_free= false;
11081109
switch (command.type) {
11091110
casekObjectTypeLuaRef:
11101111
luaref=api_new_luaref(command.data.luaref);
11111112
if (opts->desc.type==kObjectTypeString) {
11121113
rep=opts->desc.data.string.data;
11131114
}else {
1114-
snprintf((char*)IObuff,IOSIZE,"<Lua function %d>",luaref);
1115-
rep= (char*)IObuff;
1115+
// TODO(ii14): print both luaref and desc
1116+
rep=nlua_funcref_str(luaref);
1117+
rep_free= true;
11161118
}
11171119
break;
11181120
casekObjectTypeString:
@@ -1129,6 +1131,10 @@ void create_user_command(String name, Object command, Dict(user_command) *opts,
11291131
// Do not goto err, since uc_add_command now owns luaref, compl_luaref, and compl_arg
11301132
}
11311133

1134+
if (rep_free) {
1135+
xfree(rep);
1136+
}
1137+
11321138
return;
11331139

11341140
err:

‎src/nvim/autocmd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static void aupat_show(AutoPat *ap, event_T event, int previous_group)
196196
if (ac->desc!=NULL) {
197197
size_tmsglen=100;
198198
char*msg= (char*)xmallocz(msglen);
199+
// TODO(ii14): move desc to a new line
199200
snprintf(msg,msglen,"%s [%s]",exec_to_string,ac->desc);
200201
msg_outtrans(msg);
201202
XFREE_CLEAR(msg);

‎src/nvim/eval/typval.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,13 +1657,14 @@ void callback_copy(Callback *dest, Callback *src)
16571657
/// Generate a string description of a callback
16581658
char*callback_to_string(Callback*cb)
16591659
{
1660-
size_tmsglen=100;
1660+
if (cb->type==kCallbackLua) {
1661+
returnnlua_funcref_str(cb->data.luaref);
1662+
}
1663+
1664+
constsize_tmsglen=100;
16611665
char*msg= (char*)xmallocz(msglen);
16621666

16631667
switch (cb->type) {
1664-
casekCallbackLua:
1665-
snprintf(msg,msglen,"<lua: %d>",cb->data.luaref);
1666-
break;
16671668
casekCallbackFuncref:
16681669
// TODO(tjdevries): Is this enough space for this?
16691670
snprintf(msg,msglen,"<vim function: %s>",cb->data.funcref);
@@ -1672,7 +1673,7 @@ char *callback_to_string(Callback *cb)
16721673
snprintf(msg,msglen,"<vim partial: %s>",cb->data.partial->pt_name);
16731674
break;
16741675
default:
1675-
snprintf(msg,msglen,"%s","");
1676+
*msg='\0';
16761677
break;
16771678
}
16781679
returnmsg;

‎src/nvim/lua/executor.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,3 +2076,34 @@ int nlua_do_ucmd(ucmd_T *cmd, exarg_T *eap, bool preview)
20762076

20772077
returnretv;
20782078
}
2079+
2080+
/// String representation of a Lua function reference
2081+
///
2082+
/// @return Allocated string
2083+
char*nlua_funcref_str(LuaRefref)
2084+
{
2085+
lua_State*constlstate=global_lstate;
2086+
StringBuilderstr=KV_INITIAL_VALUE;
2087+
kv_resize(str,16);
2088+
2089+
if (!lua_checkstack(lstate,1)) {
2090+
gotoplain;
2091+
}
2092+
nlua_pushref(lstate,ref);
2093+
if (!lua_isfunction(lstate,-1)) {
2094+
lua_pop(lstate,1);
2095+
gotoplain;
2096+
}
2097+
2098+
lua_Debugar;
2099+
if (lua_getinfo(lstate,">S",&ar)&&*ar.source=='@'&&ar.linedefined >=0) {
2100+
char*src=home_replace_save(NULL,ar.source+1);
2101+
kv_printf(str,"<Lua %d: %s:%d>",ref,src,ar.linedefined);
2102+
xfree(src);
2103+
returnstr.items;
2104+
}
2105+
2106+
plain:
2107+
kv_printf(str,"<Lua %d>",ref);
2108+
returnstr.items;
2109+
}

‎src/nvim/mapping.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ static void showmap(mapblock_T *mp, bool local)
196196
// Use false below if we only want things like <Up> to show up as such on
197197
// the rhs, and not M-x etc, true gets both -- webb
198198
if (mp->m_luaref!=LUA_NOREF) {
199-
charmsg[100];
200-
snprintf(msg,sizeof(msg),"<Lua function %d>",mp->m_luaref);
201-
msg_puts_attr(msg,HL_ATTR(HLF_8));
199+
char*str=nlua_funcref_str(mp->m_luaref);
200+
msg_puts_attr(str,HL_ATTR(HLF_8));
201+
xfree(str);
202202
}elseif (mp->m_str[0]==NUL) {
203203
msg_puts_attr("<Nop>",HL_ATTR(HLF_8));
204204
}else {
@@ -2091,10 +2091,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
20912091
rettv->vval.v_string=str2special_save((char*)rhs, false, false);
20922092
}
20932093
}elseif (rhs_lua!=LUA_NOREF) {
2094-
size_tmsglen=100;
2095-
char*msg= (char*)xmalloc(msglen);
2096-
snprintf(msg,msglen,"<Lua function %d>",mp->m_luaref);
2097-
rettv->vval.v_string=msg;
2094+
rettv->vval.v_string=nlua_funcref_str(mp->m_luaref);
20982095
}
20992096
}else {
21002097
tv_dict_alloc_ret(rettv);

‎src/nvim/os/env.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si
11431143
/// Like home_replace, store the replaced string in allocated memory.
11441144
/// @param buf When not NULL, check for help files
11451145
/// @param src Input file name
1146-
char*home_replace_save(buf_T*buf,char*src)
1146+
char*home_replace_save(buf_T*buf,constchar*src)
11471147
FUNC_ATTR_NONNULL_RET
11481148
{
11491149
size_tlen=3;// space for "~/" and trailing NUL

‎test/functional/api/keymap_spec.lua‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,23 @@ describe('nvim_set_keymap, nvim_del_keymap', function()
797797
vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
798798
]]
799799
assert.truthy(string.match(exec_lua[[return vim.api.nvim_exec(':nmap asdf', true)]],
800-
"^\nn asdf <Luafunction%d+>"))
800+
"^\nn asdf <Lua %d+>"))
801801
end)
802802

803803
it ('mapcheck() returns lua mapping correctly',function()
804804
exec_lua[[
805805
vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
806806
]]
807807
assert.truthy(string.match(funcs.mapcheck('asdf','n'),
808-
"^<Luafunction%d+>"))
808+
"^<Lua %d+>"))
809809
end)
810810

811811
it ('maparg() returns lua mapping correctly',function()
812812
exec_lua[[
813813
vim.api.nvim_set_keymap ('n', 'asdf', '', {callback = function() print('jkl;') end })
814814
]]
815815
assert.truthy(string.match(funcs.maparg('asdf','n'),
816-
"^<Luafunction%d+>"))
816+
"^<Lua %d+>"))
817817
localmapargs=funcs.maparg('asdf','n',false,true)
818818
assert(type(mapargs.callback)=='number','callback is not luaref number')
819819
mapargs.callback=nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp