fix: WikiTagRename failure after so many tags#285
fix: WikiTagRename failure after so many tags#285lervag merged 3 commits intolervag:masterfrom trev-dev:patch-tagrename
Conversation
It appears as though we may be killing a reference to self.collection[o:old_tag] prematurely, thus causing subsequent tags to be renamed.
Ah, yes, good catch! However, I'm not sure this is quite right either. That is: for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
call remove(self.collection[a:old_tag], 0)
let l:n = 0
for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
let l:n += 1
let l:num_files += 1
endif
endfor
if l:n == len(l:tagpages)
call remove(self.collection, a:old_tag)
endifBy the way, I've so far avoided the method syntax: self.collection->get(a:old_tag)The reason has been that it is new and I have specified a compatibility requirement (Vim (>= 8.1) or neovim (>= 0.5)). I think adding this syntax means we need to tighten the requirement. Something like neovim: v0.6.0 and Vim v8.1.1803. Perhaps I'll just do that, but at least it needs attention before doing it. |
Actually, we're popping the cache directly :) - 24fcd43#diff-cd765ef8a9fc7bf69b406ef30f8ab7d371d11124401b05d82343d39400ebcf8dR426 let l:tagpages = deepcopy(self.collection[a:old_tag])
" We already know where the tag is in the file, thanks to the cache
for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
call remove(self.collection[a:old_tag], 0)
let l:num_files += 1
endif
endforBy doing this, we have an iterator that won't suddenly lose keys, that should be a 1:1 copy of
I will just use a nested function call then :) |
Hmm. I'm not properly convinced. Let's simplify: let tagpages = deepcopy(self.collection[a:old_tag]) " [1, 2, 3]
for l:x in l:tagpages
if l:x == 2
let l:y = remove(self.collection[a:old_tag], 0)
" now
" y = 2, but
" x = 2
endif
endfor
" Also: self.collection[a:old_tag] = [2, 3]However, I believe the idea here is that the loop should update all let l:tagpages = deepcopy(self.collection[a:old_tag])
for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
let l:num_files += 1
endif
endfor
call remove(self.collection, a:old_tag)or even let l:tagpages = remove(self.collection, a:old_tag)
for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
let l:num_files += 1
endif
endfor
I agree that the old code was buggy, but I think perhaps my suggestion above is correct. |
let tagpages = deepcopy(self.collection[a:old_tag]) " [1, 2, 3]
for l:x in l:tagpages
if l:x == 2
let l:y = remove(self.collection[a:old_tag], 0)
" now
" y = 2, but
" x = 2
endif
endfor
" Also: self.collection[a:old_tag] = [2, 3]My concept hinges on the idea that the loop will always do the same thing on every iteration without corner cases, so yes, throwing an let l:tagpages = remove(self.collection, a:old_tag)
for [l:file, l:lnum] in l:tagpages
if s:update_tag_in_wiki(l:file, l:lnum, a:old_tag, a:new_tag)
call self.add(a:new_tag, l:file, l:lnum)
let l:num_files += 1
endif
endforThis is indeed the most simple way to do it and it avoids the need to worry about an iterator disappearing, or doubling up on memory 🥳 |
|
After applying your simplification I get a maybe false negative about the old key being missing in my tag cache, not sure what's up with that but it's working. |
Hmm... it seems you are saying that "there is a problem" but also "it's working". I'm not sure how to understand this. Should I merge this or should I wait? |
It works, it's just giving me a nonsense error message the first time I rename something: If I were you, I would merge it. I can raise a separate issue/PR after testing to see if it's just a "me" problem. |
Yes, that's because of this: I.e., it is not really an error message. It is a warning due to an "unexpected" event where the old tag was not found in the tags collection. However, it is not unexpected if we never initialized the cache. So I've fixed this before I merged. |

It appears as though we may be killing a reference to
self.collection[o:old_tag]prematurely, thus causing subsequent tags to be renamed. Prior to this patch I could only rename tags 2 wiki files at a time.This PR addresses this by creating a deep copy of the list of tag/file relationships to iterate off of. We then "pop" off the front of
collection[a:old_tag]every iteration until we are presumably done. Ifcollection[a:old_tag]is empty, we then remove it from the collection.