ThePrimeagen / harpoon

MIT License
6.74k stars 364 forks source link

problem with vue #444

Open momozahara opened 8 months ago

momozahara commented 8 months ago

create project using vite add multiple vue file open file 1 open file 2 then error

E5108: Error executing lua BufWinEnter Autocommands for "*"..function <SNR>11_Highlight_Matching_Pair, line 149: Vim(call):E801: ID already taken: 3                                                             
stack traceback:                                                                                                                                                                                                 
        [C]: in function 'bufload'                                                                                                                                                                               
        ...ut/.local/share/nvim/lazy/harpoon/lua/harpoon/config.lua:110: in function 'select'                                                                                                                    
        ...nbut/.local/share/nvim/lazy/harpoon/lua/harpoon/list.lua:182: in function 'select'                                                                                                                    
        [string ":lua"]:1: in main chunk                      
kimabrandt-flx commented 8 months ago

I see the same error, when trying to open a file with associated swap-file.

When opening the first item in a list: :lua require("harpoon"):list():select(1), I get the following message and error:

Found a swap file by the name "....swp"
          owned by: ...
          ...
      NEWER than swap file!

(1) Another program may be editing the same file.  ...
(2) An edit session for this file crashed.
    ...

E5108: Error executing lua: Vim:E325: ATTENTION
stack traceback:
        [C]: in function 'bufload'
        .../harpoon/config.lua:110: in function 'select'
        .../harpoon/list.lua:182: in function 'select'
        ...
Press ENTER or type command to continue

This should be pretty simple to reproduce!?

After pressing enter, a blank buffer is shown. When trying ...:select(1) once more, the file is loaded into the buffer and shown. Edit-1: When trying to switch between ...:select(2) and ...:select(1), the file is not shown anymore!? Edit-2: The issue with Edit-1 only shows, when showing files with relative paths (added with require("harpoon"):list():append()).

This happens with neovim v0.9.4 and installed Lazy and harpoon2. I didn't try without Lazy.

Commenting out line 110 in lua/harpoon/config.lua seemed to work, at first. But it causes another issue, where the file/buffer is not loaded with ...:select(1), when preceded by ...:select(2) (load a different file beforehand). Edit-3: This seems to be caused by the relative paths, mentioned in Edit-2!? Meaning: this change seems to be working, when using absolute paths!? Edit-4: The issue in Edit-{1,2,3} - concerning relative paths affecting each other - have been addressed in PR #503. I think I tested with files, such as: 1234.txt, 123.txt, aso. :\

mudrii commented 8 months ago

Having same issue just using the shortcut

E5108: Error executing lua: BufWinEnter Autocommands for "*"..function <SNR>13_Highlight_Matching_Pair, line 149: Vim(call):E801: ID already taken: 3                   
stack traceback:
        [C]: in function 'bufload'

below configuration in lua

