mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
feat(:source, nvim_exec): defer script item creation until s:var access
For anonymous scripts, defer the creation of script items until an attempt to access a script-local variable is made. This dramatically reduces the number of script items created when using lots of vim.cmd and nvim_exec especially. This will mean <SID> usage fails until a script-local variable access is first made.
This commit is contained in:
@@ -89,6 +89,14 @@ describe('API', function()
|
||||
|
||||
it(':verbose set {option}?', function()
|
||||
nvim('exec', 'set nowrap', false)
|
||||
eq('nowrap\n\tLast set from anonymous :source',
|
||||
nvim('exec', 'verbose set wrap?', true))
|
||||
|
||||
-- Using script var to force creation of a script item
|
||||
nvim('exec', [[
|
||||
let s:a = 1
|
||||
set nowrap
|
||||
]], false)
|
||||
eq('nowrap\n\tLast set from anonymous :source (script id 1)',
|
||||
nvim('exec', 'verbose set wrap?', true))
|
||||
end)
|
||||
@@ -155,6 +163,20 @@ describe('API', function()
|
||||
let s:pirate = 'script-scoped varrrrr'
|
||||
call nvim_exec('echo s:pirate', 1)
|
||||
]], false))
|
||||
|
||||
-- Script items are created only on script var access
|
||||
eq('1\n0', nvim('exec', [[
|
||||
echo expand("<SID>")->empty()
|
||||
let s:a = 123
|
||||
echo expand("<SID>")->empty()
|
||||
]], true))
|
||||
|
||||
eq('1\n0', nvim('exec', [[
|
||||
echo expand("<SID>")->empty()
|
||||
function s:a() abort
|
||||
endfunction
|
||||
echo expand("<SID>")->empty()
|
||||
]], true))
|
||||
end)
|
||||
|
||||
it('non-ASCII input', function()
|
||||
|
||||
Reference in New Issue
Block a user