Temporarily disable inlay hints during debugging, fix so virtual text
gets cleared after debugging finishes.
This commit is contained in:
parent
f2e27f7a59
commit
cdfa4fe2d8
3 changed files with 57 additions and 15 deletions
35
home/.config/nvim/lua/inlay_hints_handler.lua
Normal file
35
home/.config/nvim/lua/inlay_hints_handler.lua
Normal file
|
|
@ -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
|
||||
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
["<leader>dr"] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue