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

Harpoon2 Telescope extension throws error in filter_empty_string #655

Open
weirdo-neutrino opened this issue Feb 9, 2025 · 1 comment
Open

Comments

@weirdo-neutrino
Copy link

The config I will refer to. Not the smallest, but I'm too lazy to rewrite which-key mappings.

vim.g.mapleader = " "
vim.g.maplocalleader = " "

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

if not (vim.uv or vim.loop).fs_stat(lazypath) then
	local out = vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--branch=stable",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})

	if vim.v.shell_error ~= 0 then
		vim.api.nvim_echo({
			{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
			{ out, "WarningMsg" },
			{ "\nPress any key to exit..." },
		}, true, {})
		vim.fn.getchar()
		os.exit(1)
	end
end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	spec = {
		{
			"folke/which-key.nvim",
			event = "VeryLazy",
			keys = {
				{
					"<leader>?",
					function()
						require("which-key").show({ global = false })
					end,
					desc = "Show buffer local keymaps (which-key)",
				},
			},
			init = function()
				vim.o.timeout = true
				vim.o.timeoutlen = 300
			end,
			config = true,
		},
		{
			"nvim-telescope/telescope.nvim",
			tag = "0.1.8",
			dependencies = {
				"folke/which-key.nvim",
				"nvim-lua/plenary.nvim",
				{
					"nvim-telescope/telescope-fzf-native.nvim",
					build = "make",
				},
				"nvim-telescope/telescope-ui-select.nvim",
				"nvim-tree/nvim-web-devicons",
				"nvim-treesitter/nvim-treesitter",
			},
			cmd = { "Telescope" },
			keys = {
				"<leader><space>",
				"<leader>/",
				"<leader>s/",
				"<leader>s.",
				"<leader>sd",
				"<leader>sf",
				"<leader>sg",
				"<leader>ss",
				"<leader>sw",
			},
			config = function()
				require("telescope").setup({
					defaults = {
						vimgrep_arguments = vim.list_extend({
							unpack(require("telescope/config").values.vimgrep_arguments),
						}, { "--hidden", "--glob", "!**/.git/*" }),
					},
					extensions = {
						["ui-select"] = {
							require("telescope/themes").get_dropdown({}),
						},
					},
					pickers = {
						find_files = {
							find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
						},
					},
				})

				require("telescope").load_extension("fzf")
				require("telescope").load_extension("ui-select")

				local function fuzzy_find()
					require("telescope/builtin").current_buffer_fuzzy_find(require("telescope/themes").get_dropdown({ winblend = 10, previewer = false }))
				end

				local function grep_open_files()
					require("telescope/builtin").live_grep({ grep_open_files = true, prompt_title = "Live Grep in Open Files" })
				end

				require("which-key").add({
					mode = { "n", "v" },
					noremap = true,
					silent = true,
					{ "<leader><space>", require("telescope/builtin").buffers, desc = "Search buffers" },
					{ "<leader>/", fuzzy_find, desc = "Fuzzy find in current buffer" },
					{ "<leader>s", group = "Telescope search" },
					{ "<leader>ss", require("telescope/builtin").builtin, desc = "Search Telescope builtins" },
					{ "<leader>s/", grep_open_files, desc = "Search in open files" },
					{ "<leader>sg", require("telescope/builtin").live_grep, desc = "Search in cwd" },
					{ "<leader>sw", require("telescope/builtin").grep_string, desc = "Search current word in cwd" },
					{ "<leader>sf", require("telescope/builtin").find_files, desc = "Search files in cwd" },
					{ "<leader>s.", require("telescope/builtin").oldfiles, desc = "Search recent files" },
					{ "<leader>sd", require("telescope/builtin").diagnostics, desc = "Search diagnostics" },
				})
			end,
		},
		{
			"ThePrimeagen/harpoon",
			branch = "harpoon2",
			dependecies = {
				"nvim-telescope/telescope.nvim",
				"nvim-lua/plenary.nvim",
				"folke/which-key.nvim",
			},
			config = function()
				require("harpoon"):setup()

				require("which-key").add({
					noremap = true,
					silent = true,
					{
						mode = { "n", "v", "i" },
						{ "<C-m>", function() require("telescope._extensions.harpoon").exports.marks() end, desc = "Harpoon: Select" },
						{ "<C-,>", function() require("harpoon"):list():prev({ ui_nav_wrap = true }) end, desc = "Harpoon: Previous" },
						{ "<C-.>", function() require("harpoon"):list():next({ ui_nav_wrap = true }) end, desc = "Harpoon: Next" },
					},
					{
						mode = { "n", "v" },
						{ "<leader>m", function() require("harpoon"):list():add() end, desc = "Harpoon a buffer" },
					},
				})
			end,
		},
	},
	checker = {
		enabled = true,
		notify = false,
	},
	change_detection = {
		notify = false,
	},
	profiling = {
		loader = true,
		require = true,
	},
})

