nvim-telescope / telescope.nvim

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

builtin.find_files & builtin_git_files not showing files in results view #2697

Closed mattcarlotta closed 1 year ago

mattcarlotta commented 1 year ago

Description

When invoking the telescope.builtin.find_files or telescope.builtin.git_files, the preview window won't display file search results until an arrow key is pressed.

Neovim version

NVIM v0.10.0-dev-1051+gd0d4160dd1
Build type: RelWithDebInfo
LuaJIT 2.1.1693350652

Operating system and version

Endeavour OS rolling

Telescope version / branch / rev

telescope 0.1.2

checkhealth telescope

==============================================================================
telescope: health#telescope#check

- WARNING vim.health.report_start() is deprecated, use vim.health.start() instead. :help |deprecated|
  This feature will be removed in Nvim version 0.11

Checking for required plugins ~
- WARNING vim.health.report_ok() is deprecated, use vim.health.ok() instead. :help |deprecated|
  This feature will be removed in Nvim version 0.11
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 13.0.0
- OK fd: found fd 8.7.0

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

Steps to reproduce

  1. In the cmdline type: :Telescope find_files
  2. File results will appear empty
  3. Type in a file name to search
  4. The preview window will display the file, but the results file list will still appear empty

Expected behavior

The results view should contain a list of files on initial window open and should update the list as a search term is inputted.

Actual behavior

Command: screenshot-20230908-202329Z-current

Initial window view: screenshot-20230908-202335Z-current

Adding a search term: screenshot-20230908-202340Z-current

Arrow key pressed (up or down, doesn't matter): screenshot-20230908-202345Z-current

Removing a character from the search term (results list appears empty): screenshot-20230908-205349Z-current

Arrow key pressed (up or down, doesn't matter): screenshot-20230908-205354Z-current

Minimal config

---------------------------------
-- init.lua
---------------------------------
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    print("Installing 'folke/lazy.nvim'...")
    vim.fn.system({ "git", "clone", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "Luxed/ayu-vim",
        lazy = false,
        priority = 1000,
        as = "ayu",
        config = function()
            vim.cmd([[colorscheme ayu]])
        end,
    },
    {
        "nvim-telescope/telescope.nvim",
        tag = "0.1.2",
        dependencies = "nvim-lua/plenary.nvim",
    },
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        dependencies = {
            "JoosepAlviste/nvim-ts-context-commentstring",
        }
    },
    {
        "windwp/nvim-autopairs",
        event = "InsertEnter",
        config = function()
            require("nvim-autopairs").setup({
                disable_filetype = { "TelescopePrompt" },
            })
        end,
    },
    {
        "folke/trouble.nvim",
        config = function()
            require("trouble").setup({
                icons = false,
            })
        end,
    },
    {
        "lukas-reineke/indent-blankline.nvim",
        lazy = false,
        opts = {
            char = "┊",
            show_trailing_blankline_indent = false,
        },
    },
    {
        "numToStr/Comment.nvim",
        lazy = false,
        opts = {},
    },
    {
        "windwp/nvim-ts-autotag",
        event = "InsertEnter",
        branch = "main",
        dependencies = {
            "nvim-treesitter/nvim-treesitter",
        },
        config = true,
    },
    {
        "VonHeikemen/lsp-zero.nvim",
        branch = "v1.x",
        dependencies = {
            -- LSP Support
            { "neovim/nvim-lspconfig" },
            { "williamboman/mason.nvim" },
            { "williamboman/mason-lspconfig.nvim" },

            -- Autocompletion
            { "hrsh7th/nvim-cmp" },
            { "hrsh7th/cmp-buffer" },
            { "hrsh7th/cmp-path" },
            { "saadparwaiz1/cmp_luasnip" },
            { "hrsh7th/cmp-nvim-lsp" },
            { "hrsh7th/cmp-nvim-lua" },

            -- Snippets
            { "L3MON4D3/LuaSnip" },
            { "rafamadriz/friendly-snippets" },
        },
    },
    {
        "zbirenbaum/neodim",
        event = "LspAttach",
        config = function()
            require("neodim").setup({
                alpha = 0.5,
                blend_color = "#000000",
                update_in_insert = {
                    enable = true,
                    delay = 100,
                },
            })
        end,
    },
    {
        "nvim-lualine/lualine.nvim",
        dependencies = { "kyazdani42/nvim-web-devicons", opt = true },
    },
    "lewis6991/gitsigns.nvim",
    "theprimeagen/harpoon",
    "mbbill/undotree",
    "jay-babu/mason-null-ls.nvim"
})

---------------------------------
-- after/plugin/comment.lua
---------------------------------
local filetype = require("Comment.ft")

