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

Error when calling vim.fn.getcompletion() for cmdline has unfinished regex patterns #101

Open
Bekaboo opened this issue Jun 15, 2023 · 0 comments · May be fixed by #102
Open

Error when calling vim.fn.getcompletion() for cmdline has unfinished regex patterns #101

Bekaboo opened this issue Jun 15, 2023 · 0 comments · May be fixed by #102

Comments

@Bekaboo
Copy link

Bekaboo commented Jun 15, 2023

Currently cmp-cmdline does not check if the current cmdline content is valid for completion before calling vim.fn.getcompletion(), which can leads to errors, especially when there are unfinished regex patterns in the cmdline.

Consider the following use case where users are using :grep or :vimg to search for the pattern \(foo\)\@<!bar:

:grep /\(f

after typing f the following error occurs:

Error executing vim.schedule lua callback: Vim:E54: Unmatched \(
stack traceback:
        [C]: in function 'getcompletion'
        ...e/pack/packages/opt/cmp-cmdline/lua/cmp_cmdline/init.lua:130: in function 'exec'
        ...e/pack/packages/opt/cmp-cmdline/lua/cmp_cmdline/init.lua:181: in function 'complete'
        .../nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/source.lua:330: in function 'complete'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:302: in function 'complete'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:170: in function 'autoindent'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:162: in function 'on_change'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/init.lua:313: in function 'callback'
        .../site/pack/packages/opt/nvim-cmp/lua/cmp/utils/async.lua:165: in function <.../site/pack/packages/opt/nvim-cmp/lua/cmp/utils/async.lua:163>

this can be reproduced by calling vim.fn.getcompletion('grep /\\(f', 'cmdline') directly:

E5108: Error executing lua Vim:E54: Unmatched \(
stack traceback:
        [C]: in function 'getcompletion'
        [string ":lua"]:1: in main chunk

Similar errors for \@:

:grep /\(foo\)\@<

after typing <, the following error occurs:

Error executing vim.schedule lua callback: Vim:E869: (NFA) Unknown operator '\@
stack traceback:
        [C]: in function 'getcompletion'
        ...e/pack/packages/opt/cmp-cmdline/lua/cmp_cmdline/init.lua:130: in function 'exec'
        ...e/pack/packages/opt/cmp-cmdline/lua/cmp_cmdline/init.lua:181: in function 'complete'
        .../nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/source.lua:330: in function 'complete'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:302: in function 'complete'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:170: in function 'autoindent'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/core.lua:162: in function 'on_change'
        ...re/nvim/site/pack/packages/opt/nvim-cmp/lua/cmp/init.lua:313: in function 'callback'
        .../site/pack/packages/opt/nvim-cmp/lua/cmp/utils/async.lua:165: in function <.../site/pack/packages/opt/nvim-cmp/lua/cmp/utils/async.lua:163>

Since there's no convenient way to detect if a pattern can be completed without errors, I think the best we can do is to use pcall() to try to get the completion silently and continue only if no errors are triggered.

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

Successfully merging a pull request may close this issue.

1 participant