mirror of
https://github.com/neovim/neovim.git
synced 2026-08-28 10:01:49 +00:00
fix(api): set script context when using nvim_set_hl (#28123)
This commit is contained in:
@@ -32,21 +32,30 @@ vim.api.nvim_exec2("augroup test_group\
|
||||
augroup END\
|
||||
", {})
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
group = 'test_group',
|
||||
pattern = 'cpp',
|
||||
command = 'setl cindent',
|
||||
})
|
||||
|
||||
vim.api.nvim_exec2(':highlight TestHL1 guibg=Blue', {})
|
||||
vim.api.nvim_set_hl(0, 'TestHL2', { bg = 'Green' })
|
||||
|
||||
vim.api.nvim_command("command Bdelete :bd")
|
||||
vim.api.nvim_create_user_command("TestCommand", ":echo 'Hello'", {})
|
||||
|
||||
vim.api.nvim_exec ("\
|
||||
vim.api.nvim_exec2 ("\
|
||||
function Close_Window() abort\
|
||||
wincmd -\
|
||||
endfunction\
|
||||
", false)
|
||||
", {})
|
||||
|
||||
local ret = vim.api.nvim_exec ("\
|
||||
local ret = vim.api.nvim_exec2 ("\
|
||||
function! s:return80()\
|
||||
return 80\
|
||||
endfunction\
|
||||
let &tw = s:return80()\
|
||||
", true)
|
||||
", {})
|
||||
]]
|
||||
)
|
||||
exec(cmd .. ' ' .. script_file)
|
||||
@@ -109,7 +118,7 @@ n \key1 * :echo "test"<CR>
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for mapping set by vim.keymap', function()
|
||||
it('"Last set" for mapping set by vim.keymap.set', function()
|
||||
local result = exec_capture(':verbose map <leader>key2')
|
||||
eq(
|
||||
string.format(
|
||||
@@ -123,7 +132,7 @@ n \key2 * :echo "test"<CR>
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for autocmd by vim.api.nvim_exec', function()
|
||||
it('"Last set" for autocmd set by nvim_exec2', function()
|
||||
local result = exec_capture(':verbose autocmd test_group Filetype c')
|
||||
eq(
|
||||
string.format(
|
||||
@@ -138,6 +147,47 @@ test_group FileType
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for autocmd set by nvim_create_autocmd', function()
|
||||
local result = exec_capture(':verbose autocmd test_group Filetype cpp')
|
||||
eq(
|
||||
string.format(
|
||||
[[
|
||||
--- Autocommands ---
|
||||
test_group FileType
|
||||
cpp setl cindent
|
||||
Last set from %s line 13]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for highlight group set by nvim_exec2', function()
|
||||
local result = exec_capture(':verbose highlight TestHL1')
|
||||
eq(
|
||||
string.format(
|
||||
[[
|
||||
TestHL1 xxx guibg=Blue
|
||||
Last set from %s line 19]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for highlight group set by nvim_set_hl', function()
|
||||
local result = exec_capture(':verbose highlight TestHL2')
|
||||
eq(
|
||||
string.format(
|
||||
[[
|
||||
TestHL2 xxx guibg=Green
|
||||
Last set from %s line 20]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
)
|
||||
end)
|
||||
|
||||
it('"Last set" for command defined by nvim_command', function()
|
||||
if cmd == 'luafile' then
|
||||
pending('nvim_command does not set the script context')
|
||||
@@ -148,7 +198,7 @@ test_group FileType
|
||||
[[
|
||||
Name Args Address Complete Definition
|
||||
Bdelete 0 :bd
|
||||
Last set from %s line 13]],
|
||||
Last set from %s line 22]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
@@ -162,7 +212,7 @@ test_group FileType
|
||||
[[
|
||||
Name Args Address Complete Definition
|
||||
TestCommand 0 :echo 'Hello'
|
||||
Last set from %s line 14]],
|
||||
Last set from %s line 23]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
@@ -175,7 +225,7 @@ test_group FileType
|
||||
string.format(
|
||||
[[
|
||||
function Close_Window() abort
|
||||
Last set from %s line 16
|
||||
Last set from %s line 25
|
||||
1 wincmd -
|
||||
endfunction]],
|
||||
script_location
|
||||
@@ -190,7 +240,7 @@ test_group FileType
|
||||
string.format(
|
||||
[[
|
||||
textwidth=80
|
||||
Last set from %s line 22]],
|
||||
Last set from %s line 31]],
|
||||
script_location
|
||||
),
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user