neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 8495d9623809eef5cf40b45ea3a5c2b0bd4077b5
parent 9ff12396347b0356b856b68b0e3010b3c8ec2e00
Author: Maria José Solano <majosolano99@gmail.com>
Date:   Thu, 24 Apr 2025 10:25:27 -0700

fix(lsp): ensure `bufstate` when calling `vim.lsp.document_color.is_enabled`

Diffstat:
Mruntime/lua/vim/lsp/document_color.lua | 8+++++++-
Mtest/functional/plugin/lsp/document_color_spec.lua | 9+++++++++
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/runtime/lua/vim/lsp/document_color.lua b/runtime/lua/vim/lsp/document_color.lua @@ -238,7 +238,13 @@ end function M.is_enabled(bufnr) vim.validate('bufnr', bufnr, 'number', true) - return bufstates[vim._resolve_bufnr(bufnr)].enabled + bufnr = vim._resolve_bufnr(bufnr) + + if not bufstates[bufnr] then + reset_bufstate(bufnr, false) + end + + return bufstates[bufnr].enabled end --- Enables document highlighting from the given language client in the given buffer. diff --git a/test/functional/plugin/lsp/document_color_spec.lua b/test/functional/plugin/lsp/document_color_spec.lua @@ -159,6 +159,15 @@ body { end) ) end) + + it('does not error when called on a new unattached buffer', function() + eq( + false, + exec_lua(function() + return vim.lsp.document_color.is_enabled(vim.api.nvim_create_buf(false, true)) + end) + ) + end) end) describe('enable()', function()