From b4a216f7ed417e2f1afa321883da1f9fac921aac Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sun, 20 Jun 2021 18:05:15 +0600 Subject: BugFix: Fix inconsistent verbose message When a keymap is set from lua currently verbose message says it's set from line 1. That's incorrect because we don't really know when it was set. So until proper :verbose support isn't added for sourceing lua it shouldn't say where it was set at. --- src/nvim/ex_cmds2.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 9abeee47f4..dd9444f837 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2665,7 +2665,8 @@ static void cmd_source_buffer(const exarg_T *eap) }; if (curbuf != NULL && curbuf->b_fname && 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 { source_using_linegetter((void *)&cookie, get_buffer_line, ":source (no file)"); @@ -3002,8 +3003,17 @@ int do_source(char_u *fname, int check_other, int is_vimrc) } 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 retval = (int)nlua_exec_file((const char *)fname); + current_sctx = current_sctx_backup; + sourcing_lnum = sourcing_lnum_backup; } else { // Call do_cmdline, which will call getsourceline() to get the lines. do_cmdline(firstline, getsourceline, (void *)&cookie, -- cgit From b4ac8780267d9164a84deaec27fbc6260f765514 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Sun, 20 Jun 2021 23:07:04 +0600 Subject: fix(source): Source giving E484 & parsing error at line 1 for lua files It's happening because do_source is only expected to return FAIL when it was unable to open file . But `nlua_exec_file` returns fail for parsing and execution error too . Those errors are emitted through `nlua_error`. So now return value of nlua_exec_file is ignored like do_cmdline. It now only returns fail when it was unable to open file that check is done before calling nlua_exec_file or do_cmdline. Errors in nlua_exec_file are still directly emitted through nlua_error like before. --- src/nvim/ex_cmds2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_cmds2.c') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index dd9444f837..9d500a8ddb 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -3011,15 +3011,15 @@ int do_source(char_u *fname, int check_other, int is_vimrc) current_sctx.sc_lnum = 0; sourcing_lnum = 0; // 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 { // Call do_cmdline, which will call getsourceline() to get the lines. do_cmdline(firstline, getsourceline, (void *)&cookie, DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); - retval = OK; } + retval = OK; if (l_do_profiling == PROF_YES) { // Get "si" again, "script_items" may have been reallocated. -- cgit