aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2025-01-05 21:57:53 +0800
committerGitHub <noreply@github.com>2025-01-05 05:57:53 -0800
commitbf48dfadeccc37527e9b59b1c0f529ea889bf735 (patch)
tree981e84c2061924b40dd4690f079ddbe2e90be964
parentd288f7003d256f0f4f85254974239c5f47003ede (diff)
downloadrneovim-bf48dfadeccc37527e9b59b1c0f529ea889bf735.tar.gz
rneovim-bf48dfadeccc37527e9b59b1c0f529ea889bf735.tar.bz2
rneovim-bf48dfadeccc37527e9b59b1c0f529ea889bf735.zip
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.
-rw-r--r--src/nvim/api/vim.c7
-rw-r--r--test/functional/editor/completion_spec.lua26
2 files changed, 32 insertions, 1 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 25f44bb4eb..e3e69f4ff6 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -44,6 +44,7 @@
#include "nvim/highlight.h"
#include "nvim/highlight_defs.h"
#include "nvim/highlight_group.h"
+#include "nvim/insexpand.h"
#include "nvim/keycodes.h"
#include "nvim/log.h"
#include "nvim/lua/executor.h"
@@ -2255,9 +2256,13 @@ void nvim_error_event(uint64_t channel_id, Integer lvl, String data)
/// @return Dict containing these keys:
/// - winid: (number) floating window id
/// - bufnr: (number) buffer id in floating window
-Dict nvim__complete_set(Integer index, Dict(complete_set) *opts, Arena *arena)
+Dict nvim__complete_set(Integer index, Dict(complete_set) *opts, Arena *arena, Error *err)
{
Dict rv = arena_dict(arena, 2);
+ if ((get_cot_flags() & kOptCotFlagPopup) == 0) {
+ api_set_error(err, kErrorTypeException, "completeopt option does not include popup");
+ return rv;
+ }
if (HAS_KEY(opts, complete_set, info)) {
win_T *wp = pum_set_info((int)index, opts->info.data);
if (wp) {
diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua
index c20d925713..7c68de272b 100644
--- a/test/functional/editor/completion_spec.lua
+++ b/test/functional/editor/completion_spec.lua
@@ -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)