This plugin adds virtual text support to nvim-dap. nvim-treesitter is used to find variable definitions.
Plug 'mfussenegger/nvim-dap'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'theHamsta/nvim-dap-virtual-text'
The hlgroup for the virtual text is NvimDapVirtualText
(linked to Comment
).
Exceptions that caused the debugger to stop are displayed as NvimDapVirtualTextError
(linked to DiagnosticVirtualTextError
). Changed and new variables will be highlighted with
NvimDapVirtualTextChanged
(default linked to DiagnosticVirtualTextWarn
).
The behavior of this can plugin can be activated and controlled via a setup
call
require("nvim-dap-virtual-text").setup()
Wrap this call with lua <<EOF
when you are using viml for your config:
lua <<EOF
require("nvim-dap-virtual-text").setup()
EOF
or with additional options:
require("nvim-dap-virtual-text").setup {
enabled = true, -- enable this plugin (the default)
enabled_commands = true, -- create commands DapVirtualTextEnable, DapVirtualTextDisable, DapVirtualTextToggle, (DapVirtualTextForceRefresh for refreshing when debug adapter did not notify its termination)
highlight_changed_variables = true, -- highlight changed values with NvimDapVirtualTextChanged, else always NvimDapVirtualText
highlight_new_as_changed = false, -- highlight new variables in the same way as changed variables (if highlight_changed_variables)
show_stop_reason = true, -- show stop reason when stopped for exceptions
commented = false, -- prefix virtual text with comment string
-- experimental features:
virt_text_pos = 'eol', -- position of virtual text, see `:h nvim_buf_set_extmark()`
all_frames = false, -- show virtual text for all stack frames not only current. Only works for debugpy on my machine.
virt_lines = false, -- show virtual lines instead of virtual text (will flicker!)
virt_text_win_col = nil -- position the virtual text at a fixed window column (starting from the first text column) ,
-- e.g. 80 to position at column 80, see `:h nvim_buf_set_extmark()`
}
With highlight_changed_variables = false, all_frames = false
With highlight_changed_variables = false, all_frames = true
It works for all languages with locals.scm
in nvim-treesitter (@definition.var
is required for variable definitions).
This should include C/C++, Python, Rust, Go, Java...
The virtual text can additionally use a comment-like syntax to further improve distinguishability between actual code and debugger info by setting the following option:
require("nvim-dap-virtual-text").setup {
commented = true,
}
This will use the commentstring
option to choose the appropriate comment-syntax for the current filetype
With virt_text_win_col = 80, highlight_changed_variables = true
(x has just changed its value)
Exception virtual text can be deactivated via
require("nvim-dap-virtual-text").setup {
show_stop_reason = false,
}