stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.7k stars 32 forks source link

User-provided completion does not work with lua function #57

Closed stevearc closed 1 year ago

stevearc commented 1 year ago

Tried the mentioned commit (that specific one) and now it does not crash, but no autocomplete happens either. I am trying the same key to trigger the autocomplete that previously was making it crash, so I guess it's the correct one

Originally posted by @danielo515 in https://github.com/stevearc/dressing.nvim/issues/55#issuecomment-1226755339

stevearc commented 1 year ago

The input buffer makes use of a custom user-completion function (see :help completefunc) which is triggered by <C-x><C-u> and I have also mapped <Tab> to trigger it.

I have a manual test file that I use to test various completion sources. Can you source this file and confirm that for the options using lua functions you do not see any completion menu when you press <Tab> or <C-x><C-u>?

danielo515 commented 1 year ago

The input buffer makes use of a custom user-completion function (see :help completefunc) which is triggered by <C-x><C-u> and I have also mapped <Tab> to trigger it.

I have a manual test file that I use to test various completion sources. Can you source this file and confirm that for the options using lua functions you do not see any completion menu when you press <Tab> or <C-x><C-u>?

Will try tonight or tomorrow. Thanks

danielo515 commented 1 year ago

@stevearc I tried the file you suggested and it works properly, so definitively there is something wrñg in my implementation

danielo515 commented 1 year ago

Ok, I found the problem and I am able to reproduce it. Not sure who is to blame here: neovim, dressing or the "components" library. This function fails consistently:

function _G.custom_complete_func(arglead, cmdline, cursorpos)
    return vim.fn.expand("<cword>")
end

It seems that, when the popup has the focus, the <cword> points to the currently focused input, and therefore cword is empty. If you try to run this in the normal vim commandline input, then it works as expected

stevearc commented 1 year ago

Oh, unfortunately I believe this is a product of how Neovim works. The built-in vim.ui.input happens in command mode, which happens synchronously and doesn't interact with the rest of your vim state. Since we're opening floating windows and moving the cursor around, there's just no way for this implementation to preserve the original <cword>.

I'd recommend one of the following:

  1. Pass in vim.fn.expand('<cword>') as the default to vim.ui.input. That way it's present when you want it, and very easy to delete (with <C-u>) if you don't.
  2. Set your dressing config to detect when you're using this completion function, and disable dressing in that case (so it will use the built-in input in command mode). See #29 for more information on how to conditionally disable dressing.
danielo515 commented 1 year ago

There is also a third option which is what I’m doing 😄. Since this is triggered by a function that I call using a key bind I just expand it before calling vim.ui.input and then I pass it as an argument to a curried version of my expand function. Works nice for me. Another option I can think of is mapping backspace to C-u within the buffer? Don’t know, this works fine for me

On Wed, 31 Aug 2022 at 17:31, Steven Arcangeli @.***> wrote:

Oh, unfortunately I believe this is a product of how Neovim works. The built-in vim.ui.input happens in command mode, which happens synchronously and doesn't interact with the rest of your vim state. Since we're opening floating windows and moving the cursor around, there's just no way for this implementation to preserve the original .

I'd recommend one of the following:

  1. Pass in vim.fn.expand('') as the default to vim.ui.input. That way it's present when you want it, and very easy to delete (with ) if you don't.
  2. Set your dressing config to detect when you're using this completion function, and disable dressing in that case (so it will use the built-in input in command mode). See #29 https://github.com/stevearc/dressing.nvim/issues/29 for more information on how to conditionally disable dressing.

— Reply to this email directly, view it on GitHub https://github.com/stevearc/dressing.nvim/issues/57#issuecomment-1233094059, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWI7NCIKQKKG4JZY6BLV353FXANCNFSM57TQK5WQ . You are receiving this because you were mentioned.Message ID: @.***>

--

https://danielorodriguez.com