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

Make vim.ui.input completion engines friendly #55

Open
RaafatTurki opened this issue Aug 19, 2022 · 15 comments
Open

Make vim.ui.input completion engines friendly #55

RaafatTurki opened this issue Aug 19, 2022 · 15 comments
Assignees
Labels
enhancement New feature or request P2 Not a priority. PRs welcome

Comments

@RaafatTurki
Copy link

Hi, I'm a bit confused as to how one would re-enable completion engines such as cmp and mini as both are currently explicitly disabled with no option to prevent that.

Additionally and ideally there would be a hook of some sort that users can setup their completion engines within per vim.ui.input call.
That way for example when vim.ui.input is used to do an LSP rename, one could enable cmp with sources that make sense in that context (buffer, spell, rg .. etc) which aid in the operation of LSP renaming.

It really sounds like I'm asking for some hooks per vim.ui.input call here but I didn't want to be vague in order to eliminate any chance of having an XY problem here.

I might be missing something obvious here, wdyt?

@RaafatTurki RaafatTurki added the bug Something isn't working label Aug 19, 2022
@stevearc
Copy link
Owner

First, some background on why things are the way they are:

There's a bit of conflict between the two sources of configuration for vim.ui.input. The first source is the callsite, which can pass in a completion argument to define what kind of completion to use (see :help vim.ui.select()). The second is the end user, who might want to have specific types of completion for specific types of dialogs. Additionally, the callsite has to limit itself to what's available in the bare Neovim API, whereas the user might want to use something else (e.g. LSP completion). Complicating the issue, there is no good way to tell what the purpose of the vim.ui.input dialog is. vim.ui.select() has the kind option for exactly this situation, but there is no such affordance for input.

I think a logical next step would be to make the existing completion option work with the autocomplete plugins. I believe that could be done with not too much effort, and would be a clear win.

To enable context-aware user-specified completion methods, that will be more difficult. I think the first step would be to make a PR to Neovim that adds kind to the vim.ui.input API, and to set unique values in the relevant locations (e.g. LSP rename). The next step would be to add config options to dressing that can both configure the autocompletion plugins, and also set a "default" completion method if none is specified by the callsite. I think that would then unlock the functionality you're asking for.

@danielo515
Copy link

In case you set the completion in call site, is it expected to work? Or will it fail?
I'm asking because I just opened an issue in neovim (neovim/neovim#19907) and now I am thinking if this is actually a bug in dressing.nvim

@stevearc
Copy link
Owner

@danielo515 setting the completion from the callsite is expected to work. There was a bug when the completion method was a custom lua function, but it should be fixed in 96b09a0

@danielo515
Copy link

Thanks for your confirmation @stevearc.
I'll keep the issue in neovim repo open then

@stevearc
Copy link
Owner

@danielo515 Oh no, I just pushed up that fix. I think that the report was a bug in dressing and not neovim. Try again on the latest master and see if it still repros.

@danielo515
Copy link

danielo515 commented Aug 24, 2022 via email

@danielo515
Copy link

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

@stevearc
Copy link
Owner

@danielo515 I'm moving your discussion to #57, as this is now quite different from the original posted issue discussing the enabling of autocompletion engines in the input buffer.

@stevearc stevearc added enhancement New feature or request and removed bug Something isn't working labels Aug 25, 2022
@chrisgrieser
Copy link
Contributor

are there any updates on getting completion in DressingInput? by manually adding things to DressingInput in the cmp config, I managed to get a popup menu upon, but not the ability to select things in it 🥴

@stevearc
Copy link
Owner

I just pushed up commit. If you have both nvim-cmp and cmp_omni installed you should have autocompletion now

@chrisgrieser
Copy link
Contributor

wow, this is indeed pretty cool.

With this I got a cmdline replacement for :, including completion of commands

-- : via dressing
cmp.setup.filetype("DressingInput", {
	sources = cmp.config.sources { {name = "omni"} },
})
keymap("n", ":", function ()
	vim.ui.input({ completion = "command"}, function (input)
		if not(input) then return end
		cmd(input)
	end)
end, {desc = ": cmdline replacement"})

unfortunate, that it seems you cannot get multiple completions (e.g., commands and option)? 🤔

@stevearc
Copy link
Owner

Unfortunately, the built-in input() method (and thus vim.ui.input) do not support multiple types of completion. If you want to hack it yourself, you could set the omnifunc in the input buffer to a custom function that completes commands and options.

@danielo515
Copy link

I managed to use some weird tricks to allow completion on the input, but with a custom function. Do you have a better approach?

@niksingh710
Copy link

{ completion = "command"},

i want to have path completion.
is it possible to have?

@stevearc
Copy link
Owner

See :help command-complete. You can get path completion by doing completion = "dir" or completion = "file"

@stevearc stevearc added the P2 Not a priority. PRs welcome label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 Not a priority. PRs welcome
Projects
None yet
Development

No branches or pull requests

5 participants