-- Harpoon configuration
 local harpoon = require("harpoon") 
 harpoon:setup()
    vim.keymap.set("n", "<leader>ha", function() harpoon:list():append() end)
     vim.keymap.set("n", "<leader>e", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
     vim.keymap.set("n", "<leader>1", function() harpoon:list():select(1) end) 
     vim.keymap.set("n", "<leader>2", function() harpoon:list():select(2) end)
     vim.keymap.set("n", "<leader>3", function() harpoon:list():select(3) end)
     vim.keymap.set("n", "<leader>4", function() harpoon:list():select(4) end)

     vim.keymap.set("n", "<C-S-P>", function() harpoon:list():prev() end)
     vim.keymap.set("n", "<C-S-N>", function() harpoon:list():next() end)
Discusser commented 8 months ago

I'm facing the same issue with the default configuration

back2Lobby commented 8 months ago

well mine is simple Laravel blade project but It's same for me using harpoon 2 rn.

E5108: Error executing lua: BufWinEnter Autocommands for "*"..function <SNR>25_Highlight_Matching_Pair, line 149: Vim(call):E801: ID already t
aken: 3
stack traceback:
        [C]: in function 'bufload'
        ...by/.local/share/nvim/lazy/harpoon/lua/harpoon/config.lua:111: in function 'select'
        ...obby/.local/share/nvim/lazy/harpoon/lua/harpoon/list.lua:182: in function 'select'
        ...obby/.local/share/nvim/lazy/harpoon/lua/harpoon/list.lua:200: in function 'next'
        ...ck2lobby/.config/nvim/lua/back2lobby/plugins/harpoon.lua:21: in function <...ck2lobby/.config/nvim/lua/back2lobby/plugins/harpoon.lua:21>

and here is the line 21 in my harpoon.lua:

vim.keymap.set("n", "<A-n>", function() harpoon:list():next() end)
kimabrandt-flx commented 8 months ago

The underlying issue seems to be in (n)vim!? Bram is pointing out a workaround!? So, maybe just ignore the error!?

diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua
index a759297..d77c880 100644
--- a/lua/harpoon/config.lua
+++ b/lua/harpoon/config.lua
@@ -108,7 +108,7 @@ function M.get_default_config()
                     bufnr = vim.fn.bufnr(list_item.value, true)
                 end
                 if not vim.api.nvim_buf_is_loaded(bufnr) then
-                    vim.fn.bufload(bufnr)
+                    pcall(vim.fn.bufload, bufnr)
                     vim.api.nvim_set_option_value("buflisted", true, {
                         buf = bufnr,
                     })
kimabrandt-flx commented 7 months ago

This change worked for me, too:

diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua
index a759297..262845f 100644
--- a/lua/harpoon/config.lua
+++ b/lua/harpoon/config.lua
@@ -108,6 +108,7 @@ function M.get_default_config()
                     bufnr = vim.fn.bufnr(list_item.value, true)
                 end
                 if not vim.api.nvim_buf_is_loaded(bufnr) then
+                    vim.api.nvim_set_current_buf(bufnr)
                     vim.fn.bufload(bufnr)
                     vim.api.nvim_set_option_value("buflisted", true, {
                         buf = bufnr,
Discusser commented 7 months ago

This change worked for me, too:

diff --git a/lua/harpoon/config.lua b/lua/harpoon/config.lua
index a759297..262845f 100644
--- a/lua/harpoon/config.lua
+++ b/lua/harpoon/config.lua
@@ -108,6 +108,7 @@ function M.get_default_config()
                     bufnr = vim.fn.bufnr(list_item.value, true)
                 end
                 if not vim.api.nvim_buf_is_loaded(bufnr) then
+                    vim.api.nvim_set_current_buf(bufnr)
                     vim.fn.bufload(bufnr)
                     vim.api.nvim_set_option_value("buflisted", true, {
                         buf = bufnr,

It works but certain buffers opened with harpoon can't be closed anymore, it's very weird.

kimabrandt-flx commented 7 months ago

... It works but certain buffers opened with harpoon can't be closed anymore, it's very weird.

How do you close your buffers? Does it work with :bd :bw?

Discusser commented 7 months ago

... It works but certain buffers opened with harpoon can't be closed anymore, it's very weird.

How do you close your buffers? Does it work with :bd :bw?

I tried with <leader>x keybinding, :bd, and :bw, none work. I managed to find a way to reproduce the issue:

Here's an example on my machine: https://github.com/ThePrimeagen/harpoon/assets/47938380/48a5280a-b58b-43b6-a72f-48ab9dabdc84

kimabrandt-flx commented 7 months ago

... How do you close your buffers? Does it work with :bd :bw?

I tried with <leader>x keybinding, :bd, and :bw, none work. I managed to find a way to reproduce the issue:

  • Open a project with at least 3 marked buffers
  • Open the three buffers with harpoon
  • Close them one by one, the one that was opened last will close but not others ...

I cannot reproduce your issue!? Are you doing anything special with tabbing? Any other plugins, that could be interfering?!

Discusser commented 7 months ago

... How do you close your buffers? Does it work with :bd :bw?

I tried with <leader>x keybinding, :bd, and :bw, none work. I managed to find a way to reproduce the issue:

  • Open a project with at least 3 marked buffers
  • Open the three buffers with harpoon
  • Close them one by one, the one that was opened last will close but not others ...

I cannot reproduce your issue!? Are you doing anything special with tabbing? Any other plugins, that could be interfering?!

Sorry for the late response, I've managed to pin down the issue to this line in my nvim config: harpoon:extend(extensions.builtins.navigate_with_number()); The problem does not occur when opening a buffer with the enter key, however if you open it with the number keys (1, 2, 3...) it does occur.

Here is a minimal configuration required to reproduce this using NvChad:

-- chadrc.lua
local M = {}

M.plugins = "custom.plugins"

return M
-- plugins.lua
local plugins = {
  {
    "ThePrimeagen/harpoon",
    branch = "harpoon2",
    dependencies = { "nvim-lua/plenary.nvim" },
    keys = {
      {
        "<C-e>",
        function()
          require("harpoon").ui:toggle_quick_menu(require("harpoon"):list())
        end,
        desc = "Harpoon toggle quick menu",
      },
    },
    config = function()
      require "custom.configs.harpoon"
    end,
  },
}

return plugins
-- configs/harpoon.lua
local config = {}

local harpoon = require "harpoon"
harpoon:setup()

harpoon:extend(extensions.builtins.navigate_with_number());

return config
kimabrandt-flx commented 7 months ago

... Sorry for the late response, I've managed to pin down the issue to this line in my nvim config: harpoon:extend(extensions.builtins.navigate_with_number()); The problem does not occur when opening a buffer with the enter key, however if you open it with the number keys (1, 2, 3...) it does occur. ...

You're definitely on to something! Which means, this should probably have its own issue!? Since I don't think, that these two are related!?

I can reproduce your issue now; with NvChad and also vanilla Neovim. Here's an even more minimal configuration:

vim.keymap.set("n", "1", function()
    require("harpoon"):list():select(1)
end)
vim.keymap.set("n", "2", function()
    require("harpoon"):list():select(2)
end)

The issue - that you're describing - is happening, when you're choosing 1, then 2, while the UI/picker is open, and then try to close the buffers. Something weird is happening!?

My guess is, that the builtins.navigate_with_number() was never meant to be used from inside the UI/picker!?

Discusser commented 7 months ago

... Sorry for the late response, I've managed to pin down the issue to this line in my nvim config: harpoon:extend(extensions.builtins.navigate_with_number()); The problem does not occur when opening a buffer with the enter key, however if you open it with the number keys (1, 2, 3...) it does occur. ...

You're definitely on to something! Which means, this should probably have its own issue!? Since I don't think, that these two are related!?

I can reproduce your issue now; with NvChad and also vanilla Neovim. Here's an even more minimal configuration:

vim.keymap.set("n", "1", function()
    require("harpoon"):list():select(1)
end)
vim.keymap.set("n", "2", function()
    require("harpoon"):list():select(2)
end)

The issue - that you're describing - is happening, when you're choosing 1, then 2, while the UI/picker is open, and then try to close the buffers. Something weird is happening!?

My guess is, that the builtins.navigate_with_number() was never meant to be used from inside the UI/picker!?

I can confirm what you said. I really don't know how to go about fixing this since fixing it would require finding the root cause of the problem, but there is a very simple workaround (I don't really know how to use diff command like you did):

-- harpoon/extensions/init.lua

function Builtins.navigate_with_number()
    return {
        UI_CREATE = function(cx)
            for i = 1, 9 do
                vim.keymap.set("n", "" .. i, function()
+                   require("harpoon").ui:close_menu()
                    require("harpoon"):list():select(i)
                end, { buffer = cx.bufnr })
            end
        end,
    }
end

Since you said that the problem only happens with UI open, closing the UI will fix it for now, though I think it'd be much wiser to find out why having the UI open causes an issue

Discusser commented 7 months ago

... Sorry for the late response, I've managed to pin down the issue to this line in my nvim config: harpoon:extend(extensions.builtins.navigate_with_number()); The problem does not occur when opening a buffer with the enter key, however if you open it with the number keys (1, 2, 3...) it does occur. ...

You're definitely on to something! Which means, this should probably have its own issue!? Since I don't think, that these two are related!? I can reproduce your issue now; with NvChad and also vanilla Neovim. Here's an even more minimal configuration:

vim.keymap.set("n", "1", function()
    require("harpoon"):list():select(1)
end)
vim.keymap.set("n", "2", function()
    require("harpoon"):list():select(2)
end)

The issue - that you're describing - is happening, when you're choosing 1, then 2, while the UI/picker is open, and then try to close the buffers. Something weird is happening!? My guess is, that the builtins.navigate_with_number() was never meant to be used from inside the UI/picker!?

I can confirm what you said. I really don't know how to go about fixing this since fixing it would require finding the root cause of the problem, but there is a very simple workaround (I don't really know how to use diff command like you did):

-- harpoon/extensions/init.lua

function Builtins.navigate_with_number()
    return {
        UI_CREATE = function(cx)
            for i = 1, 9 do
                vim.keymap.set("n", "" .. i, function()
+                   require("harpoon").ui:close_menu()
                    require("harpoon"):list():select(i)
                end, { buffer = cx.bufnr })
            end
        end,
    }
end

Since you said that the problem only happens with UI open, closing the UI will fix it for now, though I think it'd be much wiser to find out why having the UI open causes an issue

The PR https://github.com/ThePrimeagen/harpoon/pull/486 somehow solves the problem I experienced (see https://github.com/ThePrimeagen/harpoon/pull/486/commits/17832718394f108f1445a44c4c4ea671676461c7). With this my temporary fix of require("harpoon").ui:close_menu() is no longer required.

al-ce commented 5 months ago

The PR #486 somehow solves the problem I experienced (see 1783271). With this my temporary fix of require("harpoon").ui:close_menu() is no longer required.

That PR makes the navigate_with_number extension use the same selection function that would be called if you pressed enter over a menu item, which ultimately calls close_menu

ThePrimeagen commented 5 months ago

Marking This harpoon 2 Requirement.

kimabrandt-flx commented 5 months ago

This issue was addressed in #430 and fixed by 747169f. So, maybe this can be closed!?

Sorry, it's still an issue! The location of vim.api.nvim_set_current_buf(bufnr) (comment) seems to be crucial!? I probably tested with the newest Neovim; which works a lot better with swapfiles :)

Also #571 fixes this issue and even shows the swapfile-dialog (Open, Edit, Recover, ...), but also the exception, before showing the file.