Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): use a parameter strategy similar to enable #28523

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions runtime/doc/lsp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1645,13 +1645,15 @@ get({filter}) *vim.lsp.inlay_hint.get()*
• {client_id} (`integer`)
• {inlay_hint} (`lsp.InlayHint`)

is_enabled({bufnr}) *vim.lsp.inlay_hint.is_enabled()*
is_enabled({filter}) *vim.lsp.inlay_hint.is_enabled()*

Note: ~
• This API is pre-release (unstable).

Parameters: ~
• {bufnr} (`integer?`) Buffer handle, or 0 for current
• {filter} (`table`) Optional filters |kwargs|, or `nil` for all.
• {bufnr} (`integer?`) Buffer number, or 0 for current
buffer, or nil for all.

Return: ~
(`boolean`)
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ BREAKING CHANGES IN HEAD *news-breaking-dev*
The following changes to UNRELEASED features were made during the development
cycle (Nvim HEAD, the "master" branch).

• Changed the signature of `vim.lsp.inlay_hint.is_enabled()`.

• `vim.lsp.inlay_hint.enable()` now take effect on all buffers by default.

• Removed `vim.treesitter.foldtext` as transparent foldtext is now supported
Expand Down
23 changes: 20 additions & 3 deletions runtime/lua/vim/lsp/inlay_hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,29 @@ api.nvim_set_decoration_provider(namespace, {
end,
})

--- @param bufnr (integer|nil) Buffer handle, or 0 for current
--- @param filter vim.lsp.inlay_hint.enable.Filter
--- @return boolean
--- @since 12
function M.is_enabled(bufnr)
function M.is_enabled(filter)
---@type integer
local bufnr
if type(filter) == 'number' then
vim.deprecate(
'vim.lsp.inlay_hint.is_enabled(bufnr:number)',
'vim.lsp.inlay_hint.is_enabled(filter:table)',
'0.10-dev'
)
bufnr = filter
else
vim.validate({ filter = { filter, 'table', true } })
filter = filter or {}
bufnr = filter.bufnr
end

vim.validate({ bufnr = { bufnr, 'number', true } })
if bufnr == nil or bufnr == 0 then
if bufnr == nil then
return globalstate.enabled
elseif bufnr == 0 then
bufnr = api.nvim_get_current_buf()
end
return bufstates[bufnr].enabled
Expand Down
2 changes: 1 addition & 1 deletion test/functional/plugin/lsp/inlay_hint_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('vim.lsp.inlay_hint', function()
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 })]]
[[vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })]]
)
screen:expect({ grid = grid_without_inlay_hints, unchanged = true })

Expand Down