mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(source): fix expand('<sfile>') no longer works for Lua
This commit is contained in:
parent
1d28bbf1e5
commit
d1464d16d6
@ -1318,7 +1318,7 @@ int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
|
|||||||
current_sctx.sc_sid = SID_STR;
|
current_sctx.sc_sid = SID_STR;
|
||||||
current_sctx.sc_seq = 0;
|
current_sctx.sc_seq = 0;
|
||||||
current_sctx.sc_lnum = 0;
|
current_sctx.sc_lnum = 0;
|
||||||
estack_push(ETYPE_SCRIPT, NULL, 0);
|
estack_push(ETYPE_SCRIPT, name, 0);
|
||||||
|
|
||||||
garray_T ga;
|
garray_T ga;
|
||||||
char_u *line = NULL;
|
char_u *line = NULL;
|
||||||
|
@ -1983,6 +1983,14 @@ int do_source(char *fname, int check_other, int is_vimrc)
|
|||||||
|
|
||||||
cookie.conv.vc_type = CONV_NONE; // no conversion
|
cookie.conv.vc_type = CONV_NONE; // no conversion
|
||||||
|
|
||||||
|
if (path_with_extension((const char *)fname_exp, "lua")) {
|
||||||
|
const sctx_T current_sctx_backup = current_sctx;
|
||||||
|
current_sctx.sc_sid = SID_LUA;
|
||||||
|
current_sctx.sc_lnum = 0;
|
||||||
|
// Source the file as lua
|
||||||
|
nlua_exec_file((const char *)fname_exp);
|
||||||
|
current_sctx = current_sctx_backup;
|
||||||
|
} else {
|
||||||
// Read the first line so we can check for a UTF-8 BOM.
|
// Read the first line so we can check for a UTF-8 BOM.
|
||||||
firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true);
|
firstline = (uint8_t *)getsourceline(0, (void *)&cookie, 0, true);
|
||||||
if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
|
if (firstline != NULL && STRLEN(firstline) >= 3 && firstline[0] == 0xef
|
||||||
@ -1996,17 +2004,6 @@ int do_source(char *fname, int check_other, int is_vimrc)
|
|||||||
xfree(firstline);
|
xfree(firstline);
|
||||||
firstline = (uint8_t *)p;
|
firstline = (uint8_t *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path_with_extension((const char *)fname_exp, "lua")) {
|
|
||||||
const sctx_T current_sctx_backup = current_sctx;
|
|
||||||
current_sctx.sc_sid = SID_LUA;
|
|
||||||
current_sctx.sc_lnum = 0;
|
|
||||||
estack_push(ETYPE_SCRIPT, NULL, 0);
|
|
||||||
// Source the file as lua
|
|
||||||
nlua_exec_file((const char *)fname_exp);
|
|
||||||
current_sctx = current_sctx_backup;
|
|
||||||
estack_pop();
|
|
||||||
} 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((char *)firstline, getsourceline, (void *)&cookie,
|
do_cmdline((char *)firstline, getsourceline, (void *)&cookie,
|
||||||
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
|
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT);
|
||||||
|
@ -48,21 +48,38 @@ describe(':source', function()
|
|||||||
pending("'shellslash' only works on Windows")
|
pending("'shellslash' only works on Windows")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mkdir('Xshellslash')
|
|
||||||
local script = [[
|
|
||||||
let g:result1 = expand('<stack>')
|
|
||||||
set shellslash
|
|
||||||
let g:result2 = expand('<stack>')
|
|
||||||
set noshellslash
|
|
||||||
let g:result3 = expand('<stack>')
|
|
||||||
]]
|
|
||||||
write_file([[Xshellslash/Xexpand.vim]], script)
|
|
||||||
|
|
||||||
meths.set_option('shellslash', false)
|
meths.set_option('shellslash', false)
|
||||||
command([[source Xshellslash/Xexpand.vim]])
|
mkdir('Xshellslash')
|
||||||
matches([[Xshellslash\Xexpand%.vim]], meths.get_var('result1'))
|
|
||||||
matches([[Xshellslash/Xexpand%.vim]], meths.get_var('result2'))
|
write_file([[Xshellslash/Xstack.vim]], [[
|
||||||
matches([[Xshellslash\Xexpand%.vim]], meths.get_var('result3'))
|
let g:stack1 = expand('<stack>')
|
||||||
|
set shellslash
|
||||||
|
let g:stack2 = expand('<stack>')
|
||||||
|
set noshellslash
|
||||||
|
let g:stack3 = expand('<stack>')
|
||||||
|
]])
|
||||||
|
|
||||||
|
for _ = 1, 2 do
|
||||||
|
command([[source Xshellslash/Xstack.vim]])
|
||||||
|
matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack1'))
|
||||||
|
matches([[Xshellslash/Xstack%.vim]], meths.get_var('stack2'))
|
||||||
|
matches([[Xshellslash\Xstack%.vim]], meths.get_var('stack3'))
|
||||||
|
end
|
||||||
|
|
||||||
|
write_file([[Xshellslash/Xstack.lua]], [[
|
||||||
|
vim.g.stack1 = vim.fn.expand('<stack>')
|
||||||
|
vim.o.shellslash = true
|
||||||
|
vim.g.stack2 = vim.fn.expand('<stack>')
|
||||||
|
vim.o.shellslash = false
|
||||||
|
vim.g.stack3 = vim.fn.expand('<stack>')
|
||||||
|
]])
|
||||||
|
|
||||||
|
for _ = 1, 2 do
|
||||||
|
command([[source Xshellslash/Xstack.lua]])
|
||||||
|
matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack1'))
|
||||||
|
matches([[Xshellslash/Xstack%.lua]], meths.get_var('stack2'))
|
||||||
|
matches([[Xshellslash\Xstack%.lua]], meths.get_var('stack3'))
|
||||||
|
end
|
||||||
|
|
||||||
rmdir('Xshellslash')
|
rmdir('Xshellslash')
|
||||||
end)
|
end)
|
||||||
@ -145,11 +162,18 @@ describe(':source', function()
|
|||||||
|
|
||||||
it('can source lua files', function()
|
it('can source lua files', function()
|
||||||
local test_file = 'test.lua'
|
local test_file = 'test.lua'
|
||||||
write_file (test_file, [[vim.g.sourced_lua = 1]])
|
write_file(test_file, [[
|
||||||
|
vim.g.sourced_lua = 1
|
||||||
exec('source ' .. test_file)
|
vim.g.sfile_value = vim.fn.expand('<sfile>')
|
||||||
|
vim.g.stack_value = vim.fn.expand('<stack>')
|
||||||
|
]])
|
||||||
|
|
||||||
|
command('set shellslash')
|
||||||
|
command('source ' .. test_file)
|
||||||
eq(1, eval('g:sourced_lua'))
|
eq(1, eval('g:sourced_lua'))
|
||||||
|
matches([[/test%.lua$]], meths.get_var('sfile_value'))
|
||||||
|
matches([[/test%.lua$]], meths.get_var('stack_value'))
|
||||||
|
|
||||||
os.remove(test_file)
|
os.remove(test_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -181,13 +205,15 @@ describe(':source', function()
|
|||||||
it('can source current lua buffer without argument', function()
|
it('can source current lua buffer without argument', function()
|
||||||
local test_file = 'test.lua'
|
local test_file = 'test.lua'
|
||||||
|
|
||||||
write_file (test_file, [[
|
write_file(test_file, [[
|
||||||
vim.g.c = 10
|
vim.g.c = 10
|
||||||
vim.g.c = 11
|
vim.g.c = 11
|
||||||
vim.g.c = 12
|
vim.g.c = 12
|
||||||
a = [=[
|
a = [=[
|
||||||
\ 1
|
\ 1
|
||||||
"\ 2]=]
|
"\ 2]=]
|
||||||
|
vim.g.sfile_value = vim.fn.expand('<sfile>')
|
||||||
|
vim.g.stack_value = vim.fn.expand('<stack>')
|
||||||
]])
|
]])
|
||||||
|
|
||||||
command('edit '..test_file)
|
command('edit '..test_file)
|
||||||
@ -195,6 +221,9 @@ describe(':source', function()
|
|||||||
|
|
||||||
eq(12, eval('g:c'))
|
eq(12, eval('g:c'))
|
||||||
eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
|
eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
|
||||||
|
eq(':source (no file)', meths.get_var('sfile_value'))
|
||||||
|
eq(':source (no file)', meths.get_var('stack_value'))
|
||||||
|
|
||||||
os.remove(test_file)
|
os.remove(test_file)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user