diff --git a/home/.config/nvim/lua/inlay_hints_handler.lua b/home/.config/nvim/lua/inlay_hints_handler.lua new file mode 100644 index 0000000..0c7b419 --- /dev/null +++ b/home/.config/nvim/lua/inlay_hints_handler.lua @@ -0,0 +1,35 @@ +local M = {} + +M.hints_active = true +M.buffers = {} + +function M.add_buffer(bufnr) + table.insert(M.buffers, bufnr) + + vim.lsp.inlay_hint.enable(M.hints_active, { bufnr = bufnr }) + vim.api.nvim_create_autocmd({ "BufDelete", "BufUnload" }, { + buffer = bufnr, + callback = function() + for i, buffer in ipairs(M.buffers) do + if buffer == bufnr then + table.remove(M.buffers, i) + break + end + end + end, + }) +end + +function M.disable() + for _, bufnr in ipairs(M.buffers) do + vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) + end +end + +function M.restore() + for _, bufnr in ipairs(M.buffers) do + vim.lsp.inlay_hint.enable(M.hints_active, { bufnr = bufnr }) + end +end + +return M diff --git a/home/.config/nvim/lua/lsp/setup.lua b/home/.config/nvim/lua/lsp/setup.lua index 0992c37..0a96867 100644 --- a/home/.config/nvim/lua/lsp/setup.lua +++ b/home/.config/nvim/lua/lsp/setup.lua @@ -1,4 +1,5 @@ local utils = require("utils") +local inlay_hints_handler = require("inlay_hints_handler") local function chain_on_attach(...) local funcs = { ... } @@ -10,7 +11,7 @@ local function chain_on_attach(...) end local function global_on_attach(client, bufnr) - vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + inlay_hints_handler.add_buffer(bufnr) if client.server_capabilities.documentFormattingProvider then vim.api.nvim_buf_create_user_command(bufnr, "Format", vim.lsp.buf.format, { nargs = 0 }) diff --git a/home/.config/nvim/lua/plugs/nvim-dap.lua b/home/.config/nvim/lua/plugs/nvim-dap.lua index d12d55d..4103114 100644 --- a/home/.config/nvim/lua/plugs/nvim-dap.lua +++ b/home/.config/nvim/lua/plugs/nvim-dap.lua @@ -1,4 +1,5 @@ local utils = require("utils") +local inlay_hints_handler = require("inlay_hints_handler") local are_stepping_keymaps_active = false return { @@ -18,6 +19,20 @@ return { config = function() local dap = require("dap") local dapui = require("dapui") + -- Special adapters + require("dap-go").setup() + require("dap-python").setup("python3") + -- Special adapters + + require("dap.ext.vscode").load_launchjs() + require("persistent-breakpoints").setup { + load_breakpoints_event = { "BufReadPost" } + } + + require("nvim-dap-repl-highlights").setup() + require("nvim-dap-virtual-text").setup() + local virtual_text = require("nvim-dap-virtual-text/virtual_text") + local breakpoint_api = require("persistent-breakpoints.api") dapui.setup({ controls = { @@ -41,16 +56,6 @@ return { }, }) - -- Special adapters - require("dap-go").setup() - require("dap-python").setup("python3") - -- Special adapters - - require("dap.ext.vscode").load_launchjs() - require("persistent-breakpoints").setup { - load_breakpoints_event = { "BufReadPost" } - } - local stepping_keymaps = { n = { ["m"] = { @@ -77,6 +82,8 @@ return { utils.add_keymaps(stepping_keymaps) are_stepping_keymaps_active = true end + + inlay_hints_handler.disable() end local function exit_debug_mode() @@ -85,6 +92,9 @@ return { utils.remove_keymaps(stepping_keymaps) are_stepping_keymaps_active = false end + + inlay_hints_handler.restore() + virtual_text.clear_virtual_text() end local dap_signs = { @@ -107,10 +117,6 @@ return { exit_debug_mode() end - require("nvim-dap-repl-highlights").setup() - require("nvim-dap-virtual-text").setup() - - local breakpoint_api = require("persistent-breakpoints.api") utils.add_keymaps({ n = { ["dr"] = {