fix: compatible with the situation of disabling lsp inlay_hint delay (#360)

This commit is contained in:
yetone 2024-08-29 19:46:51 +08:00 committed by GitHub
parent abe08d5283
commit 24b0bfadea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -509,16 +509,15 @@ function M.setup()
local augroup = api.nvim_create_augroup(AUGROUP_NAME, { clear = true }) local augroup = api.nvim_create_augroup(AUGROUP_NAME, { clear = true })
local is_inlay_enable = vim.lsp.inlay_hint and vim.lsp.inlay_hint.is_enabled() or false local previous_inlay_enabled = nil
local previous_inlay = nil
api.nvim_create_autocmd("User", { api.nvim_create_autocmd("User", {
group = augroup, group = augroup,
pattern = "AvanteConflictDetected", pattern = "AvanteConflictDetected",
callback = function(ev) callback = function(ev)
vim.diagnostic.enable(false, { bufnr = ev.buf }) vim.diagnostic.enable(false, { bufnr = ev.buf })
if is_inlay_enable then if vim.lsp.inlay_hint then
previous_inlay = vim.lsp.inlay_hint.is_enabled({ bufnr = ev.buf }) previous_inlay_enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = ev.buf })
vim.lsp.inlay_hint.enable(false, { bufnr = ev.buf }) vim.lsp.inlay_hint.enable(false, { bufnr = ev.buf })
end end
setup_buffer_mappings(ev.buf) setup_buffer_mappings(ev.buf)
@ -530,9 +529,9 @@ function M.setup()
pattern = "AvanteConflictResolved", pattern = "AvanteConflictResolved",
callback = function(ev) callback = function(ev)
vim.diagnostic.enable(true, { bufnr = ev.buf }) vim.diagnostic.enable(true, { bufnr = ev.buf })
if is_inlay_enable then if vim.lsp.inlay_hint and previous_inlay_enabled ~= nil then
vim.lsp.inlay_hint.enable(previous_inlay, { bufnr = ev.buf }) vim.lsp.inlay_hint.enable(previous_inlay_enabled, { bufnr = ev.buf })
previous_inlay = nil previous_inlay_enabled = nil
end end
clear_buffer_mappings(ev.buf) clear_buffer_mappings(ev.buf)
end, end,