feat: simplify toggle
This commit is contained in:
parent
20d42ed361
commit
efdd17e22b
2 changed files with 11 additions and 3 deletions
|
@ -1,7 +1,15 @@
|
|||
local utils = require('cosmic.utils')
|
||||
local lsp_utils = require('cosmic.utils.lsp')
|
||||
local user_config = require('cosmic.core.user')
|
||||
local M = {}
|
||||
|
||||
local function toggle_inlay_hints(bufnr, enabled)
|
||||
return function()
|
||||
enabled = not enabled
|
||||
vim.lsp.inlay_hint(bufnr, enabled)
|
||||
end
|
||||
end
|
||||
|
||||
-- Mappings.
|
||||
function M.init(client, bufnr)
|
||||
local buf_map = utils.create_buf_map(bufnr, {
|
||||
|
@ -35,7 +43,7 @@ function M.init(client, bufnr)
|
|||
|
||||
-- inlay hints
|
||||
if client.supports_method('textDocument/inlayHint') then
|
||||
buf_map('n', '<leader>lh', lsp_utils.toggle_inlay_hints(bufnr), { desc = 'Toggle inlay hints for buffer' })
|
||||
buf_map('n', '<leader>lh', lsp_utils.toggle_inlay_hints(), { desc = 'Toggle inlay hints for buffer' })
|
||||
end
|
||||
|
||||
-- code actions
|
||||
|
|
|
@ -69,11 +69,11 @@ function M.get_lsp_status_str()
|
|||
return client_str
|
||||
end
|
||||
|
||||
function M.toggle_inlay_hints(bufnr)
|
||||
function M.toggle_inlay_hints()
|
||||
local enabled = user_config.lsp.inlay_hint
|
||||
return function()
|
||||
enabled = not enabled
|
||||
vim.lsp.inlay_hint(bufnr, enabled)
|
||||
vim.lsp.inlay_hint(vim.api.nvim_get_current_buf() or 0, enabled)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue