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

Deleting marks from middle of the list breaks telescope extension #588

Open
waduhek opened this issue May 9, 2024 · 1 comment
Open

Comments

@waduhek
Copy link

waduhek commented May 9, 2024

Description of the issue

After adding multiple marks and deleting one or more of them from the middle of the list, the telescope extension does not display the rest of the marks after the deleted mark.

Reproduction steps

  1. Add 3 or more marks to the harpoon list.
  2. Delete any mark from the middle of the list using the telescope finder. Any mark apart from the last mark should do.
  3. Check the list of marks again in the telescope finder.

Log file

config_default#create_list_item lua/harpoon/ui.lua
HarpoonList:add { index = -1, item = { context = { col = 0, row = 1 }, value = "lua/harpoon/ui.lua" } }
config_default#create_list_item lua/harpoon/autocmd.lua
HarpoonList:add { index = -1, item = { context = { col = 0, row = 1 }, value = "lua/harpoon/autocmd.lua" } }
config_default#create_list_item lua/harpoon/config.lua
HarpoonList:add { index = -1, item = { context = { col = 0, row = 1 }, value = "lua/harpoon/config.lua" } }
config_default#BufLeave updating position 7 lua/harpoon/config.lua { context = { col = 0, row = 1 }, value = "lua/harpoon/config.lua" } to position { 1, 0 }
HarpoonList:remove { index = 2, item = { context = { col = 0, row = 1 }, value = "lua/harpoon/autocmd.lua" } }

Neovim Version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1713773202

Minimal Config

local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "nvim-telescope/telescope.nvim",
        tag = "0.1.5",
        dependencies = {
            "nvim-lua/plenary.nvim",
        },
    },
    {
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
        dependencies = {
            "nvim-lua/plenary.nvim",
            "nvim-telescope/telescope.nvim",
        },
        config = function ()
            require("telescope").load_extension("harpoon")
        end
    },
})

local harpoon = require("harpoon")
local telescope = require("telescope")

harpoon:setup()

vim.keymap.set(
    "n",
    "<leader>a",
    function()
        harpoon:list():add()
    end
)

vim.keymap.set("n", "<C-q>", telescope.extensions.harpoon.marks)

Additional context

This could be related to #555. But since that issue doesn't mention the telescope extension I thought of creating a new issue for it.

A workaround that I've found is to open the harpoon quick menu and delete the mark from there to get telescope to show the rest of the marks. Additionally, the harpoon quick menu shows a blank line for where the mark used be.

@ducktordanny
Copy link

Yeah, for me, it's the same and it's because remove_at changes the structure of the table by setting the list's item to nil:

Screenshot 2024-07-26 at 9 05 06

Though replacing the remove logic for table.remove, it seems it works again:

Screenshot 2024-07-26 at 9 05 47

I'm currently on the harpoon2 branch at commit 0378a6c, where I have the following diff which solves my issue:

diff --git a/lua/harpoon/list.lua b/lua/harpoon/list.lua
index 897122f..b65ef88 100644
--- a/lua/harpoon/list.lua
+++ b/lua/harpoon/list.lua
@@ -208,7 +208,7 @@ function HarpoonList:remove_at(index)
             "HarpoonList:removeAt",
             { item = self.items[index], index = index }
         )
-        self.items[index] = nil
+        table.remove(self.items, index)
         if index == self._length then
             self._length = determine_length(self.items, self._length)
         end

Later on today, I could create a PR for it, or if anyone has the time then feel free to do it. NOTE: It should probably be checked if other places use this nil logic and see if those work as expected.

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