fix(api): nvim__complete_set requires completeopt=popup #31177

Problem:
If completeopt does not include "popup" flag, nvim__complete_set still
auto-creates a floating preview window.

Solution:
Fail if completeopt does not include the "popup" flag.
This commit is contained in:
glepnir
2025-01-05 21:57:53 +08:00
committed by GitHub
parent d288f7003d
commit bf48dfadec
2 changed files with 32 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ local fn = n.fn
local command = n.command
local api = n.api
local poke_eventloop = n.poke_eventloop
local exec_lua = n.exec_lua
describe('completion', function()
local screen
@@ -1326,4 +1327,29 @@ describe('completion', function()
]],
})
end)
describe('nvim__complete_set', function()
it("fails when 'completeopt' does not include popup", function()
exec_lua([[
function _G.omni_test(findstart, base)
if findstart == 1 then
return vim.fn.col('.') - 1
end
return { { word = 'one' } }
end
vim.api.nvim_create_autocmd('CompleteChanged', {
callback = function()
local ok, err = pcall(vim.api.nvim__complete_set, 0, { info = '1info' })
if not ok then
vim.g.err_msg = err
end
end,
})
vim.opt.completeopt = 'menu,menuone'
vim.opt.omnifunc = 'v:lua.omni_test'
]])
feed('S<C-X><C-O>')
eq('completeopt option does not include popup', api.nvim_get_var('err_msg'))
end)
end)
end)