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

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

Closed
stevearc opened this issue Aug 25, 2022 · 6 comments
Closed

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

stevearc opened this issue Aug 25, 2022 · 6 comments

Comments

@stevearc
Copy link
Owner

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 #55 (comment)

@stevearc
Copy link
Owner Author

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
Copy link

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
Copy link

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

@danielo515
Copy link

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
Copy link
Owner Author

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 Ability to use the default vim.ui.input based on filetype? #29 for more information on how to conditionally disable dressing.

@danielo515
Copy link

danielo515 commented Aug 31, 2022 via email

@stevearc stevearc closed this as completed Nov 9, 2022
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

2 participants