ThePrimeagen/harpoon

Harpoon ui flashes when opening

Closed this issue ยท 5 comments

When I try to open harpoon ui it immediately closes
I press the keymap to open it, it flashes but doesn't stay open
(I am on harpoon2 branch)

Here is my config:

	{
		"ThePrimeagen/harpoon",
		dependencies = {
			"nvim-lua/plenary.nvim",
			"nvim-telescope/telescope.nvim",
		},
		branch = "harpoon2",

		keys = function(_, keys)
			local harpoon = require("harpoon")

			return vim.tbl_deep_extend("error", keys, {
				{
					"<leader>hh",
					function()
						harpoon.ui:toggle_quick_menu(harpoon:list())
					end,
					desc = "Toggle Harpoon",
				},
				{
					"<leader>uh",
					function()
						local conf = require("telescope.config").values
						local harpoon_files = require("harpoon"):list()

						local file_paths = {}
						for _, item in ipairs(harpoon_files.items) do
							table.insert(file_paths, item.value)
						end

						require("telescope.pickers")
							.new({}, {
								prompt_title = "Harpoon",
								finder = require("telescope.finders").new_table({
									results = file_paths,
								}),
								previewer = conf.file_previewer({}),
								sorter = conf.generic_sorter({}),
							})
							:find()
					end,
					desc = "Toggle Harpoon",
				},
				{
					"<leader>ha",
					function()
						harpoon:list():append()
					end,
					desc = "Add file to Harpoon",
				},
				{
					"[h",
					function()
						harpoon:list():prev()
					end,
					desc = "Previous Harpoon file",
				},
				{
					"]h",
					function()
						harpoon:list():next()
					end,
					desc = "Next Harpoon file",
				},
				{
					"<C-x>",
					function()
						vim.ui.input({ prompt = "Harpoon mark index: " }, function(input)
							local num = tonumber(input)
							if num then
								require("harpoon"):list():select(num)
							end
						end)
					end,
					desc = "Goto index of mark",
				},
			})
		end,
		config = function()
			local harpoon = require("harpoon")
			local extensions = require("harpoon.extensions")

			harpoon:setup()
			harpoon:extend(extensions.builtins.navigate_with_number())
			-- Add keymaps for harpoon window
			harpoon:extend({
				UI_CREATE = function(cx)
					vim.keymap.set("n", "<C-v>", function()
						harpoon.ui:select_menu_item({ vsplit = true })
					end, { buffer = cx.bufnr })

					vim.keymap.set("n", "<C-x>", function()
						harpoon.ui:select_menu_item({ split = true })
					end, { buffer = cx.bufnr })
				end,
			})
		end,
	},

@snikoletopoulos I have this problem when using the 'Pocco81/auto-save.nvim' plugin. When I turn off the autosave feature, the Harpoon UI persists as it should.
ref: #366

I have posted my fix there: #366 (comment).

That didn't work for me, nor the other suggestions in #366

If this help here is my config for auto-save

return {
  "Pocco81/auto-save.nvim",
  event = { "User AstroFile", "InsertEnter" },
  opts = {
    debounce_delay = 1000,
    execution_message = {
        message = function()
        return ""
      end,
    },
    condition = function(buf)
      return require("auto-save.utils.data").not_in(
        vim.fn.getbufvar(buf, "&filetype"),
	{ "harpoon" }
      )
      end,
    },
    callbacks = {
      before_saving = function()
        -- save global autoformat status
        vim.g.OLD_AUTOFORMAT = vim.g.autoformat_enabled

        vim.g.autoformat_enabled = false
        vim.g.OLD_AUTOFORMAT_BUFFERS = {}
        -- disable all manually enabled buffers
        for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
          if vim.b[bufnr].autoformat_enabled then
            table.insert(vim.g.OLD_BUFFER_AUTOFORMATS, bufnr)
            vim.b[bufnr].autoformat_enabled = false
          end
        end
      end,
      after_saving = function()
        -- restore global autoformat status
        vim.g.autoformat_enabled = vim.g.OLD_AUTOFORMAT
        -- reenable all manually enabled buffers
        for _, bufnr in ipairs(vim.g.OLD_AUTOFORMAT_BUFFERS or {}) do
          vim.b[bufnr].autoformat_enabled = true
        end
      end,
    },
  },
}

The only thing I can suggest is making the auto-save's config as small as possible and trying all the solutions one by one. If some solution will work, only then you can restore your initial settings bit by bit, checking if it still works.

Also there is a potential problem of some other plugin messing with the harpoon menu window. So trying to make a MWE of your entire Neovim settings is the best approach.

I tried it with a minimal config and still had the same problem.

I ended up using the fork that you mention here #366 (comment) and it worked fine.