Open weisbrja opened 1 week ago
Maybe this has something to do with inheriting the values. I read somewhere that the behavior isn't well documented yet.
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.
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.
@jamestrew I tested the minmal config on my device and it reproduced the bug. Please reopen this issue.
Ok I haven't had a chance to try myself but I'll try to take a look.
I think the above PR will fix this. If you can give it a try and confirm, that'll be helpful.
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:
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.
I just don't understand why preview
can be overriden from anywhere, if the global default is false
. Why does it's value matter?
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)
I'll try to reproduce the bug in a more minimal setup and post the config here.
nvim -nu minimal.lua
<Space>H
.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",
})
@jamestrew could you reproduce the issue with my minimal config?
Description
When using
to setup telescope, the find_files picker still shows a preview. I also tried passing
preview = false
directly into thefind_files
function, but that didn't work either.Neovim version
Operating system and version
Arch Linux x86_64
Telescope version / branch / rev
master
checkhealth telescope
Steps to reproduce
nvim -nu minimal.lua
<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