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

bug: keys are not working with Telescope on initial install #744

Closed
3 tasks done
ghost opened this issue Apr 24, 2023 · 3 comments · Fixed by #745
Closed
3 tasks done

bug: keys are not working with Telescope on initial install #744

ghost opened this issue Apr 24, 2023 · 3 comments · Fixed by #745
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Apr 24, 2023

Did you check docs and existing issues?

  • I have read all the lazy.nvim docs
  • I have searched the existing issues of lazy.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.9.0

Operating system/version

MacOS Ventura 13.3

Describe the bug

A small annoyance but something I noticed specifically with telescope.

My telescope spec looks like this:

return {
    "nvim-telescope/telescope.nvim",
    tag = "0.1.1",
    dependencies = {
        "nvim-lua/plenary.nvim",
        {
            "nvim-telescope/telescope-fzf-native.nvim",
            build = "make",
            config = function() require("telescope").load_extension("fzf") end,
        },
        "nvim-tree/nvim-web-devicons",
    },
    keys = {
        {
            "<leader><leader>",
            function() require("telescope.builtin").buffers() end,
            desc = "[ ] Find Existing Buffers",
        },
        {
            "<leader>/",
            function() require("telescope.builtin").current_buffer_fuzzy_find() end,
            desc = "[/] Fuzzily Search In Current Buffer",
        },
        {
            "<leader>sf",
            function() require("telescope.builtin").find_files() end,
            desc = "[S]earch [F]iles",
        },
        {
            "<leader>sp",
            function() require("telescope.builtin").git_files() end,
            desc = "[S]earch Git Files [P]",
        },
        {
            "<leader>sh",
            function() require("telescope.builtin").help_tags() end,
            desc = "[S]earch [H]elp",
        },
        {
            "<leader>sk",
            function() require("telescope.builtin").keymaps() end,
            desc = "[S]earch [K]eymaps",
        },
        {
            "<leader>sw",
            function() require("telescope.builtin").grep_string() end,
            desc = "[S]earch Current [W]ord",
        },
        {
            "<leader>sg",
            function() require("telescope.builtin").live_grep() end,
            desc = "[S]earch By [G]rep",
        },
    },
}

On first install none of the keys work. The Telescope command will be there but the keymaps won't do anything. It'll resolve itself if I quit and reopen.

I checked to see if other plugins did this and I also have neo-tree setup with the keys options like this:

return {
    "nvim-neo-tree/neo-tree.nvim",
    branch = "v2.x",
    dependencies = {
        "nvim-lua/plenary.nvim",
        "nvim-tree/nvim-web-devicons",
        "MunifTanjim/nui.nvim",
    },
    opts = {
        filesystem = {
            hijack_netrw_behavior = "open_current",
        },
    },
    keys = {
        {
            "<leader>fe",
            function()
                require("neo-tree.command").execute({
                    toggle = true,
                    reveal = true,
                })
            end,
            desc = "[F]ile [E]xplorer",
        },
    },
}

This one works fine on first install though.

Steps To Reproduce

  1. Create the repro.lua from below
  2. Run with nvim -u repro.lua
  3. Check if key works (I only did one for simplicity) (Mine doesn't work at this point)
  4. Close and reopen nvim
  5. Run it again with nvim -u repro.lua
  6. Check if key works again

Expected Behavior

For the keys to work on fist install.

Repro

-- DO NOT change the paths and don't remove the colorscheme
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.loop.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 = {
	"folke/tokyonight.nvim",
	{
		"nvim-telescope/telescope.nvim",
		tag = "0.1.1",
		dependencies = {
			"nvim-lua/plenary.nvim",
			{
				"nvim-telescope/telescope-fzf-native.nvim",
				build = "make",
				config = function()
					require("telescope").load_extension("fzf")
				end,
			},
			"nvim-tree/nvim-web-devicons",
		},
		keys = {
			{
				"fb",
				function()
					require("telescope.builtin").buffers()
				end,
				desc = "[ ] Find Existing Buffers",
			},
		},
	},
}

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

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@ghost ghost added the bug Something isn't working label Apr 24, 2023
@ghost
Copy link
Author

ghost commented Apr 24, 2023

Lol

I was getting an error due to this dependency

{
				"nvim-telescope/telescope-fzf-native.nvim",
				build = "make",
				config = function()
					require("telescope").load_extension("fzf")
				end,
},

It wasn't finding "fzf". Moved that config for the parent module aka telescope:

{
		"nvim-telescope/telescope.nvim",
		tag = "0.1.1",
		dependencies = {
			"nvim-lua/plenary.nvim",
			{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
			"nvim-tree/nvim-web-devicons",
		},
                config = function() require("telescope").load_extension("fzf") end,
		keys = {
			{
				"fb",
				function()
					require("telescope.builtin").buffers()
				end,
				desc = "[ ] Find Existing Buffers",
			},
		},
	},

And it works. I guess there's some loading shenanigan that tripped me up :(

@folke
Copy link
Owner

folke commented Apr 24, 2023

There's indeed a bug here. It's caused by the build part. I'm working on a fix. Due to build, the plugin gets loaded during startup (which is needed), but then when lazy creates lazy handlers, it won't for telescope since that is already loaded.

@ghost
Copy link
Author

ghost commented Apr 24, 2023

Fantastic!

Can confirm keys are working on first install now!

The only other quick check I made was moving config = function() require("telescope").load_extension("fzf") end back to the fzf-native spec and I still get hit with the error about not finding the "fzf" extension. But it works when I close and reopen.

I'm assuming it has something to do with executing the config before the build command is done.

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.

1 participant