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

cmp-cmdline causes Neovim to freeze when using ! in command mode #112

Open
theSprog opened this issue Apr 23, 2024 · 5 comments
Open

cmp-cmdline causes Neovim to freeze when using ! in command mode #112

theSprog opened this issue Apr 23, 2024 · 5 comments

Comments

@theSprog
Copy link

I encountered an issue described in title with the cmp-cmdline plugin when using Neovim. The problem occurs when I attempt to execute a shell command using ! in command mode.

I have tried disabling the cmp-cmdline plugin, and the issue disappears when the plugin is disabled. This leads me to believe that the problem lies within the cmp-cmdline plugin.

Steps to reproduce:

  1. Install and configure the cmp-cmdline plugin in Neovim.

  2. Enter command mode by pressing :.

  3. Type r followed by a space.

  4. Type ! to indicate a shell command.

  5. Attempt to type the shell command (e.g., ls). that I want to type is

    r !ls
    

Expected behavior:
Neovim should allow me to type the shell command without any freezing or long processing times. The command should be executed immediately when I press Enter.

Actual behavior:
After typing !, Neovim freezes and becomes unresponsive. It appears to be stuck in a long processing logic. After waiting for a few minutes, Neovim eventually reads the contents of the ls command, but the freezing and long processing time are unacceptable.

Additional information:

  • Neovim version: 0.9.5

  • cmp-cmdline version: These is no release published in the cmp-cmdline and I’m using lazy.nvim to install it

  • Operating system: WSL + arch

  • options:

    cmp.setup.cmdline(":", {
            mapping = cmp.mapping.preset.cmdline(),
            sources = cmp.config.sources({
                    { name = "path" },
                }, {
                    {
                        name = "cmdline",
                        option = {
                            ignore_cmds = { "Man", "!" },
                        },
                    },
                }),
        })
@theSprog
Copy link
Author

I checked the source code and I don't know if there is a problem here.

  if vim.tbl_contains(option.ignore_cmds, parsed.cmd) then
    return {}
  end

  -- Cleanup modifiers.
  -- We can just remove modifiers because modifiers is always separated by space.
  if arglead ~= cmdline then
    while true do
      local s, e = MODIFIER_REGEX:match_str(cmdline)
      if s == nil then
        break
      end
      cmdline = string.sub(cmdline, e + 1)
    end

Here vim.tbl_contains(option.ignore_cmds, parsed.cmd) does not seem to filter out strings like 'r !ls', so it is not stopped by return {}, and there is a while true after it, so neovim seems to be stuck

@dhnam
Copy link

dhnam commented Apr 23, 2024

+1 for this. This is why ! is ignored by default (as it takes really long time) I believe.

#109 (I opened the issue, btw) can be handeled here, as it is caused by same '! is not ignored by cmp-cmdline when it is not follows : directly'.

@sybereal
Copy link

I believe I have run into a similar issue.

I added terminal to the list of ignored commands for the same reason as ! is there, because trying to complete the 11k+ executables on my PATH (according to fzf) would freeze Neovim for over a minute, if not more.

However, I noticed that, when I chain commands using |, the ignore does not seem to apply. This is unfortunate, as I often do :split | terminal run-something to start a process in a new terminal split.

For now, I'll see if I can work around this by adding a custom command that wraps this split | terminal workflow and then put that on my ignore list.

@mau-mauricelim
Copy link

I have the same issue with :w ! and :r !

@Alfamari
Copy link

Not a great workaround, but if you add the full names for the command prefix you are trying to ignore with the ! it will work. So ignore_cmds = { 'Man', '!', 'read', 'write' } will prevent the hang on :r!, :r !, and :w !. Unfortunately, this comes with a ton of false positives, so there won't be any completions for any other command that starts with w or r until you keep typing and reach a letter that breaks the sequence of those commands. Like ru or wi.

Dunno if it's possible to improve this by adding another keybind that would utilize a different ignore list or 'ignore' the ignore list, so as to choose when you want to disable completions for :r! but allow completions for :r. But for me, I only need to fix the read until I wait for a fix.

I was also unable to adopt this older solution to the current issue:
#24 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants