Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

menu_closed event is emitted way too often, even if menu was not open #1187

Open
2 tasks done
MunifTanjim opened this issue Sep 24, 2022 · 4 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@MunifTanjim
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

minimal_init.lua

local root_dir = vim.fn.fnamemodify(vim.trim(vim.fn.system('git rev-parse --show-toplevel')), ':p')

package.path = string.format('%s;%s?.lua;%s?/init.lua', package.path, root_dir, root_dir)

vim.opt.packpath:prepend(root_dir .. '.testcache/site')

vim.opt.runtimepath:prepend(root_dir)

vim.cmd([[
  packadd nvim-cmp
]])

local cmp = require('cmp')

cmp.setup({
  completion = {
    autocomplete = false,
  },
})

cmp.event:on('menu_opened', function()
  print('menu_opened', os.clock())
end)

cmp.event:on('menu_closed', function()
  print('menu_closed', os.clock())
end)

test.sh

#!/usr/bin/env bash

function setup_environment() {
  echo
  echo "[test] setting up environment"
  echo

  local plugins_dir="./.testcache/site/pack/deps/start"
  mkdir -p "${plugins_dir}"

  echo "[nvim-cmp] linking..."
  mkdir -p "./.testcache/site/pack/deps/opt"
  ln -nsf "$(pwd)" "./.testcache/site/pack/deps/opt/nvim-cmp"

  echo "[test] environment ready"
  echo
}

setup_environment

nvim --clean --noplugin -u minimal_init.lua

Description

After adding a few logs inside the source code, found out that:

Those two code paths are running very often. And because of that menu_closed is emitted even if the menu is not visible.

Steps to reproduce

Run ./test.sh

Start typing something or move around in insert mode.

Even if the completion menu is not opened once, the menu_closed will be printed very often.

Expected behavior

menu_closed will only fire when menu was actually opened and then closed.

Actual behavior

menu_closed is fired very often even when menu was never opened.

Additional context

No response

@MunifTanjim MunifTanjim added the bug Something isn't working label Sep 24, 2022
@hrsh7th
Copy link
Owner

hrsh7th commented Oct 2, 2022

The menu_opened event is also emitted too often.
What do you use this event and the actual problem is?

@MunifTanjim
Copy link
Author

What do you use this event?

https://github.com/zbirenbaum/copilot.lua/blob/2202f7abe238e9e4e28fb91a885fc1e8a2fd2ab5/README.md?plain=1#L106-L118

and the actual problem is?

Since I'm using it only to set a variable, I guess it doesn't matter much for my use-case.

But created the issue 'cause I expected these events to be emitted when the menu is actually opened/closed.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 2, 2022

To be honest, I also think the current implementation is not good and not reasonable.
But changing the implementation would be a breaking change...

@monkoose
Copy link

monkoose commented Apr 2, 2024

What is the status of this?

Even when autocompletion is disabled it runs this event on every keystroke.

cmp.setup({
  completion = {
    autocomplete = false
  }
}

The menu_opened event is also emitted too often.

For me and this snippet menu_opened doesn't invoke on every key pressed, like menu_closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants