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

bug: global conceallevel modified by search #634

Closed
3 tasks done
rliebz opened this issue Oct 22, 2023 · 0 comments · Fixed by #639
Closed
3 tasks done

bug: global conceallevel modified by search #634

rliebz opened this issue Oct 22, 2023 · 0 comments · Fixed by #639
Labels
bug Something isn't working

Comments

@rliebz
Copy link

rliebz commented Oct 22, 2023

Did you check docs and existing issues?

  • I have read all the noice.nvim docs
  • I have searched the existing issues of noice.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.4

Operating system/version

macOS 14.0

Describe the bug

When enabling both noice and oil.nvim, the global conceallevel is modified after using the search function in an oil buffer. I suspect this behavior would occur in other situations where window-local options are set, but the included example uses oil.nvim because that's where I encountered it.

I'm not particularly well versed in how set/setlocal/setglobal options vs. window/buffer options are meant to work, but my guess is that the issue is here:

---@see https://github.com/neovim/neovim/issues/17810
function M.fix_incsearch()
---@type integer|nil
local conceallevel
vim.api.nvim_create_autocmd("CmdlineEnter", {
group = M.group,
callback = function(event)
if event.match == "/" or event.match == "?" then
conceallevel = vim.wo.conceallevel
vim.wo.conceallevel = 0
end
end,
})
vim.api.nvim_create_autocmd("CmdlineLeave", {
group = M.group,
callback = function(event)
if conceallevel and (event.match == "/" or event.match == "?") then
vim.wo.conceallevel = conceallevel
conceallevel = nil
end
end,
})
end

Where setting vim.wo.conceallevel also modifies vim.go.conceallevel.

From reading the help docs I think this might be more appropriate:

-vim.wo.conceallevel = conceallevel
+vim.api.nvim_set_option_value('conceallevel', conceallevel, { scope = 'local' })

And seems to fix the issue I'm experiencing locally, but figured I'd report the behavior and explain my reasoning rather than submit the fix as a guess when I don't fully understand what the other implications of that change my might be.

Steps To Reproduce

  1. nvim -u repro.lua .
    • You may need to exit and run this again, oil doesn't seem to hijack the file explorer in the same session that it's installed
  2. := vim.go.conceallevel
    • Prints 0
  3. / <esc>
    • When you type /, the conceallevel will change and numbers will be visible to the left of files in the directory
    • When you press <esc>, the conceallevel will revert to its previous value
    • No need to search for any text or confirm
  4. := vim.go.conceallevel
    • Prints 3

Expected Behavior

The global conceallevel should be restored to its original value (0) after the search command finishes.

Repro

-- 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 = {
	"folke/tokyonight.nvim",
	{
		"folke/noice.nvim",
		dependencies = {
			"MunifTanjim/nui.nvim",
		},
		opts = {},
	},
	-- add any other plugins here
	{ "stevearc/oil.nvim", opts = {} },
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@rliebz rliebz added the bug Something isn't working label Oct 22, 2023
@folke folke closed this as completed in c1591df Oct 25, 2023
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

Successfully merging a pull request may close this issue.

1 participant