pocco81 / auto-save.nvim

🧶 Automatically save your changes in NeoVim
GNU General Public License v3.0
670 stars 58 forks source link

nvim_buf_set_var can rise invalid buf error #51

Closed doubleloop closed 2 years ago

doubleloop commented 2 years ago
danielfalk commented 2 years ago

I came here because I was having the same issue, but I think it might be better solved like this instead of using pcall:

    elseif api.nvim_buf_is_valid(buf) then
       api.nvim_buf_set_var(buf, 'autosave_' .. name, value)
    end
doubleloop commented 2 years ago

@danielfalk I am not a specialist on vim buffer but can there be race condition? I mean can buffer become invalid between calling nvim_buf_is_valid and api.nvim_buf_set_var? If no then your approach may be better, if yes, then pcall is better.

Also note that pcall is already used in similar case so it might be more consistent to use it

danielfalk commented 2 years ago

@danielfalk I am not a specialist on vim buffer but can there be race condition? I mean can buffer become invalid between calling nvim_buf_is_valid and api.nvim_buf_set_var? If no then your approach may be better, if yes, then pcall is better.

Also note that pcall is already used in similar case so it might be more consistent to use it

Neither am I! Just a suggestion because as far as I know, this isn't multi-threaded and the code runs synchronously, but I don't know for sure.