require("Comment").setup({
    mappings = {
        basic = true,
    },
    toggler = {
        line = "<leader>gcc",
        block = "<leader>gcb",
    },
    opleader = {
        line = "<leader>gc",
        block = "<leader>gb",
    },
    extra = {
        above = "<leader>gcO",
        below = "<leader>gco",
        eol = "<leader>gcA",
    },
    ignore = "^$", -- Ignore empty lines
    pre_hook = function(ctx)
        if vim.bo.filetype == "typescriptreact" then
            local c_utils = require("Comment.utils")
            local ts_context_utils = require("ts_context_commentstring.utils")
            local type = ctx.ctype == c_utils.ctype.linewise and "__default" or "__multiline"
            local location

            if ctx.ctype == c_utils.ctype.blockwise then
                location = ts_context_utils.get_cursor_location()
            elseif ctx.cmotion == c_utils.cmotion.v or ctx.cmotion == c_utils.cmotion.V then
                location = ts_context_utils.get_visual_start_location()
            end

            return require("ts_context_commentstring.internal").calculate_commentstring({
                key = type,
                location = location,
            })
        end
    end,
})

filetype.http = "# %s"

---------------------------------
-- after/plugin/gitsigns.lua
---------------------------------
require("gitsigns").setup({
    on_attach = function(bufnr)
        local gs = package.loaded.gitsigns

        local function map(mode, l, r, opts)
            opts = opts or {}
            opts.buffer = bufnr
            vim.keymap.set(mode, l, r, opts)
        end

        -- Navigation
        map("n", "]c", function()
            if vim.wo.diff then
                return "]c"
            end
            vim.schedule(function()
                gs.next_hunk()
            end)
            return "<Ignore>"
        end, { expr = true })

        map("n", "[c", function()
            if vim.wo.diff then
                return "[c"
            end
            vim.schedule(function()
                gs.prev_hunk()
            end)
            return "<Ignore>"
        end, { expr = true })

        -- Actions
        map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
        map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
        map("n", "<leader>hS", gs.stage_buffer)
        map("n", "<leader>hu", gs.undo_stage_hunk)
        map("n", "<leader>hR", gs.reset_buffer)
        map("n", "<leader>hp", gs.preview_hunk)
        map("n", "<leader>hb", function()
            gs.blame_line({ full = true })
        end)
        map("n", "<leader>tb", gs.toggle_current_line_blame)
        map("n", "<leader>hd", gs.diffthis)
        map("n", "<leader>hD", function()
            gs.diffthis("~")
        end)
        map("n", "<leader>td", gs.toggle_deleted)

        -- Text object
        map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
    end,
})

---------------------------------
-- after/plugin/harpoon.lua
---------------------------------
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
local keymap_set = vim.keymap.set

keymap_set("n", "<leader>a", mark.add_file)
keymap_set("n", "<C-e>", ui.toggle_quick_menu)

keymap_set("n", "<leader>1", function()
    ui.nav_file(1)
end)
keymap_set("n", "<leader>2", function()
    ui.nav_file(2)
end)
keymap_set("n", "<leader>3", function()
    ui.nav_file(3)
end)
keymap_set("n", "<leader>4", function()
    ui.nav_file(4)
end)

---------------------------------
-- after/plugin/lsp.lua
---------------------------------
local lsp = require("lsp-zero")

lsp.preset("recommended")

lsp.ensure_installed({
    "astro",
    "clangd",
    "eslint",
    "lua_ls",
    "rust_analyzer",
    "tailwindcss",
    "tsserver",
})

-- Fix Undefined global 'vim'
lsp.configure("lua_ls", {
    settings = {
        Lua = {
            diagnostics = {
                globals = { "vim" },
            },
        },
    },
})

