-
-
Notifications
You must be signed in to change notification settings - Fork 378
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] Calling remove_at
to manipulate elements when using Telescope UI causes items list to become malformed
#627
Comments
Fix in the making #628 |
I've been using my "fixed" version of -- excerpt from my neovim config
local harpoon_get_paths = function(files)
local paths = {}
local items = files.items
local len = files._length
for i = 1, len do
paths[i] = ''
local item = items[i]
if item ~= nil then
paths[i] = item.value
end
end
return paths
end Then you can use function M.toggle_telescope(harpoon_files)
...
attach_mappings = function(prompt_buffer_number, map)
map("i", "<M-d>", function()
local selected_entry = telescope_state.get_selected_entry()
local current_picker = telescope_state.get_current_picker(prompt_buffer_number)
- table.remove(harpoon:list().items, selected_entry.index)
+ harpoon:list():remove_at(selected_entry.index)
current_picker:refresh(harpoon_make_finder(harpoon_get_paths(harpoon:list())))
end)
...
end Asciinema demo of the fixed behaviour: |
I am officially back, I'll get this through shortly |
👀 |
remove_at
to manipulate elements when using Telescope UI causes items list to become malformed #628;for
-loop, instead ofnext()
oripairs()
, to prevent loss of data #573;When using Harpoon via the Telescope UI, I would like to be able to remove items from the Harpoon list; currently, there are some ways to do it, such as extracting the index in
selected_entry.index
fromtelescope.actions.state
, and using that to index the item to be removed from the list:This method leads to problems, however. As it turns out, calling
remove_at
and passing it an index will leave a list with a "hole" where the removed item once was, and every item that comes after will be explicitly indexed, like so:This alone wouldn't be a problem, but whenever an operation requires looping over the list, the iterator will halt once it reaches the "missing" element. That includes the Telecope UI rendering, which would only display elements up to that position, and, for whatever reason, this also seems to impact the "persistence" of the harpooned items on exit;
harpoon:list().items
only contains items up to that index once you restart vim (possibly caused by the use ofipairs()
overself.items
inHarpoonList:encode
, which halts once it reaches the "hole"); this means that the items after the removed element are LOST once you exit vim:There is a possible workaround if you want to make it work nonetheless, as suggested by @Ocholla-T in this comment (#499); it works by manually removing the item from the table, instead of making the acutal API call:
This works! But it seems as if there's a bug in the actual list implementation, though it isn't caught by the unit tests nor seems to cause any other apparent problems.
I'm still doing some debugging over this issue, but I was able to roughly identify the point where the "bug" occurs:
from: harpoon/lua/harpoon/list.lua#L205
The text was updated successfully, but these errors were encountered: