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

preview flag does not get overriden (for find_files picker) #3325

Open
weisbrja opened this issue Oct 11, 2024 · 14 comments · May be fixed by #3327
Open

preview flag does not get overriden (for find_files picker) #3325

weisbrja opened this issue Oct 11, 2024 · 14 comments · May be fixed by #3327
Labels
bug Something isn't working

Comments

@weisbrja
Copy link

weisbrja commented Oct 11, 2024

Description

When using

opts = {
	defaults = { preview = true },
	pickers = { find_files = { preview = false } }
}

to setup telescope, the find_files picker still shows a preview. I also tried passing preview = false directly into the find_files function, but that didn't work either.

Neovim version

NVIM v0.10.2
Build type: RelWithDebInfo
LuaJIT 2.1.1725453128

Operating system and version

Arch Linux x86_64

Telescope version / branch / rev

master

checkhealth telescope

telescope: health#telescope#check

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.1
- OK fd: found fd 10.2.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

  1. nvim -nu minimal.lua
  2. press <Space>f

Expected behavior

I expected the find_files picker to not show a preview.

Actual behavior

The find_files picker showed a preview.

Minimal config

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.uv.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 = {
	{
		"nvim-telescope/telescope.nvim",
		keys = {
			{
				"<Space>f",
				function()
					require("telescope.builtin").find_files() -- also reproducible with { preview = true } as args
				end,
			},
		},
		dependencies = { "nvim-lua/plenary.nvim" },
		opts = {
			defaults = { preview = true },
			pickers = { find_files = { preview = false } },
		},
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})
@weisbrja weisbrja added the bug Something isn't working label Oct 11, 2024
@weisbrja
Copy link
Author

Maybe this has something to do with inheriting the values. I read somewhere that the behavior isn't well documented yet.

@jamestrew
Copy link
Contributor

This is a lazy.nvim usage error.

You need to put the pickers table into the opts table.
I can elaborate more when I'm not on my phone but hope this helps.

@weisbrja
Copy link
Author

Sorry, I made a typo in the minimal reproduction file. I meant the pickers to be in the opts table. This bug is not a configuration issue. I'll edit the issue.

@weisbrja
Copy link
Author

@jamestrew I tested the minmal config on my device and it reproduced the bug. Please reopen this issue.

@jamestrew
Copy link
Contributor

Ok I haven't had a chance to try myself but I'll try to take a look.

@jamestrew jamestrew reopened this Oct 12, 2024
jamestrew added a commit to jamestrew/telescope.nvim that referenced this issue Oct 15, 2024
According to `:h telescope.defaults.preview`, we should be able to do
`preview=false` to disable the previewer for pickers. With how picker
options resolve inheritance, something like this should work.

```lua
require('telescope').setup {
  defaults = { preview = true },
  pickers = { find_files = { preview = false } }
}
```
Here, find_files should not show a previewer but it previously would.

Corrects this by checking if `opts.preview` is explicitly set to
`false`. In which case, we won't show the previewer.

Closes nvim-telescope#3325
@jamestrew jamestrew linked a pull request Oct 15, 2024 that will close this issue
@jamestrew
Copy link
Contributor

I think the above PR will fix this.
If you can give it a try and confirm, that'll be helpful.

@weisbrja
Copy link
Author

Tried the PR with my own config. It fixes the issue that preview couldn't be overriden from the pickers section. But I also have a custom picker which I create via require("telescope.pickers").new(opts, defaults). Even if I set preview = false in defaults and opts, the picker will still show a preview, because it probably still uses the global preview setting.

I also think that this might be a more systemic issue and that just fixing it for the preview option might not be enough. For me it's fine though 🤷

@weisbrja
Copy link
Author

I have to add that layout_strategy for example can be overridden from anywhere. So maybe it's not a systemic bug, but rather effects just preview. Just guessing though.

@weisbrja
Copy link
Author

I just don't understand why preview can be overriden from anywhere, if the global default is false. Why does it's value matter?

@jamestrew
Copy link
Contributor

I also have a custom picker which I create via require("telescope.pickers").new(opts, defaults). Even if I set preview = false in defaults and opts, the picker will still show a preview, because it probably still uses the global preview setting.

Do you have an example of this I can see? I'm trying this rudimentary find_files example I made and I'm not getting a preview as I'd expect.

vim.keymap.set("n", "<space>f", function()
  local pickers = require("telescope.pickers")
  local finders = require("telescope.finders")
  local make_entry = require("telescope.make_entry")
  local conf = require("telescope.config").values

  local files = vim.trim(vim.system({ "fd", "-tf" }):wait().stdout)
  files = vim.split(files, "\n")
  local opts = { preview = false }
  pickers
    .new(opts, {
      prompt_title = "colors",
      finder = finders.new_table({
        results = files,
        entry_maker = make_entry.gen_from_file(opts),
      }),
      previewer = conf.file_previewer(opts),
      sorter = conf.generic_sorter(opts),
    })
    :find()
end)

@weisbrja
Copy link
Author

I'll try to reproduce the bug in a more minimal setup and post the config here.

@weisbrja
Copy link
Author

weisbrja commented Oct 16, 2024

Steps to reproduce

  1. run nvim -nu minimal.lua
  2. press <Space>H.

Minimal config

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.uv.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 = {
	{
		"jamestrew/telescope.nvim",
		branch = "preview-opt-inheritance",
		keys = {
			{
				-- This seems fixed.
				"<Space>f",
				function()
					require("telescope.builtin").find_files()
				end,
			},
			-- This does not.
			"<Space>H",
		},
		dependencies = { "nvim-lua/plenary.nvim" },
		opts = {
			defaults = { preview = true },
			pickers = { find_files = { preview = false } },
		},
		config = function(_, opts)
			local telescope = require("telescope")
			telescope.setup(opts)

			local conf = require("telescope.config").values
			vim.keymap.set("n", "<Space>H", function()
				local files = vim.split(vim.trim(vim.system({ "fd", "-tf" }):wait().stdout), "\n")

				-- FIXME: global preview option still can't be overridden here
				require("telescope.pickers")
					.new({
						preview = false,
					}, {
						preview = false,
						prompt_title = "Harpoon",
						-- layout_strategy = "center",
						finder = require("telescope.finders").new_table({
							results = files,
							-- I tried this, but it didn't change anything and I didn't need it before.
							-- entry_maker = require("telescope.make_entry").gen_from_file({ preview = false }),
						}),
						previewer = conf.file_previewer({}),
						sorter = conf.generic_sorter({}),
					})
					:find()
			end)
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

@weisbrja
Copy link
Author

@jamestrew could you reproduce the issue with my minimal config?

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.

2 participants