local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }
local cmp_mappings = lsp.defaults.cmp_mappings({
    ["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
    ["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
    ["<C-y>"] = cmp.mapping.confirm({ select = true }),
    ["<C-Space>"] = cmp.mapping.complete(),
})

cmp_mappings["<Tab>"] = nil
cmp_mappings["<S-Tab>"] = nil

lsp.setup_nvim_cmp({
    mapping = cmp_mappings,
})

lsp.set_preferences({
    suggest_lsp_servers = false,
})

lsp.on_attach(function(client, bufnr)
    local opts = { buffer = bufnr, remap = false }
    local keymap_set = vim.keymap.set
    lsp.buffer_autoformat()

    keymap_set("n", "gd", function()
        vim.lsp.buf.definition()
    end, opts)
    keymap_set("n", "gt", function()
        vim.lsp.buf.type_definition()
    end, opts)
    keymap_set("n", "K", function()
        vim.lsp.buf.hover()
    end, opts)
    keymap_set("n", "<leader>ws", function()
        vim.lsp.buf.workspace_symbol()
    end, opts)
    keymap_set("n", "<leader>dof", function()
        vim.diagnostic.open_float()
    end, opts)
    keymap_set("n", "[d", function()
        vim.diagnostic.goto_next()
    end, opts)
    keymap_set("n", "]d", function()
        vim.diagnostic.goto_prev()
    end, opts)
    keymap_set("n", "<leader>ca", function()
        vim.lsp.buf.code_action()
    end, opts)
    keymap_set("n", "<leader>rr", function()
        vim.lsp.buf.references()
    end, opts)
    keymap_set("n", "<leader>rn", function()
        vim.lsp.buf.rename()
    end, opts)
    keymap_set("i", "<C-h>", function()
        vim.lsp.buf.signature_help()
    end, opts)
end)

lsp.setup()

vim.diagnostic.config({
    virtual_text = true,
})

---------------------------------
-- after/plugin/lualine.lua
---------------------------------
require("lualine").setup({
    options = {
        icons_enabled = true,
        theme = "auto",
        component_separators = { left = "", right = "" },
        section_separators = { left = "", right = "" },
        disabled_filetypes = {
            statusline = {},
            winbar = {},
        },
        ignore_focus = {},
        always_divide_middle = true,
        globalstatus = false,
        refresh = {
            statusline = 1000,
            tabline = 1000,
            winbar = 1000,
        },
    },
    sections = {
        lualine_a = {
            "mode",
        },
        lualine_b = {
            {
                "branch",
                color = { fg = "#aad541", bg = "#0f131a" },
            },
            {
                "diff",
                symbols = { added = " ", modified = "柳", removed = " " },
                diff_color = {
                    added = { fg = "#98be65" },
                    modified = { fg = "#ff8800" },
                    removed = { fg = "#ec5f67" },
                },
                color = { bg = "#0f131a" },
            },
            {
                "diagnostics",
                symbols = { error = "  ", warn = "  ", info = "  ", hint = " " },
                diagnostics_color = {
                    error = { fg = "#ec5f67" },
                    warn = { fg = "#ecbe7b" },
                    info = { fg = "#008080" },
                    hint = { fg = "#ecbe7b" },
                },
                color = { bg = "#0f131a" },
            },
        },
        lualine_c = { "filename" },
        lualine_x = { "progress", "filetype" },
        lualine_y = {
            {
                function()
                    local msg = "No Active Lsp"
                    local buf_ft = vim.api.nvim_buf_get_option(0, "filetype")
                    local clients = vim.lsp.get_active_clients()
                    if next(clients) == nil then
                        return msg
                    end
                    for _, client in ipairs(clients) do
                        local filetypes = client.config.filetypes
                        if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
                            return client.name
                        end
                    end
                    return msg
                end,
                icon = "   LSP:",
                color = { fg = "#555a65", bg = "#0f131a" },
            },
        },
        lualine_z = { "location" },
    },
    inactive_sections = {
        lualine_a = {},
        lualine_b = {},
        lualine_c = { "filename" },
        lualine_x = { "location" },
        lualine_y = {},
        lualine_z = {},
    },
    tabline = {},
    winbar = {},
    inactive_winbar = {},
    extensions = {},
})

---------------------------------
-- after/plugin/telescope.lua
---------------------------------
local builtin = require("telescope.builtin")

local keymap_set = vim.keymap.set

keymap_set("n", "<leader>pf", builtin.find_files, { desc = "[P]review [F]iles" })
keymap_set("n", "<leader>pg", builtin.git_files, { desc = "[P]review [G]it files" })
keymap_set("n", "<leader>ps", function()
    builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)

---------------------------------
-- after/plugin/treesitter.lua
---------------------------------
require("nvim-treesitter.configs").setup({
    ensure_installed = { "vimdoc", "javascript", "typescript", "c", "lua", "rust" },
    sync_install = false,
    auto_install = true,
    highlight = {
        enable = true,
        additional_vim_regex_highlighting = false,
    },
})
cristiansofronie commented 1 year ago

Isn't this the same issues as https://github.com/nvim-telescope/telescope.nvim/issues/2667 ? It seems to have been fixed you just have to update to the latest version of telescope.

mattcarlotta commented 1 year ago

Seems to be a similar problem as the linked issue, but updating doesn't appear to fix it (tag is set to 0.1.2): screenshot-20230908-211150Z-current screenshot-20230908-211205Z-current

mattcarlotta commented 1 year ago

That said, setting defaults = { sorting_strategy = "ascending" }, appears to fix it (only "descending" appears to broken): screenshot-20230908-211902Z-current

Feel free to close this issue if it's a duplicate to the linked issue!

cristiansofronie commented 1 year ago

Setting the sorting strategy fixed the previous issue also. This has to be the last issue. I don't know about tag. The issue was fixed in 3fae9c1e14910e6669bb8ecbb473aba6a9e13b33. That tag seems to be older. You will need to sync with master to get it fixed.

mattcarlotta commented 1 year ago

Syncing to branch = "0.1.x" instead of tag = "0.1.2" appears to have fixed it!

jamestrew commented 1 year ago

@Conni2461 maybe we need to cut a new tag for the latest commit of 0.1.x. I think this is causing an issue with vim-plug as well #2692

Conni2461 commented 1 year ago

I'll cut a new release