Actions:

  • I open a buffer
  • I add a buffer to harpoon2
  • I open harpoon2 telescope extension
  • I press <C-d> to remove item from harpoon2

Result: Success

Actions:

  • I open 2 buffers
  • I add 2 buffers to harpoon2
  • I open harpoon2 telescope extension
  • I press <Up> to choose another item (IMPORTANT)
  • I press <C-d> to remove item from harpoon2
  • I press <C-d> to remove item from harpoon2

Result: Success

Actions:

  • I open 2 buffers
  • I add 2 buffers to harpoon2
  • I open harpoon2 telescope extension
  • I press <C-d> to remove item from harpoon2

Result:

Delete current mark(s)? [y/n]: yE5108: Error executing lua: ...re/nvim/lazy/harpoon/lua/telescope/_extens
ions/marks.lua:12: attempt to index a nil value                                                          
stack traceback:                                                                                         
        ...re/nvim/lazy/harpoon/lua/telescope/_extensions/marks.lua:12: in function 'filter_empty_string'
                                                                                                         
        ...re/nvim/lazy/harpoon/lua/telescope/_extensions/marks.lua:22: in function 'generate_new_finder'
                                                                                                         
        ...re/nvim/lazy/harpoon/lua/telescope/_extensions/marks.lua:83: in function 'key_func'           
        ...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:253: in function <...hare/nvim/lazy/t
elescope.nvim/lua/telescope/mappings.lua:252>                                                            
Press ENTER or type command to continue              

I also can no longer open harpoon2 telescope extension with the same error.

This is the file in question: https://github.com/ThePrimeagen/harpoon/blob/harpoon2/lua/telescope/_extensions/marks.lua

local function filter_empty_string(list)
    local next = {}
    for idx = 1, #list do
        if list[idx].value ~= "" then -- list[1] is nil at some point.
            table.insert(next, list[idx])
        end
    end

    return next
end

The function can be changed to prevent this error:

local function filter_empty_string(list)
    local next = {}
    for _, t in pairs(list) do
        if t.value ~= "" then
            table.insert(next, t)
        end
    end

    return next
end

nvim -V1 -v output:

NVIM v0.11.0-dev-1707+g52ff5e3032
Build type: RelWithDebInfo
LuaJIT 2.1.1736781742
Compilation: /usr/bin/cc -O2 -g -flto=auto -fno-fat-lto-objects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wno-conversion -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=auto  -DUNIT_TESTING -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -DUTF8PROC_STATIC -I/home/archivist/packages/neovim/.deps/usr/include/luajit-2.1 -I/home/archivist/packages/neovim/.deps/usr/include -I/home/archivist/packages/neovim/build/src/nvim/auto -I/home/archivist/packages/neovim/build/include -I/home/archivist/packages/neovim/build/cmake.config -I/home/archivist/packages/neovim/src -I/usr/include 

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/archivist/.local/share/nvim"

Run :checkhealth for more info

:checkhealth is OK

@ThePrimeagen
Copy link
Owner

I'll see if I can get to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants