telescope.nvim icon indicating copy to clipboard operation
telescope.nvim copied to clipboard

preview flag does not get overriden (for find_files picker)

Open weisbrja opened this issue 1 year ago • 14 comments

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 avatar Oct 11 '24 15:10 weisbrja

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

weisbrja avatar Oct 11 '24 15:10 weisbrja

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.

jamestrew avatar Oct 11 '24 17:10 jamestrew

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 avatar Oct 11 '24 22:10 weisbrja

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

weisbrja avatar Oct 11 '24 22:10 weisbrja

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

jamestrew avatar Oct 12 '24 12:10 jamestrew

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

jamestrew avatar Oct 15 '24 01:10 jamestrew

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 :shrug:

weisbrja avatar Oct 15 '24 11:10 weisbrja

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 avatar Oct 15 '24 11:10 weisbrja

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

weisbrja avatar Oct 15 '24 11:10 weisbrja

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)

jamestrew avatar Oct 16 '24 01:10 jamestrew

https://gitlab.com/weisbrja/dotfiles/-/blob/74cabf5158869233283b0e74c4b18fd213fe3c05/.config/nvim/lua/plugins/telescope.lua

weisbrja avatar Oct 16 '24 07:10 weisbrja

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

weisbrja avatar Oct 16 '24 07:10 weisbrja

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 avatar Oct 16 '24 07:10 weisbrja

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

weisbrja avatar Oct 19 '24 21:10 weisbrja

@jamestrew I've tested and confirmed that does infact fix the issue. please feel free to go ahead and merge & release :)

mattp- avatar Nov 25 '24 18:11 mattp-

Commenting here to please just fix this by merging @jamestrew

weisbrja avatar Nov 06 '25 23:11 weisbrja