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

Conflict between ufo and reactive.nvim causes weird behavior of nvim-cmp scroll_docs #223

Closed
b1nhack opened this issue May 18, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@b1nhack
Copy link

b1nhack commented May 18, 2024

Neovim version (nvim -v | head -n1)

NVIM v0.10.0

Operating system/version

macOS 14.5

How to reproduce the issue

As per the documentation, I have the following minimal configuration:

vim.o.foldcolumn = "0" -- '0' is not bad
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true

require("ufo").setup({
    provider_selector = function(bufnr, filetype, buftype)
    return { "treesitter", "indent" }
    end,
})

nvim-cmp has the following keymap:

["<C-h>"] = cmp.mapping(function(fallback) 
	if cmp.visible_docs() then             
		cmp.scroll_docs(-5)                
	else                                   
		fallback()                         
	end                                    
end),                                      
["<C-b>"] = cmp.mapping(function(fallback) 
	if cmp.visible_docs() then             
		cmp.scroll_docs(5)                 
	else                                   
		fallback()                         
	end                                    
end),                                      

At this point, the scroll_docs function will cause some confusion.
vim.o.foldenable = true does not cause problems when ufo is disabled.

Expected behavior

nvim-cmp scroll_docs normal behavior.

Actual behavior

nvim-cmp scroll_docs causes confusion.

@b1nhack b1nhack added the bug Something isn't working label May 18, 2024
@kevinhwang91
Copy link
Owner

what's error msg?

@b1nhack
Copy link
Author

b1nhack commented May 19, 2024

what's error msg?

No error message, just scroll_docs causes strange behavior, cmp.scroll_docs() moves my cursor forward one character, and the autocomplete window goes back to its original state

@b1nhack
Copy link
Author

b1nhack commented May 19, 2024

I did more testing, and it turns out that the problem has nothing to do with vim.o.foldenable, but with ufo itself!

@b1nhack b1nhack changed the title nvim-cmp scroll_docs error when vim.o.foldenable = true ufo causes weird behavior of nvim-cmp scroll_docs May 19, 2024
@kevinhwang91
Copy link
Owner

can't reproduce it.

@b1nhack
Copy link
Author

b1nhack commented May 19, 2024

can't reproduce it.

Okay, I'll try to make a minimal configuration. There may be other conflicts.

@b1nhack
Copy link
Author

b1nhack commented May 20, 2024

I'm sorry, using ufo and nvim-cmp minimal configuration did not cause the problem. It should be other plugins and ufo that caused the problem, because if I disable ufo, everything works fine.
I will continue testing.

@b1nhack
Copy link
Author

b1nhack commented May 20, 2024

In fact, reactive.nvim and ufo have some conflicts, which will cause this problem when they exist at the same time.
I don't know who is the source of the problem.
The minimum configuration is as follows:

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	{
		"rasulomaroff/reactive.nvim",

		config = function()
			require("reactive").setup({
				builtin = {
					cursorline = true,
					cursor = true,
					modemsg = true,
				},
			})
		end,
	},

	{
		"williamboman/mason.nvim",

		config = function()
			require("mason").setup()
		end,
	},
	{
		"WhoIsSethDaniel/mason-tool-installer.nvim",

		config = function()
			require("mason-tool-installer").setup({
				ensure_installed = {
					"lua-language-server",
				},
			})
		end,
	},
	{
		"neovim/nvim-lspconfig",

		config = function()
			require("lspconfig").lua_ls.setup({})
		end,
	},
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"hrsh7th/cmp-nvim-lsp",
		},

		config = function()
			local cmp = require("cmp")

			cmp.setup({
				mapping = {
					["<C-u>"] = cmp.mapping(function(fallback)
						if cmp.visible() then
							cmp.select_prev_item()
						else
							fallback()
						end
					end),
					["<C-e>"] = cmp.mapping(function(fallback)
						if cmp.visible() then
							cmp.select_next_item()
						else
							fallback()
						end
					end),

					["<C-h>"] = cmp.mapping(function(fallback)
						if cmp.visible_docs() then
							cmp.scroll_docs(-5)
						else
							fallback()
						end
					end),
					["<C-b>"] = cmp.mapping(function(fallback)
						if cmp.visible_docs() then
							cmp.scroll_docs(5)
						else
							fallback()
						end
					end),
				},
				sources = cmp.config.sources({
					{ name = "nvim_lsp" },
				}),
			})
		end,
	},

	{
		"nvim-treesitter/nvim-treesitter",

		config = function()
			require("nvim-treesitter.configs").setup({
				ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
			})
		end,
	},
	{
		"kevinhwang91/nvim-ufo",
		dependencies = {
			"kevinhwang91/promise-async",
		},

		config = function()
			vim.o.foldcolumn = "1" -- '0' is not bad
			vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
			vim.o.foldlevelstart = 99
			vim.o.foldenable = true

			-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself
			vim.keymap.set("n", "zR", require("ufo").openAllFolds)
			vim.keymap.set("n", "zM", require("ufo").closeAllFolds)

			require("ufo").setup({
				provider_selector = function(bufnr, filetype, buftype)
					return { "treesitter", "indent" }
				end,
			})
		end,
	},
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

@b1nhack b1nhack changed the title ufo causes weird behavior of nvim-cmp scroll_docs Conflict between ufo and reactive.nvim causes weird behavior of nvim-cmp scroll_docs May 20, 2024
b1nhack added a commit to b1nhack/nvim that referenced this issue May 20, 2024
This reverts commit 4b5ad30.
Conflict with nvim-ufo.
kevinhwang91/nvim-ufo#223
@kevinhwang91
Copy link
Owner

The issue is complex. reactive.nvim fires a redraw, and then ufo invokes vim.api.nvim_win_call to make the floating window of nvim-cmp broken.

I'm not sure if there's an issue of vim.api.nvim_set_decoration_provider used by ufo.

@b1nhack
Copy link
Author

b1nhack commented May 20, 2024

In which repository do you think this problem would be more simple and elegant to solve? Or should it be solved in conjunction with the reactive.nvim contributors?

@kevinhwang91
Copy link
Owner

Solved by ufo.

@b1nhack
Copy link
Author

b1nhack commented May 20, 2024

Ha ha ha, let me know if you need any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants