mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 09:26:30 +00:00
Merge pull request #14868 from shadmansaleh/patch_verbose_for_lua
fix(runtime): Fix bugs regarding lua runtime files
This commit is contained in:
@@ -2665,7 +2665,8 @@ static void cmd_source_buffer(const exarg_T *eap)
|
|||||||
};
|
};
|
||||||
if (curbuf != NULL && curbuf->b_fname
|
if (curbuf != NULL && curbuf->b_fname
|
||||||
&& path_with_extension((const char *)curbuf->b_fname, "lua")) {
|
&& path_with_extension((const char *)curbuf->b_fname, "lua")) {
|
||||||
nlua_source_using_linegetter(get_buffer_line, (void *)&cookie, ":source");
|
nlua_source_using_linegetter(get_buffer_line, (void *)&cookie,
|
||||||
|
":source (no file)");
|
||||||
} else {
|
} else {
|
||||||
source_using_linegetter((void *)&cookie, get_buffer_line,
|
source_using_linegetter((void *)&cookie, get_buffer_line,
|
||||||
":source (no file)");
|
":source (no file)");
|
||||||
@@ -3002,14 +3003,23 @@ int do_source(char_u *fname, int check_other, int is_vimrc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (path_with_extension((const char *)fname, "lua")) {
|
if (path_with_extension((const char *)fname, "lua")) {
|
||||||
|
// TODO(shadmansaleh): Properly handle :verbose for lua
|
||||||
|
// For now change currennt_sctx before sourcing lua files
|
||||||
|
// So verbose doesn't say everything was done in line 1 since we don't know
|
||||||
|
const sctx_T current_sctx_backup = current_sctx;
|
||||||
|
const linenr_T sourcing_lnum_backup = sourcing_lnum;
|
||||||
|
current_sctx.sc_lnum = 0;
|
||||||
|
sourcing_lnum = 0;
|
||||||
// Source the file as lua
|
// Source the file as lua
|
||||||
retval = (int)nlua_exec_file((const char *)fname);
|
nlua_exec_file((const char *)fname);
|
||||||
|
current_sctx = current_sctx_backup;
|
||||||
|
sourcing_lnum = sourcing_lnum_backup;
|
||||||
} else {
|
} else {
|
||||||
// Call do_cmdline, which will call getsourceline() to get the lines.
|
// Call do_cmdline, which will call getsourceline() to get the lines.
|
||||||
do_cmdline(firstline, getsourceline, (void *)&cookie,
|
do_cmdline(firstline, getsourceline, (void *)&cookie,
|
||||||
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
|
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
|
||||||
retval = OK;
|
|
||||||
}
|
}
|
||||||
|
retval = OK;
|
||||||
|
|
||||||
if (l_do_profiling == PROF_YES) {
|
if (l_do_profiling == PROF_YES) {
|
||||||
// Get "si" again, "script_items" may have been reallocated.
|
// Get "si" again, "script_items" may have been reallocated.
|
||||||
|
@@ -1164,6 +1164,13 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
|
|||||||
int nlua_source_using_linegetter(LineGetter fgetline,
|
int nlua_source_using_linegetter(LineGetter fgetline,
|
||||||
void *cookie, char *name)
|
void *cookie, char *name)
|
||||||
{
|
{
|
||||||
|
const linenr_T save_sourcing_lnum = sourcing_lnum;
|
||||||
|
const sctx_T save_current_sctx = current_sctx;
|
||||||
|
current_sctx.sc_sid = SID_STR;
|
||||||
|
current_sctx.sc_seq = 0;
|
||||||
|
current_sctx.sc_lnum = 0;
|
||||||
|
sourcing_lnum = 0;
|
||||||
|
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
char_u *line = NULL;
|
char_u *line = NULL;
|
||||||
|
|
||||||
@@ -1174,6 +1181,9 @@ int nlua_source_using_linegetter(LineGetter fgetline,
|
|||||||
char *code = (char *)ga_concat_strings_sep(&ga, "\n");
|
char *code = (char *)ga_concat_strings_sep(&ga, "\n");
|
||||||
size_t len = strlen(code);
|
size_t len = strlen(code);
|
||||||
nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
|
nlua_typval_exec(code, len, name, NULL, 0, false, NULL);
|
||||||
|
|
||||||
|
sourcing_lnum = save_sourcing_lnum;
|
||||||
|
current_sctx = save_current_sctx;
|
||||||
ga_clear_strings(&ga);
|
ga_clear_strings(&ga);
|
||||||
xfree(code);
|
xfree(code);
|
||||||
return OK;
|
return OK;
|
||||||
|
@@ -9,6 +9,8 @@ local feed_command = helpers.feed_command
|
|||||||
local write_file = helpers.write_file
|
local write_file = helpers.write_file
|
||||||
local exec = helpers.exec
|
local exec = helpers.exec
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
|
local exec_capture = helpers.exec_capture
|
||||||
|
local neq = helpers.neq
|
||||||
|
|
||||||
describe(':source', function()
|
describe(':source', function()
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@@ -90,4 +92,27 @@ describe(':source', function()
|
|||||||
eq(12, eval('g:c'))
|
eq(12, eval('g:c'))
|
||||||
os.remove(test_file)
|
os.remove(test_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("doesn't throw E484 for lua parsing/runtime errors", function()
|
||||||
|
local test_file = 'test.lua'
|
||||||
|
|
||||||
|
-- Does throw E484 for unreadable files
|
||||||
|
local ok, result = pcall(exec_capture, ":source "..test_file ..'noexisting')
|
||||||
|
eq(false, ok)
|
||||||
|
neq(nil, result:find("E484"))
|
||||||
|
|
||||||
|
-- Doesn't throw for parsing error
|
||||||
|
write_file (test_file, "vim.g.c = ")
|
||||||
|
ok, result = pcall(exec_capture, ":source "..test_file)
|
||||||
|
eq(false, ok)
|
||||||
|
eq(nil, result:find("E484"))
|
||||||
|
os.remove(test_file)
|
||||||
|
|
||||||
|
-- Doesn't throw for runtime error
|
||||||
|
write_file (test_file, "error('Cause error anyway :D')")
|
||||||
|
ok, result = pcall(exec_capture, ":source "..test_file)
|
||||||
|
eq(false, ok)
|
||||||
|
eq(nil, result:find("E484"))
|
||||||
|
os.remove(test_file)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user