aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin
diff options
context:
space:
mode:
authorYi Ming <ofseed@foxmail.com>2024-05-02 21:16:20 +0800
committerGitHub <noreply@github.com>2024-05-02 06:16:20 -0700
commitd5063f4b290e1c4262f7ced6d425ff2d7a2e2045 (patch)
tree823ace167610043482ff23da0fd8448688e19c1a /test/functional/plugin
parent2becec289c77a359087ab6322276811aea9e87c8 (diff)
downloadrneovim-d5063f4b290e1c4262f7ced6d425ff2d7a2e2045.tar.gz
rneovim-d5063f4b290e1c4262f7ced6d425ff2d7a2e2045.tar.bz2
rneovim-d5063f4b290e1c4262f7ced6d425ff2d7a2e2045.zip
feat(lsp): vim.lsp.inlay_hint.enable(nil) applies to all buffers #28543
Problem: Inlay hints `enable()` does not fully implement the `:help dev-lua` guidelines: Interface conventions ~ - When accepting a buffer id, etc., 0 means "current buffer", nil means "all buffers". Likewise for window id, tabpage id, etc. - Examples: |vim.lsp.codelens.clear()| |vim.diagnostic.enable()| Solution: Implement globally enabling inlay hints. * refactor(lsp): do not rely on `enable` to create autocmds * refactor(lsp): make `bufstates` a defaulttable * refactor(lsp): make `bufstate` inherit values from `globalstate` * feat(lsp): `vim.lsp.inlay_hints` now take effect on all buffers by default * test(lsp): add basic tests for enable inlay hints for all buffers * test(lsp): add test cases cover more than one buffer
Diffstat (limited to 'test/functional/plugin')
-rw-r--r--test/functional/plugin/lsp/inlay_hint_spec.lua53
1 files changed, 42 insertions, 11 deletions
diff --git a/test/functional/plugin/lsp/inlay_hint_spec.lua b/test/functional/plugin/lsp/inlay_hint_spec.lua
index 0aaf94d6da..94e7fbb97c 100644
--- a/test/functional/plugin/lsp/inlay_hint_spec.lua
+++ b/test/functional/plugin/lsp/inlay_hint_spec.lua
@@ -137,20 +137,51 @@ describe('vim.lsp.inlay_hint', function()
)
end)
- it('clears/applies inlay hints when passed false/true/nil', function()
- exec_lua([[vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })]])
- screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ describe('clears/applies inlay hints when passed false/true/nil', function()
+ before_each(function()
+ exec_lua([[
+ bufnr2 = vim.api.nvim_create_buf(true, false)
+ vim.lsp.buf_attach_client(bufnr2, client_id)
+ vim.api.nvim_win_set_buf(0, bufnr2)
+ ]])
+ insert(text)
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr2 })]])
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints })
+ end)
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
- screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ it('for one single buffer', function()
+ exec_lua([[
+ vim.lsp.inlay_hint.enable(false, { bufnr = bufnr })
+ vim.api.nvim_win_set_buf(0, bufnr2)
+ ]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua(
- [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]]
- )
- screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+
+ exec_lua(
+ [[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(bufnr), { bufnr = bufnr })]]
+ )
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+
+ exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
+
+ it('for all buffers', function()
+ exec_lua([[vim.lsp.inlay_hint.enable(false)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr2)]])
+ screen:expect({ grid = grid_without_inlay_hints, unchanged = true })
- exec_lua([[vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })]])
- screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.lsp.inlay_hint.enable(true)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ exec_lua([[vim.api.nvim_win_set_buf(0, bufnr)]])
+ screen:expect({ grid = grid_with_inlay_hints, unchanged = true })
+ end)
end)
end)