nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.77k stars 833 forks source link

lsp_references() pickers not included in cached pickers (Telescope resume) #2952

Closed tristone13th closed 7 months ago

tristone13th commented 7 months ago

Description

lsp_references() pickers not included in cached pickers (Telescope resume)

Neovim version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

Operating system and version

CentOS 9

Telescope version / branch / rev

master

checkhealth telescope

telescope: require("telescope.health").check()
  3
  4 Checking for required plugins
  5 - OK plenary installed.
  6 - OK nvim-treesitter installed.
  7
  8 Checking external dependencies
  9 - OK rg: found ripgrep 13.0.0 (rev af6b6c543b)
 10 - WARNING fd: not found. Install [sharkdp/fd](https://github.com/sharkdp/fd) for extended capabilities
 11
 12 ===== Installed extensions =====
 13
 14 Telescope Extension: `fzf`
 15 - OK lib working as expected
 16 - OK file_sorter correctly configured
 17 - OK generic_sorter correctly configured
 18
 19 Telescope Extension: `vim_bookmarks`
 20 - No healthcheck provided

Steps to reproduce

  1. setup lsp and put the cursor under a token
  2. run :lua require('telescope.builtin').lsp_references()
  3. close the telescope picker
  4. run :Telescope resume

Expected behavior

Show the last picker

Actual behavior

Neovim shows "No cached picker(s)"

Minimal config

local function telescope()
    local function Enter(prompt_bufnr)
        local actions = require("telescope.actions")
        local selection = require("telescope.actions.state").get_selected_entry()
        if vim.fn.isdirectory(selection.path) ~= 0 then -- project
            -- cd to new project
            local dir = vim.fn.fnamemodify(selection.path, ":p:h")
            require("telescope.actions").close(prompt_bufnr)

            -- change directory
            ChangeProject(dir)

            -- if we jump from the closeall function, delete all old buffers
            if #Bufnrs ~= 0 then
                for _, b in ipairs(Bufnrs) do
                    if vim.api.nvim_buf_is_valid(b) then
                        vim.api.nvim_buf_delete(b, {})
                    end
                end
                Bufnrs = {}
            end
            vim.cmd("stopinsert")
        elseif selection["col"] then -- live_grep, todo, diag
            actions.close(prompt_bufnr)
            if selection["filename"] == nil then
                vim.cmd(string.format("silent edit %s", selection.path))
            else --symbol
                if vim.fn.expand("%:p") ~= selection.filename then
                    vim.cmd(string.format("silent edit %s", selection.filename))
                end
            end
            vim.api.nvim_win_set_cursor(0, { selection["lnum"], selection["col"] + 1 })
            -- return to normal mode
            vim.cmd("stopinsert")
        else -- jump to file directly
            actions.close(prompt_bufnr)
            if selection.path == nil then -- buffers
                vim.cmd(string.format("buffer %s", selection.bufnr))
            else -- find_files
                if vim.fn.expand("%:p") ~= selection.path then
                    vim.cmd(string.format("silent edit %s", selection.path))
                end
            end
            vim.cmd("stopinsert")
        end
    end

    require("telescope").setup({
        defaults = {
            mappings = {
                i = {
                    ["<Enter>"] = Enter,
                },
                n = {
                    ["<Enter>"] = Enter,
                },
            },
            layout_strategy = "vertical",
            layout_config = {
                width = 0.99,
                height = 0.99,
                preview_height = 0.4,
                preview_cutoff = 0,
                anchor = "N",
                prompt_position = "bottom",
                mirror = true,
            },
            file_ignore_patterns = {
                -- remove all the bkc/rr-cache stuffs
                "bkc",
            },
        },
        pickers = {
            find_files = {
                find_command = { "rg", "--no-ignore", "--ignore-case", "--files", "--hidden", "-g=!.git/" },
                prompt_prefix = "🍉",
            },
        },
        extensions = {
            project = {
                base_dirs = {
                    { path = "~/.config" }, --.config
                },
            },
        },
    })

    require("telescope").load_extension("fzf")
    require("telescope").load_extension("vim_bookmarks")
end
jamestrew commented 7 months ago

We recently merged a PR to not cache pickers with empty prompts by default. https://github.com/nvim-telescope/telescope.nvim/pull/2817

You can disable this like so

require("telescope").setup({
  defaults = {
    cache_picker = {
      ignore_empty_prompt = false,
    },
  },
})

:h telescope.defaults.cache_picker

But I'm having second thoughts on having this enabled by default since for lsp pickers (and maybe others), it's maybe reasonable to use without prompts often times.

@Conni2461 should be undo the default? We could make the default picker specific but this comes down to personal opinion and workflow so I'm not really like this idea.

tristone13th commented 7 months ago

Thanks, it works!

Conni2461 commented 7 months ago

Hmm i dont have that strong preferences, i dont use resume and i also dont see why you would resume something that you dont have any filtering done yet. I think send to qflist is the superior and i use that basically always.

So yeah if you disagree feel free to change this default, i was mostly argueing from the perspective of find_files/live_grep because if you havent inserted a query why would you wanna cache it, just run it again

TisnKu commented 7 months ago

I can contribute another case. I use vim.fn.input to get initial search term and use telescope to fuzzy search. If I can find desired result in first few lines and does not type further characters, then resume won't work. vim.keymap.set("n", "<leader>rg", ":lua require('telescope.builtin').grep_string({search = vim.fn.input('Search term: ')})<CR>", opts)

xim commented 7 months ago

I often use e.g. lsp_references and other pickers that are useful without filtering.

Hover over a symbol, get references, go to a reference.

Find out it's not what I wanted, resume telescope, find another.

lather, rinse repeat.

jamestrew commented 7 months ago

I'm not a big resume user so I don't have strong opinions on this but I think I'll flip the default for it.