diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-11-22 08:47:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 08:47:30 -0700 |
commit | e02d4732f2d523b2dc4bf436b28341f54ea89132 (patch) | |
tree | 09a3d21134829b7e6e6dafc43aab0564005297c5 /runtime/lua/vim/lsp/util.lua | |
parent | 33ce02ee4d3b8bb8f5432049397cb7976bc3a55e (diff) | |
download | rneovim-e02d4732f2d523b2dc4bf436b28341f54ea89132.tar.gz rneovim-e02d4732f2d523b2dc4bf436b28341f54ea89132.tar.bz2 rneovim-e02d4732f2d523b2dc4bf436b28341f54ea89132.zip |
fix(diagnostics): don't allow 0 bufnr for metatable index (#16405)
04bfd20bb introduced a subtle bug where using 0 as the buffer number in
the diagnostic cache resets the cache for the current buffer. This
happens because we were not checking to see if the _resolved_ buffer
number already existed in the cache; rather, when the __index metamethod
was called we assumed the index did not exist so we set its value to an
empty table. The fix for this is to check `rawget()` for the resolved
buffer number to see if the index already exists.
However, the reason this bug was introduced in the first place was
because we are simply being too clever by allowing a 0 buffer number as
the index which is automatically resolved to a real buffer number.
In the interest of minimizing metatable magic, remove this "feature" by
requiring the buffer number index to always be a valid buffer. This
ensures that the __index metamethod is only ever called for non-existing
buffers (which is what we wanted originally) as well as reduces some of
the cognitive overhead for understanding how the diagnostic cache works.
The tradeoff is that all public API functions must now resolve 0 buffer
numbers to the current buffer number.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
0 files changed, 0 insertions, 0 deletions