diff options
author | Bartłomiej Maryńczak <marynczakbartlomiej@gmail.com> | 2025-03-30 17:39:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-30 08:39:10 -0700 |
commit | 49756ebc70dcd37eb7465f9cacd5e78803619daa (patch) | |
tree | 98be19cd0ce5c9921920e7b972fc45c0a38512bb | |
parent | 87b4469adcf2de5f792ea0d19afd002e9cb96016 (diff) | |
download | rneovim-49756ebc70dcd37eb7465f9cacd5e78803619daa.tar.gz rneovim-49756ebc70dcd37eb7465f9cacd5e78803619daa.tar.bz2 rneovim-49756ebc70dcd37eb7465f9cacd5e78803619daa.zip |
fix(vim.lsp.inlay_hint): requesting inlay_hints even when disabled #32999
Problem:
Nvim needlessly requests inlay_hints even if they are disabled for a given buffer.
Solution:
Add the missing `enabled` check in `on_refresh`.
Rest of the code has this check already so that's the only needed one to fix this.
-rw-r--r-- | runtime/lua/vim/lsp/inlay_hint.lua | 4 | ||||
-rw-r--r-- | test/functional/plugin/lsp/inlay_hint_spec.lua | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua index ab3a269937..a37fa42aac 100644 --- a/runtime/lua/vim/lsp/inlay_hint.lua +++ b/runtime/lua/vim/lsp/inlay_hint.lua @@ -94,10 +94,10 @@ function M.on_refresh(err, _, ctx) for _, bufnr in ipairs(vim.lsp.get_buffers_by_client_id(ctx.client_id)) do for _, winid in ipairs(api.nvim_list_wins()) do if api.nvim_win_get_buf(winid) == bufnr then - if bufstates[bufnr] then + if bufstates[bufnr] and bufstates[bufnr].enabled then bufstates[bufnr].applied = {} + util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr }) end - util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr }) end end end diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua index e410a54c31..3ff190fb55 100644 --- a/test/functional/plugin/lsp/inlay_hint_spec.lua +++ b/test/functional/plugin/lsp/inlay_hint_spec.lua @@ -297,6 +297,50 @@ int main() { end) ) end) + + it('does not request hints from lsp when disabled', function() + exec_lua(function() + _G.server2 = _G._create_server({ + capabilities = { + inlayHintProvider = true, + }, + handlers = { + ['textDocument/inlayHint'] = function(_, _, callback) + _G.got_inlay_hint_request = true + callback(nil, {}) + end, + }, + }) + _G.client2 = vim.lsp.start({ name = 'dummy2', cmd = _G.server2.cmd }) + end) + + local function was_request_sent() + return exec_lua(function() + return _G.got_inlay_hint_request == true + end) + end + + eq(false, was_request_sent()) + + exec_lua(function() + vim.lsp.inlay_hint.get() + end) + + eq(false, was_request_sent()) + + exec_lua(function() + vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) + vim.lsp.inlay_hint.get() + end) + + eq(false, was_request_sent()) + + exec_lua(function() + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + end) + + eq(true, was_request_sent()) + end) end) end) |