mfussenegger / nvim-dap

Debug Adapter Protocol client implementation for Neovim
GNU General Public License v3.0
5.1k stars 179 forks source link

Breakpoint symbol is not using sign column background color by default #1137

Closed shmerl closed 1 month ago

shmerl commented 5 months ago

Steps to Reproduce

My color scheme defines one color for Normal and a different color for SignColumn.

When simply placing a breakpoint, it uses background color of the editor pane (Normal) rather than sign column (SignColumn) color.

See example below (note background around symbol B):

dap_nvim_colors

Expected Result

It would make sense for the breakpoint and other nvim-dap signs to use the background of SignColumn by default.

Actual Result

Color used for breakpoint signs matches Normal color of the scheme.

I can work around it by setting the matching color for SignColumn through configuration for DapBreakpoint, DapStopped and etc. but it's not ideal and would break every time the color schema is changed.

shmerl commented 4 months ago

I can try fixing it, but would appreciate if you can please give any pointers where in the code the color is being set (or not set).

Thanks!

shmerl commented 4 months ago

If anyone needs also, for the current code, here is a workaround that reads current color for SignColumn and reuses it. This has to be applied before color scheme is loaded for the first time (or you can reload the color scheme if plugin is lazy loaded for example and this snippet is only executed at some later point):

vim.api.nvim_create_autocmd("ColorScheme", {
  pattern = "*",
  desc = "Prevent colorscheme clearing self-defined DAP marker colors",
  callback = function()
      -- Reuse current SignColumn background (except for DapStoppedLine)
      local sign_column_hl = vim.api.nvim_get_hl(0, { name = 'SignColumn' })
      -- if bg or ctermbg aren't found, use bg = 'bg' (which means current Normal) and ctermbg = 'Black'
      -- convert to 6 digit hex value starting with #
      local sign_column_bg = (sign_column_hl.bg ~= nil) and ('#%06x'):format(sign_column_hl.bg) or 'bg'
      local sign_column_ctermbg = (sign_column_hl.ctermbg ~= nil) and sign_column_hl.ctermbg or 'Black'

      vim.api.nvim_set_hl(0, 'DapStopped', { fg = '#00ff00', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
      vim.api.nvim_set_hl(0, 'DapStoppedLine', { bg = '#2e4d3d', ctermbg = 'Green' })
      vim.api.nvim_set_hl(0, 'DapBreakpoint', { fg = '#c23127', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
      vim.api.nvim_set_hl(0, 'DapBreakpointRejected', { fg = '#888ca6', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
      vim.api.nvim_set_hl(0, 'DapLogPoint', { fg = '#61afef', bg = sign_column_bg, ctermbg = sign_column_ctermbg })
  end
})

-- reload current color scheme to pick up colors override if it was set up in a lazy plugin definition fashion
vim.cmd.colorscheme(vim.g.colors_name)
mfussenegger commented 1 month ago

nvim-dap doesn't define the background at all for the signs.

It is just:

DapBreakpoint = { text = "B", texthl = "", linehl = "", numhl = "" },
shmerl commented 1 month ago

Well, somehow with my theme it turned to Normal instead of staying what was already defined, so there is some disconnect there. I assume numhl being set to "" turns it to default (Normal) may be? Using the above workaround ensures that theme defined value is used.

shmerl commented 1 month ago

OK, this fixes the bug in your code itself (i.e. setting texthl = "SignColumn" for your signs except for DapStoppedLine):

local signs = {
  DapBreakpoint = { text = "B", texthl = "SignColumn", linehl = "", numhl = "" },
  DapBreakpointCondition = { text = "C", texthl = "SignColumn", linehl = "", numhl = "" },
  DapBreakpointRejected = { text = 'R', texthl = 'SignColumn', linehl = '', numhl = '' },
  DapLogPoint = { text = 'L', texthl = 'SignColumn', linehl = '', numhl = '' },
  DapStopped = { text = '→', texthl = 'SignColumn', linehl = 'debugPC', numhl = '' },
}

Somehow setting texthl to empty doesn't use current value but simply falls back to Normal which is not correct.

It doesn't hurt for your code to do that since you are intending not to change the coloring of the sign column by default, right? Though may be it's working around a bug in neovim itself.

shmerl commented 1 month ago

Thanks for fixing it on your side.